From: Yehuda Sadeh Date: Tue, 5 Mar 2013 22:43:00 +0000 (-0800) Subject: rgw: add top level metadata handler X-Git-Tag: v0.67-rc1~128^2~189 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ff2d3c95aed2215801407201bdd4cf6c6135aabd;p=ceph.git rgw: add top level metadata handler Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 3a669c0aee1c..f27d819baf55 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1524,7 +1524,7 @@ next: } formatter->flush(cout); - } while (!truncated); + } while (truncated); formatter->close_section(); formatter->flush(cout); diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index 8dfa1c74d282..9296dc28e78b 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -4,12 +4,56 @@ #include "common/ceph_json.h" #include "cls/version/cls_version_types.h" +#include "rgw_rados.h" + obj_version& RGWMetadataObject::get_version() { return objv; } +class RGWMetadataTopHandler : public RGWMetadataHandler { + struct iter_data { + list sections; + list::iterator iter; + }; + +public: + RGWMetadataTopHandler() {} + + virtual string get_type() { return string(); } + + virtual int get(RGWRados *store, string& entry, RGWMetadataObject **obj) { return -ENOTSUP; } + virtual int put(RGWRados *store, string& entry, obj_version& objv, JSONObj *obj) { return -ENOTSUP; } + + virtual int list_keys_init(RGWRados *store, void **phandle) { + iter_data *data = new iter_data; + store->meta_mgr->get_sections(data->sections); + data->iter = data->sections.begin(); + + *phandle = data; + + return 0; + } + virtual int list_keys_next(void *handle, int max, list& keys, bool *truncated) { + iter_data *data = (iter_data *)handle; + for (int i = 0; i < max && data->iter != data->sections.end(); ++i, ++(data->iter)) { + keys.push_back(*data->iter); + } + + *truncated = (data->iter != data->sections.end()); + + return 0; + } + virtual void list_keys_complete(void *handle) { + iter_data *data = (iter_data *)handle; + + delete data; + } +}; + +static RGWMetadataTopHandler md_top_handler; + RGWMetadataManager::~RGWMetadataManager() { map::iterator iter; @@ -50,6 +94,11 @@ int RGWMetadataManager::find_handler(const string& metadata_key, RGWMetadataHand parse_metadata_key(metadata_key, type, entry); + if (type.empty()) { + *handler = &md_top_handler; + return 0; + } + map::iterator iter = handlers.find(type); if (iter == handlers.end()) return -ENOENT; @@ -115,6 +164,7 @@ int RGWMetadataManager::put(string& metadata_key, bufferlist& bl) return handler->put(store, entry, objv, jo); } + struct list_keys_handle { void *handle; RGWMetadataHandler *handler; @@ -125,7 +175,10 @@ int RGWMetadataManager::list_keys_init(string& section, void **handle) { string entry; RGWMetadataHandler *handler; - int ret = find_handler(section, &handler, entry); + + int ret; + + ret = find_handler(section, &handler, entry); if (ret < 0) { return -ENOENT; } @@ -163,4 +216,11 @@ void RGWMetadataManager::list_keys_complete(void *handle) delete h; } +void RGWMetadataManager::get_sections(list& sections) +{ + for (map::iterator iter = handlers.begin(); iter != handlers.end(); ++iter) { + sections.push_back(iter->first); + } +} + diff --git a/src/rgw/rgw_metadata.h b/src/rgw/rgw_metadata.h index 3f92ea0c352e..eb052e7b03cc 100644 --- a/src/rgw/rgw_metadata.h +++ b/src/rgw/rgw_metadata.h @@ -58,6 +58,8 @@ public: 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); + + void get_sections(list& sections); }; #endif