]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add top level metadata handler
authorYehuda Sadeh <yehuda@inktank.com>
Tue, 5 Mar 2013 22:43:00 +0000 (14:43 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 8 May 2013 17:55:50 +0000 (10:55 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_metadata.cc
src/rgw/rgw_metadata.h

index 3a669c0aee1c2e714165d6ae0c38a05c68f36f25..f27d819baf5580185013707d4e271906d6d84f16 100644 (file)
@@ -1524,7 +1524,7 @@ next:
       }
       formatter->flush(cout);
 
-    } while (!truncated);
+    } while (truncated);
 
     formatter->close_section();
     formatter->flush(cout);
index 8dfa1c74d282edf712aae7e60a828ec5979b77f7..9296dc28e78b06f56fc31bdfbf2e4dcf7de1dea5 100644 (file)
@@ -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<string> sections;
+    list<string>::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<string>& 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<string, RGWMetadataHandler *>::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<string, RGWMetadataHandler *>::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<string>& sections)
+{
+  for (map<string, RGWMetadataHandler *>::iterator iter = handlers.begin(); iter != handlers.end(); ++iter) {
+    sections.push_back(iter->first);
+  }
+}
+
 
index 3f92ea0c352ef29355c928ba919ff2f5bb85fd41..eb052e7b03cc75a193e0bc6d4edf820356b1aa2e 100644 (file)
@@ -58,6 +58,8 @@ public:
   int list_keys_init(string& section, void **phandle);
   int list_keys_next(void *handle, int max, list<string>& keys, bool *truncated);
   void list_keys_complete(void *handle);
+
+  void get_sections(list<string>& sections);
 };
 
 #endif