]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: metadata manager, api to list keys
authorYehuda Sadeh <yehuda@inktank.com>
Mon, 4 Mar 2013 20:25:34 +0000 (12:25 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 8 May 2013 17:55:50 +0000 (10:55 -0700)
Also, implement key listing for user metadata.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_metadata.cc
src/rgw/rgw_metadata.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_user.cc

index 76fbe792b3006caeee59c2b441b9c149195a4b6a..e85e0eed74fff0703e26ff35a50c99d45c362c4a 100644 (file)
@@ -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<RGWObjCategory, RGWBucketStats>& stats, Formatter *formatter)
 {
   map<RGWObjCategory, RGWBucketStats>::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<string> 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<string>::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;
 }
index dbc1f269a13041759e3f5bc596c052101c481f4c..841779f3ceb2853e820bfbbc9fc0591c8b561b46 100644 (file)
@@ -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<string>& 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;
+}
+
 
index 47518065fffef8b0c1dc2de3d4a10e3ba6d9beb0..704c894f55208e0d2dbb1e122236f24b02b038a5 100644 (file)
@@ -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<string>& 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<string>& keys, bool *truncated);
+  void list_keys_complete(void *handle);
 };
 
 #endif
index 5850c7276db1ec8edb57963c0a45edf5a6f37bfd..645f2ff03317f2c77ddf84202c3f44366e85690a 100644 (file)
@@ -577,13 +577,13 @@ int RGWRados::list_raw_prefixed_objs(string pool_name, const string& prefix, lis
   bool is_truncated;
   RGWListRawObjsCtx ctx;
   do {
-    vector<string> oids;
+    list<string> oids;
     int r = list_raw_objects(pool, prefix, 1000,
                             ctx, oids, &is_truncated);
     if (r < 0) {
       return r;
     }
-    vector<string>::iterator iter;
+    list<string>::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<string>& oids,
+                              int max, RGWListRawObjsCtx& ctx, list<string>& oids,
                               bool *is_truncated)
 {
   RGWAccessListFilterPrefix filter(prefix_filter);
index a792cb4d788e75fa66b8f3f3443d41eab7560760..b262e6dc4b519d46b5425bbce6106053524e0c48 100644 (file)
@@ -555,6 +555,10 @@ public:
     }
   }
 
+  int list_raw_objects(rgw_bucket& pool, const string& prefix_filter, int max,
+                       RGWListRawObjsCtx& ctx, list<string>& oids,
+                       bool *is_truncated);
+
   int list_raw_prefixed_objs(string pool_name, const string& prefix, list<string>& result);
   int list_regions(list<string>& regions);
   int list_zones(list<string>& zones);
@@ -1003,10 +1007,6 @@ public:
   int pool_iterate(RGWPoolIterCtx& ctx, uint32_t num, vector<RGWObjEnt>& objs,
                    bool *is_truncated, RGWAccessListFilter *filter);
 
-  int list_raw_objects(rgw_bucket& pool, const string& prefix_filter, int max,
-                       RGWListRawObjsCtx& ctx, vector<string>& oids,
-                       bool *is_truncated);
-
   uint64_t instance_id();
   uint64_t next_bucket_id();
 
index 6973586a60d15c583c9b15edb7881eaad5967f19..1a45ebbb8171976aa1d826d38dc3f24ee5ce8a15 100644 (file)
@@ -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<string>& 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)