summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-03-04 12:25:34 -0800
committerYehuda Sadeh <yehuda@inktank.com>2013-03-04 12:25:34 -0800
commite8f74c896b015950e7907f87a8aa8c293aab62d7 (patch)
tree013313ebed46b66c978c89c287d61ab49bc1f9a3
parent065f82278cd2ecb1eb562862532857d15b3e1f36 (diff)
downloadceph-e8f74c896b015950e7907f87a8aa8c293aab62d7.tar.gz
rgw: metadata manager, api to list keys
Also, implement key listing for user metadata. Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/rgw/rgw_admin.cc39
-rw-r--r--src/rgw/rgw_metadata.cc52
-rw-r--r--src/rgw/rgw_metadata.h8
-rw-r--r--src/rgw/rgw_rados.cc6
-rw-r--r--src/rgw/rgw_rados.h8
-rw-r--r--src/rgw/rgw_user.cc34
6 files changed, 136 insertions, 11 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc
index 92a405c398f..9977d6fbd7b 100644
--- a/src/rgw/rgw_admin.cc
+++ b/src/rgw/rgw_admin.cc
@@ -186,6 +186,7 @@ enum {
OPT_CAPS_ADD,
OPT_CAPS_RM,
OPT_METADATA_GET,
+ OPT_METADATA_LIST,
};
static uint32_t str_to_perm(const char *str)
@@ -352,6 +353,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;
@@ -421,8 +424,6 @@ static int create_bucket(string bucket_str, string& user_id, string& display_nam
ret = rgw_add_bucket(store, user_id, bucket);
- dout(20) << "ret=" << ret << dendl;
-
if (ret == -EEXIST)
ret = 0;
done:
@@ -2150,5 +2151,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;
}
diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc
index dbc1f269a13..841779f3ceb 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<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;
+}
+
diff --git a/src/rgw/rgw_metadata.h b/src/rgw/rgw_metadata.h
index 47518065fff..704c894f552 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<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
diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc
index 3d5634a2e44..f57d58dbafc 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<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())
@@ -3814,7 +3814,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);
diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h
index ac2a1d98c59..e850ab8a281 100644
--- a/src/rgw/rgw_rados.h
+++ b/src/rgw/rgw_rados.h
@@ -554,6 +554,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);
@@ -994,10 +998,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();
diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc
index 0e86d876252..e6de3224502 100644
--- a/src/rgw/rgw_user.cc
+++ b/src/rgw/rgw_user.cc
@@ -505,6 +505,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;
+ }
};