From: Yehuda Sadeh Date: Mon, 4 Mar 2013 20:25:34 +0000 (-0800) Subject: rgw: metadata manager, api to list keys X-Git-Tag: v0.67-rc1~128^2~191 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1269986dade27461bf32afc90c0e0448a16509b7;p=ceph.git rgw: metadata manager, api to list keys Also, implement key listing for user metadata. Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 76fbe792b300..e85e0eed74ff 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -187,6 +187,7 @@ enum { OPT_CAPS_ADD, OPT_CAPS_RM, OPT_METADATA_GET, + OPT_METADATA_LIST, }; static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more) @@ -340,6 +341,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more) } else if (strcmp(prev_cmd, "metadata") == 0) { if (strcmp(cmd, "get") == 0) return OPT_METADATA_GET; + if (strcmp(cmd, "list") == 0) + return OPT_METADATA_LIST; } return -EINVAL; @@ -373,7 +376,6 @@ static void show_user_info(RGWUserInfo& info, Formatter *formatter) cout << std::endl; } - static void dump_bucket_usage(map& stats, Formatter *formatter) { map::iterator iter; @@ -1460,5 +1462,39 @@ next: formatter->flush(cout); } + if (opt_cmd == OPT_METADATA_LIST) { + void *handle; + int max = 1000; + int ret = store->meta_mgr->list_keys_init(metadata_key, &handle); + if (ret < 0) { + cerr << "ERROR: can't get key: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + + bool truncated; + + formatter->open_array_section("keys"); + + do { + list keys; + ret = store->meta_mgr->list_keys_next(handle, max, keys, &truncated); + if (ret < 0) { + cerr << "ERROR: lists_keys_next(): " << cpp_strerror(-ret) << std::endl; + return -ret; + } + + for (list::iterator iter = keys.begin(); iter != keys.end(); ++iter) { + formatter->dump_string("key", *iter); + } + formatter->flush(cout); + + } while (!truncated); + + formatter->close_section(); + formatter->flush(cout); + + store->meta_mgr->list_keys_complete(handle); + } + return 0; } diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index dbc1f269a130..841779f3ceb2 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -58,10 +58,10 @@ int RGWMetadataManager::get(string& metadata_key, Formatter *f) { RGWMetadataHandler *handler; string entry; - int ret = find_handler(metadata_key, &handler, entry); - if (ret < 0) + if (ret < 0) { return ret; + } return handler->get(store, metadata_key, entry, f); } @@ -78,4 +78,52 @@ int RGWMetadataManager::update(string& metadata_key, bufferlist& bl) return handler->update(store, entry, bl); } +struct list_keys_handle { + void *handle; + RGWMetadataHandler *handler; +}; + + +int RGWMetadataManager::list_keys_init(string& section, void **handle) +{ + string entry; + RGWMetadataHandler *handler; + int ret = find_handler(section, &handler, entry); + if (ret < 0) { + return -ENOENT; + } + + list_keys_handle *h = new list_keys_handle; + h->handler = handler; + ret = handler->list_keys_init(store, &h->handle); + if (ret < 0) { + delete h; + return ret; + } + + *handle = (void *)h; + + return 0; +} + +int RGWMetadataManager::list_keys_next(void *handle, int max, list& keys, bool *truncated) +{ + list_keys_handle *h = (list_keys_handle *)handle; + + RGWMetadataHandler *handler = h->handler; + + return handler->list_keys_next(h->handle, max, keys, truncated); +} + + +void RGWMetadataManager::list_keys_complete(void *handle) +{ + list_keys_handle *h = (list_keys_handle *)handle; + + RGWMetadataHandler *handler = h->handler; + + handler->list_keys_complete(h->handle); + delete h; +} + diff --git a/src/rgw/rgw_metadata.h b/src/rgw/rgw_metadata.h index 47518065fffe..704c894f5520 100644 --- a/src/rgw/rgw_metadata.h +++ b/src/rgw/rgw_metadata.h @@ -16,6 +16,10 @@ public: virtual int get(RGWRados *store, string& key, string& entry, Formatter *f) = 0; virtual int update(RGWRados *store, string& entry, bufferlist& bl) = 0; + + virtual int list_keys_init(RGWRados *store, void **phandle) = 0; + virtual int list_keys_next(void *handle, int max, list& keys, bool *truncated) = 0; + virtual void list_keys_complete(void *handle) = 0; }; @@ -35,6 +39,10 @@ public: int get(string& metadata_key, Formatter *f); int update(string& metadata_key, bufferlist& bl); + + int list_keys_init(string& section, void **phandle); + int list_keys_next(void *handle, int max, list& keys, bool *truncated); + void list_keys_complete(void *handle); }; #endif diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 5850c7276db1..645f2ff03317 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -577,13 +577,13 @@ int RGWRados::list_raw_prefixed_objs(string pool_name, const string& prefix, lis bool is_truncated; RGWListRawObjsCtx ctx; do { - vector oids; + list oids; int r = list_raw_objects(pool, prefix, 1000, ctx, oids, &is_truncated); if (r < 0) { return r; } - vector::iterator iter; + list::iterator iter; for (iter = oids.begin(); iter != oids.end(); ++iter) { string& val = *iter; if (val.size() > prefix.size()) @@ -3856,7 +3856,7 @@ struct RGWAccessListFilterPrefix : public RGWAccessListFilter { }; int RGWRados::list_raw_objects(rgw_bucket& pool, const string& prefix_filter, - int max, RGWListRawObjsCtx& ctx, vector& oids, + int max, RGWListRawObjsCtx& ctx, list& oids, bool *is_truncated) { RGWAccessListFilterPrefix filter(prefix_filter); diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index a792cb4d788e..b262e6dc4b51 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -555,6 +555,10 @@ public: } } + int list_raw_objects(rgw_bucket& pool, const string& prefix_filter, int max, + RGWListRawObjsCtx& ctx, list& oids, + bool *is_truncated); + int list_raw_prefixed_objs(string pool_name, const string& prefix, list& result); int list_regions(list& regions); int list_zones(list& zones); @@ -1003,10 +1007,6 @@ public: int pool_iterate(RGWPoolIterCtx& ctx, uint32_t num, vector& objs, bool *is_truncated, RGWAccessListFilter *filter); - int list_raw_objects(rgw_bucket& pool, const string& prefix_filter, int max, - RGWListRawObjsCtx& ctx, vector& oids, - bool *is_truncated); - uint64_t instance_id(); uint64_t next_bucket_id(); diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index 6973586a60d1..1a45ebbb8171 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -2243,6 +2243,40 @@ public: int update(RGWRados *store, string& metadata_key, bufferlist& bl) { return 0; } + + struct list_keys_info { + RGWRados *store; + RGWListRawObjsCtx ctx; + }; + + int list_keys_init(RGWRados *store, void **phandle) + { + list_keys_info *info = new list_keys_info; + + info->store = store; + + *phandle = (void *)info; + + return 0; + } + + int list_keys_next(void *handle, int max, list& keys, bool *truncated) { + list_keys_info *info = (list_keys_info *)handle; + + string no_filter; + + keys.clear(); + + RGWRados *store = info->store; + + return store->list_raw_objects(store->zone.user_uid_pool, no_filter, + max, info->ctx, keys, truncated); + } + + void list_keys_complete(void *handle) { + list_keys_info *info = (list_keys_info *)handle; + delete info; + } }; void rgw_user_init(RGWMetadataManager *mm)