OPT_LOG_RM,
OPT_USAGE_SHOW,
OPT_USAGE_TRIM,
- OPT_TEMP_REMOVE,
OPT_OBJECT_RM,
OPT_OBJECT_UNLINK,
OPT_OBJECT_STAT,
return OPT_USAGE_SHOW;
if (strcmp(cmd, "trim") == 0)
return OPT_USAGE_TRIM;
- } else if (strcmp(prev_cmd, "temp") == 0) {
- if (strcmp(cmd, "remove") == 0)
- return OPT_TEMP_REMOVE;
} else if (strcmp(prev_cmd, "caps") == 0) {
if (strcmp(cmd, "add") == 0)
return OPT_CAPS_ADD;
map<string, bool> common_prefixes;
string ns;
- rgw_obj_key marker_key(marker);
+ RGWRados::Bucket target(store, bucket);
+ RGWRados::Bucket::List list_op(&target);
+
+ list_op.params.prefix = prefix;
+ list_op.params.delim = delim;
+ list_op.params.marker = rgw_obj_key(marker);
+ list_op.params.ns = ns;
+ list_op.params.enforce_ns = false;
+ list_op.params.list_versions = true;
do {
- list<rgw_bi_log_entry> entries;
- ret = store->list_objects(bucket, max_entries - count, prefix, delim,
- marker_key, NULL, result, common_prefixes, true,
- ns, false, true, &truncated, NULL);
+ ret = list_op.list_objects(max_entries - count, &result, &common_prefixes, &truncated);
if (ret < 0) {
cerr << "ERROR: store->list_objects(): " << cpp_strerror(-ret) << std::endl;
return -ret;
for (vector<RGWObjEnt>::iterator iter = result.begin(); iter != result.end(); ++iter) {
RGWObjEnt& entry = *iter;
encode_json("entry", entry, formatter);
-
- marker_key = entry.key;
}
formatter->flush(cout);
} while (truncated && count < max_entries);
}
}
- if (opt_cmd == OPT_TEMP_REMOVE) {
- if (date.empty()) {
- cerr << "date wasn't specified" << std::endl;
- return usage();
- }
- string parsed_date, parsed_time;
- int r = utime_t::parse_date(date, NULL, NULL, &parsed_date, &parsed_time);
- if (r < 0) {
- cerr << "failure parsing date: " << cpp_strerror(r) << std::endl;
- return 1;
- }
- r = store->remove_temp_objects(parsed_date, parsed_time);
- if (r < 0) {
- cerr << "failure removing temp objects: " << cpp_strerror(r) << std::endl;
- return 1;
- }
- }
-
if (opt_cmd == OPT_LOG_LIST) {
// filter by date?
if (date.size() && date.size() != 10) {
int ret;
map<RGWObjCategory, RGWStorageStats> stats;
std::vector<RGWObjEnt> objs;
- std::string prefix, delim, ns;
- rgw_obj_key marker;
map<string, bool> common_prefixes;
rgw_obj obj;
RGWBucketInfo info;
if (ret < 0)
return ret;
+
+ RGWRados::Bucket target(store, bucket);
+ RGWRados::Bucket::List list_op(&target);
+
+ list_op.params.list_versions = true;
+
if (delete_children) {
int max = 1000;
- ret = store->list_objects(bucket, max, prefix, delim, marker, NULL,
- objs, common_prefixes,
- false, ns, true, true, NULL, NULL);
-
+ ret = list_op.list_objects(max, &objs, &common_prefixes, NULL);
if (ret < 0)
return ret;
}
objs.clear();
- ret = store->list_objects(bucket, max, prefix, delim, marker, NULL, objs, common_prefixes,
- false, ns, true, true, NULL, NULL);
+ ret = list_op.list_objects(max, &objs, &common_prefixes, NULL);
if (ret < 0)
return ret;
}
rgw_bucket bucket = op_state.get_bucket();
int max = 1000;
- string prefix;
- string delim;
- rgw_obj_key marker;
map<string, bool> common_prefixes;
string ns = "multipart";
map<string, bool> meta_objs;
map<rgw_obj_key, string> all_objs;
+ RGWRados::Bucket target(store, bucket);
+ RGWRados::Bucket::List list_op(&target);
+
+ list_op.params.list_versions = true;
+
do {
vector<RGWObjEnt> result;
- int r = store->list_objects(bucket, max, prefix, delim, marker, NULL,
- result, common_prefixes, false,
- ns, true, true,
- &is_truncated, NULL);
-
+ int r = list_op.list_objects(max, &result, &common_prefixes, &is_truncated);
if (r < 0) {
set_err_msg(err_msg, "failed to list objects in bucket=" + bucket.name +
" err=" + cpp_strerror(-r));
rgw_obj_key key;
obj.get_index_key(&key);
- marker = key;
-
string oid = key.name;
int pos = oid.find_last_of('.');
uint64_t obj_ofs = 0, len_count = 0;
bool found_start = false, found_end = false;
string delim;
- rgw_obj_key marker;
bool is_truncated;
- string no_ns;
- map<string, bool> common_prefixes;
vector<RGWObjEnt> objs;
utime_t start_time = ceph_clock_now(cct);
+ RGWRados::Bucket target(store, bucket);
+ RGWRados::Bucket::List list_op(&target);
+
+ list_op.params.prefix = obj_prefix;
+ list_op.params.delim = delim;
+
do {
#define MAX_LIST_OBJS 100
- int r = store->list_objects(bucket, MAX_LIST_OBJS, obj_prefix, delim, marker, NULL,
- objs, common_prefixes,
- true, no_ns, true,
- false,
- &is_truncated, NULL);
+ int r = list_op.list_objects(MAX_LIST_OBJS, &objs, NULL, &is_truncated);
if (r < 0)
return r;
return r;
}
}
- marker = ent.key;
start_time = ceph_clock_now(cct);
}
if (ret < 0)
return;
- rgw_obj_key *pnext_marker = (delimiter.empty() ? NULL : &next_marker);
+ RGWRados::Bucket target(store, s->bucket);
+ RGWRados::Bucket::List list_op(&target);
+
+ list_op.params.prefix = prefix;
+ list_op.params.delim = delimiter;
+ list_op.params.marker = marker;
+ list_op.params.list_versions = list_versions;
- ret = store->list_objects(s->bucket, max, prefix, delimiter, marker, pnext_marker, objs, common_prefixes,
- !!(s->prot_flags & RGW_REST_SWIFT), no_ns, true, list_versions, &is_truncated, NULL);
+ ret = list_op.list_objects(max, &objs, &common_prefixes, &is_truncated);
+ if (ret >= 0 && !delimiter.empty()) {
+ next_marker = list_op.get_next_marker();
+ }
}
int RGWGetBucketLogging::verify_permission()
}
}
marker_meta = marker.get_meta();
- ret = store->list_objects(s->bucket, max_uploads, prefix, delimiter, marker_meta, NULL, objs, common_prefixes,
- !!(s->prot_flags & RGW_REST_SWIFT), mp_ns, true, false, &is_truncated, &mp_filter);
+
+ RGWRados::Bucket target(store, s->bucket);
+ RGWRados::Bucket::List list_op(&target);
+
+ list_op.params.prefix = prefix;
+ list_op.params.delim = delimiter;
+ list_op.params.marker = marker_meta;
+ list_op.params.ns = mp_ns;
+ list_op.params.filter = &mp_filter;
+
+ ret = list_op.list_objects(max_uploads, &objs, &common_prefixes, &is_truncated);
if (!objs.empty()) {
vector<RGWObjEnt>::iterator iter;
RGWMultipartUploadEntry entry;
* common_prefixes: if delim is filled in, any matching prefixes are placed
* here.
*/
-int RGWRados::list_objects(rgw_bucket& bucket, int max, string& prefix, string& delim,
- const rgw_obj_key& marker, rgw_obj_key *next_marker, vector<RGWObjEnt>& result,
- map<string, bool>& common_prefixes,
- bool get_content_type, string& ns, bool enforce_ns,
- bool list_versions,
- bool *is_truncated, RGWAccessListFilter *filter)
+int RGWRados::Bucket::List::list_objects(int max, vector<RGWObjEnt> *result,
+ map<string, bool> *common_prefixes,
+ bool *is_truncated)
{
+ RGWRados *store = target->get_store();
+ CephContext *cct = store->ctx();
+ rgw_bucket& bucket = target->get_bucket();
+
int count = 0;
bool truncated = true;
- if (bucket_is_system(bucket)) {
+ if (store->bucket_is_system(bucket)) {
return -EINVAL;
}
- result.clear();
+ result->clear();
rgw_obj marker_obj, prefix_obj;
- marker_obj.set_instance(marker.instance);
- marker_obj.set_ns(ns);
- marker_obj.set_obj(marker.name);
+ marker_obj.set_instance(params.marker.instance);
+ marker_obj.set_ns(params.ns);
+ marker_obj.set_obj(params.marker.name);
rgw_obj_key cur_marker;
marker_obj.get_index_key(&cur_marker);
- prefix_obj.set_ns(ns);
- prefix_obj.set_obj(prefix);
+ prefix_obj.set_ns(params.ns);
+ prefix_obj.set_obj(params.prefix);
string cur_prefix = prefix_obj.get_index_key_name();
string bigger_than_delim;
- if (!delim.empty()) {
- unsigned long val = decode_utf8((unsigned char *)delim.c_str(), delim.size());
- char buf[delim.size() + 16];
+ if (!params.delim.empty()) {
+ unsigned long val = decode_utf8((unsigned char *)params.delim.c_str(), params.delim.size());
+ char buf[params.delim.size() + 16];
int r = encode_utf8(val + 1, (unsigned char *)buf);
if (r < 0) {
ldout(cct,0) << "ERROR: encode_utf8() failed" << dendl;
string skip_after_delim;
/* if marker points at a common prefix, fast forward it into its upperbound string */
- if (!delim.empty()) {
- int delim_pos = cur_marker.name.find(delim, prefix.size());
+ if (!params.delim.empty()) {
+ int delim_pos = cur_marker.name.find(params.delim, params.prefix.size());
if (delim_pos >= 0) {
string s = cur_marker.name.substr(0, delim_pos);
s.append(bigger_than_delim);
ldout(cct, 20) << "setting cur_marker=" << cur_marker.name << "[" << cur_marker.instance << "]" << dendl;
}
std::map<string, RGWObjEnt> ent_map;
- int r = cls_bucket_list(bucket, cur_marker, cur_prefix, max + 1 - count, list_versions, ent_map,
+ int r = store->cls_bucket_list(bucket, cur_marker, cur_prefix, max + 1 - count, params.list_versions, ent_map,
&truncated, &cur_marker);
if (r < 0)
return r;
rgw_obj_key key = obj;
string instance;
- bool check_ns = rgw_obj::translate_raw_obj_to_obj_in_ns(obj.name, instance, ns);
- if (!list_versions && !entry.is_visible()) {
+ bool check_ns = rgw_obj::translate_raw_obj_to_obj_in_ns(obj.name, instance, params.ns);
+ if (!params.list_versions && !entry.is_visible()) {
continue;
}
- if (enforce_ns && !check_ns) {
- if (!ns.empty()) {
+ if (params.enforce_ns && !check_ns) {
+ if (!params.ns.empty()) {
/* we've iterated past the namespace we're searching -- done now */
truncated = false;
goto done;
continue;
}
- if (next_marker && count < max) {
- *next_marker = obj;
+ if (count < max) {
+ params.marker = obj;
+ next_marker = obj;
}
- if (filter && !filter->filter(obj.name, key.name))
+ if (params.filter && !params.filter->filter(obj.name, key.name))
continue;
- if (prefix.size() && (obj.name.compare(0, prefix.size(), prefix) != 0))
+ if (params.prefix.size() && (obj.name.compare(0, params.prefix.size(), params.prefix) != 0))
continue;
- if (!delim.empty()) {
- int delim_pos = obj.name.find(delim, prefix.size());
+ if (!params.delim.empty()) {
+ int delim_pos = obj.name.find(params.delim, params.prefix.size());
if (delim_pos >= 0) {
string prefix_key = obj.name.substr(0, delim_pos + 1);
- if (common_prefixes.find(prefix_key) == common_prefixes.end()) {
+ if (common_prefixes &&
+ common_prefixes->find(prefix_key) == common_prefixes->end()) {
if (count >= max) {
truncated = true;
goto done;
}
- if (next_marker) {
- *next_marker = prefix_key;
- }
- common_prefixes[prefix_key] = true;
+ next_marker = prefix_key;
+ (*common_prefixes)[prefix_key] = true;
skip_after_delim = obj.name.substr(0, delim_pos);
skip_after_delim.append(bigger_than_delim);
RGWObjEnt ent = eiter->second;
ent.key = obj;
- ent.ns = ns;
- result.push_back(ent);
+ ent.ns = params.ns;
+ result->push_back(ent);
count++;
}
}
return r;
}
-/* a simple object read */
-int RGWRados::read(void *ctx, rgw_obj& obj, off_t ofs, size_t size, bufferlist& bl)
-{
- rgw_rados_ref ref;
- rgw_bucket bucket;
- int r = get_obj_ref(obj, &ref, &bucket);
- if (r < 0) {
- return r;
- }
- RGWObjectCtx *rctx = static_cast<RGWObjectCtx *>(ctx);
- RGWObjState *astate = NULL;
-
- ObjectReadOperation op;
-
- r = append_atomic_test(rctx, obj, op, &astate);
- if (r < 0)
- return r;
-
- op.read(ofs, size, &bl, NULL);
-
- return ref.ioctx.operate(ref.oid, &op, NULL);
-}
-
int RGWRados::obj_operate(rgw_obj& obj, ObjectWriteOperation *op)
{
rgw_rados_ref ref;
bool *is_truncated, RGWUsageIter& read_iter, map<rgw_user_bucket, rgw_usage_log_entry>& usage);
int trim_usage(string& user, uint64_t start_epoch, uint64_t end_epoch);
- /**
- * get listing of the objects in a bucket.
- * bucket: bucket to list contents of
- * max: maximum number of results to return
- * prefix: only return results that match this prefix
- * delim: do not include results that match this string.
- * Any skipped results will have the matching portion of their name
- * inserted in common_prefixes with a "true" mark.
- * marker: if filled in, begin the listing with this object.
- * result: the objects are put in here.
- * common_prefixes: if delim is filled in, any matching prefixes are placed
- * here.
- */
- virtual int list_objects(rgw_bucket& bucket, int max, std::string& prefix, std::string& delim,
- const rgw_obj_key& marker, rgw_obj_key *next_marker, std::vector<RGWObjEnt>& result,
- map<string, bool>& common_prefixes, bool get_content_type, string& ns, bool enforce_ns,
- bool list_versions,
- bool *is_truncated, RGWAccessListFilter *filter);
-
virtual int create_pool(rgw_bucket& bucket);
/**
struct GetObjState {
librados::IoCtx io_ctx;
- bool sent_data;
-
- GetObjState() : sent_data(false) {}
} state;
struct ConditionParams {
int complete_del(int64_t poolid, uint64_t epoch);
int cancel();
};
+
+ struct List {
+ RGWRados::Bucket *target;
+ rgw_obj_key next_marker;
+
+ struct Params {
+ string prefix;
+ string delim;
+ rgw_obj_key marker;
+ string ns;
+ bool enforce_ns;
+ RGWAccessListFilter *filter;
+ bool list_versions;
+
+ Params() : enforce_ns(true), filter(NULL), list_versions(false) {}
+ } params;
+
+ public:
+ List(RGWRados::Bucket *_target) : target(_target) {}
+
+ int list_objects(int max, vector<RGWObjEnt> *result, map<string, bool> *common_prefixes, bool *is_truncated);
+ rgw_obj_key& get_next_marker() {
+ return next_marker;
+ }
+ };
};
/** Write/overwrite an object to the bucket storage. */
/**
* a simple object read without keeping state
*/
- virtual int read(void *ctx, rgw_obj& obj, off_t ofs, size_t size, bufferlist& bl);
virtual int raw_obj_stat(rgw_obj& obj, uint64_t *psize, time_t *pmtime, uint64_t *epoch,
map<string, bufferlist> *attrs, bufferlist *first_chunk,
void gen_rand_obj_instance_name(rgw_obj *target);
- virtual bool supports_omap() { return true; }
int omap_get_vals(rgw_obj& obj, bufferlist& header, const std::string& marker, uint64_t count, std::map<string, bufferlist>& m);
virtual int omap_get_all(rgw_obj& obj, bufferlist& header, std::map<string, bufferlist>& m);
virtual int omap_set(rgw_obj& obj, std::string& key, bufferlist& bl);
virtual int watch_cb(int opcode, uint64_t ver, bufferlist& bl) { return 0; }
void pick_control_oid(const string& key, string& notify_oid);
- void *create_context(void *user_ctx) {
- RGWObjectCtx *rctx = new RGWObjectCtx(this);
- rctx->user_ctx = user_ctx;
- return rctx;
- }
- void destroy_context(void *ctx) {
- delete static_cast<RGWObjectCtx *>(ctx);
- }
void set_atomic(void *ctx, rgw_obj& obj) {
RGWObjectCtx *rctx = static_cast<RGWObjectCtx *>(ctx);
rctx->set_atomic(obj);
int lock_exclusive(rgw_bucket& pool, const string& oid, utime_t& duration, string& zone_id, string& owner_id);
int unlock(rgw_bucket& pool, const string& oid, string& zone_id, string& owner_id);
- /// clean up/process any temporary objects older than given date[/time]
- int remove_temp_objects(string date, string time);
-
int gc_operate(string& oid, librados::ObjectWriteOperation *op);
int gc_aio_operate(string& oid, librados::ObjectWriteOperation *op);
int gc_operate(string& oid, librados::ObjectReadOperation *op, bufferlist *pbl);
#include "rgw/rgw_log.h"
TYPE(rgw_log_entry)
-TYPE(rgw_intent_log_entry)
#include "cls/rbd/cls_rbd.h"
TYPE(cls_rbd_parent)