rgw/rgw_multi_del.cc \
rgw/rgw_env.cc \
rgw/rgw_cors.cc \
- rgw/rgw_cors_s3.cc
+ rgw/rgw_cors_s3.cc \
+ rgw/rgw_metadata.cc
librgw_a_CFLAGS = ${CRYPTO_CFLAGS} ${AM_CFLAGS}
librgw_a_CXXFLAGS = -Woverloaded-virtual ${AM_CXXFLAGS}
noinst_LIBRARIES += librgw.a
noinst_LIBRARIES += libcls_refcount_client.a
libcls_version_client_a_SOURCES = \
- cls/version/cls_version_client.cc
+ cls/version/cls_version_client.cc \
+ cls/version/cls_version_types.cc
noinst_LIBRARIES += libcls_version_client.a
libcls_rgw_client_a_SOURCES = \
rgw/rgw_multi.h\
rgw/rgw_policy_s3.h\
rgw/rgw_gc.h\
+ rgw/rgw_metadata.h\
rgw/rgw_multi_del.h\
rgw/rgw_op.h\
rgw/rgw_http_client.h\
--- /dev/null
+
+#include "cls/version/cls_version_types.h"
+#include "common/Formatter.h"
+
+
+void obj_version::dump(Formatter *f) const
+{
+ f->dump_int("ver", ver);
+ f->dump_string("tag", tag);
+}
+
return (ver == v->ver &&
tag.compare(v->tag) == 0);
}
+
+ void dump(Formatter *f) const;
};
WRITE_CLASS_ENCODER(obj_version)
cerr << " specified date (and optional time)\n";
cerr << " gc list dump expired garbage collection objects\n";
cerr << " gc process manually process garbage\n";
+ cerr << " metadata get get metadata info\n";
cerr << "options:\n";
cerr << " --uid=<id> user id\n";
cerr << " --subuser=<name> subuser name\n";
OPT_ZONE_LIST,
OPT_CAPS_ADD,
OPT_CAPS_RM,
+ OPT_METADATA_GET,
};
static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
strcmp(cmd, "regions") == 0 ||
strcmp(cmd, "region-map") == 0 ||
strcmp(cmd, "regionmap") == 0 ||
- strcmp(cmd, "zone") == 0) {
+ strcmp(cmd, "zone") == 0 ||
+ strcmp(cmd, "temp") == 0 ||
+ strcmp(cmd, "usage") == 0 ||
+ strcmp(cmd, "user") == 0 ||
+ strcmp(cmd, "metadata") == 0) {
*need_more = true;
return 0;
}
return OPT_GC_LIST;
if (strcmp(cmd, "process") == 0)
return OPT_GC_PROCESS;
+ } else if (strcmp(prev_cmd, "metadata") == 0) {
+ if (strcmp(cmd, "get") == 0)
+ return OPT_METADATA_GET;
}
return -EINVAL;
map<string, bool> categories;
string caps;
int check_objects = false;
- std::string infile;
RGWUserAdminOpState user_op;
RGWBucketAdminOpState bucket_op;
+ string infile;
+ string metadata_key;
std::string val;
std::ostringstream errs;
caps = val;
} else if (ceph_argparse_witharg(args, i, &val, "-i", "--infile", (char*)NULL)) {
infile = val;
+ } else if (ceph_argparse_witharg(args, i, &val, "--metadata-key", (char*)NULL)) {
+ metadata_key = val;
} else {
++i;
}
return 5; //EIO
}
+ rgw_user_init(store->meta_mgr);
+
StoreDestructor store_destructor(store);
if (raw_storage_op) {
check_bad_user_bucket_mapping(store, user_id, fix);
}
+ if (opt_cmd == OPT_METADATA_GET) {
+ int ret = store->meta_mgr->get(metadata_key, formatter);
+ if (ret < 0) {
+ cerr << "ERROR: can't get key: " << cpp_strerror(-ret) << std::endl;
+ return -ret;
+ }
+
+ formatter->flush(cout);
+ }
+
return 0;
}
--- /dev/null
+
+
+#include "rgw_metadata.h"
+
+
+
+RGWMetadataManager::~RGWMetadataManager()
+{
+ map<string, RGWMetadataHandler *>::iterator iter;
+
+ for (iter = handlers.begin(); iter != handlers.end(); ++iter) {
+ delete iter->second;
+ }
+
+ handlers.clear();
+}
+
+int RGWMetadataManager::register_handler(RGWMetadataHandler *handler)
+{
+ string type = handler->get_type();
+
+ if (handlers.find(type) != handlers.end())
+ return -EINVAL;
+
+ handlers[type] = handler;
+
+ return 0;
+}
+
+void RGWMetadataManager::parse_metadata_key(const string& metadata_key, string& type, string& entry)
+{
+ int pos = metadata_key.find(':');
+ if (pos < 0) {
+ type = metadata_key;
+ }
+
+ type = metadata_key.substr(0, pos);
+ entry = metadata_key.substr(pos + 1);
+}
+
+int RGWMetadataManager::find_handler(const string& metadata_key, RGWMetadataHandler **handler, string& entry)
+{
+ string type;
+
+ parse_metadata_key(metadata_key, type, entry);
+
+ map<string, RGWMetadataHandler *>::iterator iter = handlers.find(type);
+ if (iter == handlers.end())
+ return -ENOENT;
+
+ *handler = iter->second;
+
+ return 0;
+
+}
+
+int RGWMetadataManager::get(string& metadata_key, Formatter *f)
+{
+ RGWMetadataHandler *handler;
+ string entry;
+
+ int ret = find_handler(metadata_key, &handler, entry);
+ if (ret < 0)
+ return ret;
+
+ return handler->get(store, metadata_key, entry, f);
+}
+
+int RGWMetadataManager::update(string& metadata_key, bufferlist& bl)
+{
+ RGWMetadataHandler *handler;
+ string entry;
+
+ int ret = find_handler(metadata_key, &handler, entry);
+ if (ret < 0)
+ return ret;
+
+ return handler->update(store, entry, bl);
+}
+
+
--- /dev/null
+#ifndef CEPH_RGW_METADATA_H
+#define CEPH_RGW_METADATA_H
+
+#include <string>
+
+#include "include/types.h"
+#include "rgw_common.h"
+
+class RGWRados;
+
+
+class RGWMetadataHandler {
+public:
+ virtual ~RGWMetadataHandler() {}
+ virtual string get_type() = 0;
+
+ virtual int get(RGWRados *store, string& key, string& entry, Formatter *f) = 0;
+ virtual int update(RGWRados *store, string& entry, bufferlist& bl) = 0;
+};
+
+
+class RGWMetadataManager {
+ map<string, RGWMetadataHandler *> handlers;
+ RGWRados *store;
+
+ void parse_metadata_key(const string& metadata_key, string& type, string& entry);
+
+ int find_handler(const string& metadata_key, RGWMetadataHandler **handler, string& entry);
+
+public:
+ RGWMetadataManager(RGWRados *_store) : store(_store) {}
+ ~RGWMetadataManager();
+
+ int register_handler(RGWMetadataHandler *handler);
+
+ int get(string& metadata_key, Formatter *f);
+ int update(string& metadata_key, bufferlist& bl);
+};
+
+#endif
#include "rgw_rados.h"
#include "rgw_cache.h"
#include "rgw_acl.h"
+#include "rgw_metadata.h"
#include "cls/rgw/cls_rgw_types.h"
#include "cls/rgw/cls_rgw_client.h"
void RGWRados::finalize()
{
+ delete meta_mgr;
if (use_gc_thread) {
gc->stop_processor();
delete gc;
{
int ret;
+ meta_mgr = new RGWMetadataManager(this);
+
ret = init_rados();
if (ret < 0)
return ret;
#include "cls/rgw/cls_rgw_types.h"
#include "cls/version/cls_version_types.h"
#include "rgw_log.h"
+#include "rgw_metadata.h"
class RGWWatcher;
class SafeTimer;
num_watchers(0), watchers(NULL), watch_handles(NULL),
bucket_id_lock("rados_bucket_id"), max_bucket_id(0),
cct(NULL), rados(NULL),
- pools_initialized(false) {}
+ pools_initialized(false), meta_mgr(NULL) {}
void set_context(CephContext *_cct) {
cct = _cct;
RGWRegion region;
RGWZoneParams zone;
+ RGWMetadataManager *meta_mgr;
+
virtual ~RGWRados() {
if (rados) {
rados->shutdown();
#include <map>
#include "common/errno.h"
+#include "common/Formatter.h"
+#include "common/ceph_json.h"
#include "rgw_rados.h"
#include "rgw_acl.h"
}
/**
- * Given an email, finds the user info associated with it.
+ * Given a uid, finds the user info associated with it.
* returns: 0 on success, -ERR# on failure (including nonexistence)
*/
-int rgw_get_user_info_by_uid(RGWRados *store, string& uid, RGWUserInfo& info)
+static int rgw_read_uid_info(RGWRados *store, string& uid, RGWUserInfo& info, obj_version *objv)
{
bufferlist bl;
RGWUID user_id;
- int ret = rgw_get_system_obj(store, NULL, store->zone.user_uid_pool, uid, bl, NULL);
+ int ret = rgw_get_system_obj(store, NULL, store->zone.user_uid_pool, uid, bl, objv);
if (ret < 0)
return ret;
return 0;
}
+int rgw_get_user_info_by_uid(RGWRados *store, string& uid, RGWUserInfo& info)
+{
+ return rgw_read_uid_info(store, uid, info, NULL);
+}
+
/**
* Given an email, finds the user info associated with it.
* returns: 0 on success, -ERR# on failure (including nonexistence)
return 0;
}
+
int RGWUserAdminOp_Caps::remove(RGWRados *store, RGWUserAdminOpState& op_state,
RGWFormatterFlusher& flusher)
{
return 0;
}
+
+class RGWUserMetadataHandler : public RGWMetadataHandler {
+public:
+ string get_type() { return "user"; }
+ int get(RGWRados *store, string& key, string& entry, Formatter *f) {
+ RGWUserInfo info;
+
+ obj_version objv;
+
+ int ret = rgw_read_uid_info(store, entry, info, &objv);
+ if (ret < 0)
+ return ret;
+
+ f->open_object_section("metadata_info");
+ encode_json("key", key, f);
+ encode_json("ver", objv, f);
+ encode_json("data", info, f);
+ f->close_section();
+ f->flush(cout);
+ return 0;
+ }
+
+ int update(RGWRados *store, string& metadata_key, bufferlist& bl) {
+ return 0;
+ }
+};
+
+void rgw_user_init(RGWMetadataManager *mm)
+{
+ mm->register_handler(new RGWUserMetadataHandler);
+}
RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher);
};
+class RGWMetadataManager;
+
+extern void rgw_user_init(RGWMetadataManager *mm);
+
#endif