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-22 11:28:02 -0700
commite7d29f8c37bdaa2c28d071881462f17423fdcb8f (patch)
treee38c4fd04633766e5f47c6dbef1b8cebb81081bf
parent39c213384b438d61884cf452f307c7fa9c4aea85 (diff)
downloadceph-e7d29f8c37bdaa2c28d071881462f17423fdcb8f.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 89ffe021a9d..92ebd06daa8 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)
@@ -354,6 +355,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;
@@ -422,8 +425,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:
@@ -2149,5 +2150,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 767558c9440..9d5a649896a 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())
@@ -3831,7 +3831,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 2da6294e479..f40ef180ef1 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 e9da226bd7c..08bccf7775b 100644
--- a/src/rgw/rgw_user.cc
+++ b/src/rgw/rgw_user.cc
@@ -501,6 +501,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;
+ }
};