From be00f9b6cc705ddaf113e2a2a2b779e5f20059d3 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 10 Aug 2012 15:59:44 -0700 Subject: [PATCH] rgw: pool names are not global Move all hard coded pool names outside of the global namespace. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_common.h | 2 -- src/rgw/rgw_log.cc | 8 +++---- src/rgw/rgw_log.h | 4 ---- src/rgw/rgw_rados.cc | 50 +++++++++++++++++++++++++++++--------------- src/rgw/rgw_rados.h | 10 +++++++++ src/rgw/rgw_user.cc | 44 ++++++++++++++++++-------------------- src/rgw/rgw_user.h | 4 ---- 7 files changed, 66 insertions(+), 56 deletions(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index ed082eeddf8af..2cd209e6e9eda 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -37,8 +37,6 @@ namespace ceph { using ceph::crypto::MD5; -#define RGW_CONTROL_BUCKET ".rgw.control" - #define RGW_ATTR_PREFIX "user.rgw." #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl" diff --git a/src/rgw/rgw_log.cc b/src/rgw/rgw_log.cc index 1183b1d09951d..779a394f7ccda 100644 --- a/src/rgw/rgw_log.cc +++ b/src/rgw/rgw_log.cc @@ -8,8 +8,6 @@ #define dout_subsys ceph_subsys_rgw -static rgw_bucket log_bucket(RGW_LOG_POOL_NAME); - static void set_param_str(struct req_state *s, const char *name, string& str) { const char *p = s->env->get(name); @@ -265,13 +263,13 @@ int rgw_log_op(RGWRados *store, struct req_state *s) string oid = render_log_object_name(s->cct->_conf->rgw_log_object_name, &bdt, s->bucket.bucket_id, entry.bucket.c_str()); - rgw_obj obj(log_bucket, oid); + rgw_obj obj(store->params.log_pool, oid); int ret = store->append_async(obj, bl.length(), bl); if (ret == -ENOENT) { string id; map attrs; - ret = store->create_bucket(id, log_bucket, attrs, true); + ret = store->create_bucket(id, store->params.log_pool, attrs, true); if (ret < 0) goto done; // retry @@ -286,7 +284,7 @@ done: int rgw_log_intent(RGWRados *store, rgw_obj& obj, RGWIntentEvent intent, const utime_t& timestamp, bool utc) { - rgw_bucket intent_log_bucket(RGW_INTENT_LOG_POOL_NAME); + rgw_bucket intent_log_bucket(store->params.intent_log_pool); rgw_intent_log_entry entry; entry.obj = obj; diff --git a/src/rgw/rgw_log.h b/src/rgw/rgw_log.h index 6b5e50a6dedfd..e24a157639c3d 100644 --- a/src/rgw/rgw_log.h +++ b/src/rgw/rgw_log.h @@ -6,10 +6,6 @@ class RGWRados; -#define RGW_LOG_POOL_NAME ".log" -#define RGW_INTENT_LOG_POOL_NAME ".intent-log" -#define RGW_USAGE_LOG_POOL_NAME ".usage" - struct rgw_log_entry { string object_owner; string bucket_owner; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 46b5647369130..d02774c1827fa 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -58,6 +58,15 @@ static RGWObjCategory main_category = RGW_OBJ_CATEGORY_MAIN; void RGWRadosParams::init_default() { domain_root = ".rgw"; + control_pool = ".rgw.control"; + gc_pool = ".rgw.gc"; + log_pool = ".log"; + intent_log_pool = ".intent-log"; + usage_log_pool = ".usage"; + user_keys_pool = ".users"; + user_email_pool = ".users.email"; + user_swift_pool = ".users.swift"; + user_uid_pool = ".users.uid"; } @@ -211,15 +220,16 @@ int RGWRados::open_root_pool_ctx() int RGWRados::open_gc_pool_ctx() { - int r = rados->ioctx_create(RGW_GC_BUCKET, gc_pool_ctx); + const char *gc_pool = params.gc_pool.name.c_str(); + int r = rados->ioctx_create(gc_pool, gc_pool_ctx); if (r == -ENOENT) { - r = rados->pool_create(RGW_GC_BUCKET); + r = rados->pool_create(gc_pool); if (r == -EEXIST) r = 0; if (r < 0) return r; - r = rados->ioctx_create(RGW_GC_BUCKET, gc_pool_ctx); + r = rados->ioctx_create(gc_pool, gc_pool_ctx); } return r; @@ -227,15 +237,16 @@ int RGWRados::open_gc_pool_ctx() int RGWRados::init_watch() { - int r = rados->ioctx_create(RGW_CONTROL_BUCKET, control_pool_ctx); + const char *control_pool = params.control_pool.name.c_str(); + int r = rados->ioctx_create(control_pool, control_pool_ctx); if (r == -ENOENT) { - r = rados->pool_create(RGW_CONTROL_BUCKET); + r = rados->pool_create(control_pool); if (r == -EEXIST) r = 0; if (r < 0) return r; - r = rados->ioctx_create(RGW_CONTROL_BUCKET, control_pool_ctx); + r = rados->ioctx_create(control_pool, control_pool_ctx); if (r < 0) return r; } @@ -355,7 +366,8 @@ struct log_list_state { int RGWRados::log_list_init(const string& prefix, RGWAccessHandle *handle) { log_list_state *state = new log_list_state; - int r = rados->ioctx_create(RGW_LOG_POOL_NAME, state->io_ctx); + const char *log_pool = params.log_pool.name.c_str(); + int r = rados->ioctx_create(log_pool, state->io_ctx); if (r < 0) return r; state->prefix = prefix; @@ -387,7 +399,8 @@ int RGWRados::log_list_next(RGWAccessHandle handle, string *name) int RGWRados::log_remove(const string& name) { librados::IoCtx io_ctx; - int r = rados->ioctx_create(RGW_LOG_POOL_NAME, io_ctx); + const char *log_pool = params.log_pool.name.c_str(); + int r = rados->ioctx_create(log_pool, io_ctx); if (r < 0) return r; return io_ctx.remove(name); @@ -406,7 +419,8 @@ struct log_show_state { int RGWRados::log_show_init(const string& name, RGWAccessHandle *handle) { log_show_state *state = new log_show_state; - int r = rados->ioctx_create(RGW_LOG_POOL_NAME, state->io_ctx); + const char *log_pool = params.log_pool.name.c_str(); + int r = rados->ioctx_create(log_pool, state->io_ctx); if (r < 0) return r; state->name = name; @@ -2891,17 +2905,18 @@ int RGWRados::cls_obj_usage_log_add(const string& oid, rgw_usage_log_info& info) { librados::IoCtx io_ctx; - int r = rados->ioctx_create(RGW_USAGE_LOG_POOL_NAME, io_ctx); + const char *usage_log_pool = params.usage_log_pool.name.c_str(); + int r = rados->ioctx_create(usage_log_pool, io_ctx); if (r == -ENOENT) { string id; map attrs; - rgw_bucket pool(RGW_USAGE_LOG_POOL_NAME); + rgw_bucket pool(usage_log_pool); r = create_bucket(id, pool, attrs, true); if (r < 0) return r; // retry - r = rados->ioctx_create(RGW_USAGE_LOG_POOL_NAME, io_ctx); + r = rados->ioctx_create(usage_log_pool, io_ctx); } if (r < 0) return r; @@ -2920,7 +2935,8 @@ int RGWRados::cls_obj_usage_log_read(string& oid, string& user, uint64_t start_e *is_truncated = false; - int r = rados->ioctx_create(RGW_USAGE_LOG_POOL_NAME, io_ctx); + const char *usage_log_pool = params.usage_log_pool.name.c_str(); + int r = rados->ioctx_create(usage_log_pool, io_ctx); if (r < 0) return r; @@ -2934,7 +2950,8 @@ int RGWRados::cls_obj_usage_log_trim(string& oid, string& user, uint64_t start_e { librados::IoCtx io_ctx; - int r = rados->ioctx_create(RGW_USAGE_LOG_POOL_NAME, io_ctx); + const char *usage_log_pool = params.usage_log_pool.name.c_str(); + int r = rados->ioctx_create(usage_log_pool, io_ctx); if (r < 0) return r; @@ -3063,7 +3080,6 @@ int RGWRados::remove_temp_objects(string date, string time) } time_t epoch = mktime(&tm); - rgw_bucket bucket(RGW_INTENT_LOG_POOL_NAME); string prefix, delim, marker; vector objs; map common_prefixes; @@ -3072,7 +3088,7 @@ int RGWRados::remove_temp_objects(string date, string time) bool is_truncated; IntentLogNameFilter filter(date.c_str(), &tm); RGWPoolIterCtx iter_ctx; - int r = pool_iterate_begin(bucket, iter_ctx); + int r = pool_iterate_begin(params.intent_log_pool, iter_ctx); if (r < 0) { cerr << "failed to list objects" << std::endl; return r; @@ -3087,7 +3103,7 @@ int RGWRados::remove_temp_objects(string date, string time) } vector::iterator iter; for (iter = objs.begin(); iter != objs.end(); ++iter) { - process_intent_log(bucket, (*iter).name, epoch, I_DEL_OBJ | I_DEL_DIR, true); + process_intent_log(params.intent_log_pool, (*iter).name, epoch, I_DEL_OBJ | I_DEL_DIR, true); } } while (is_truncated); diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index dba5196c78c21..0030da4919dc0 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -184,6 +184,16 @@ struct RGWPoolIterCtx { struct RGWRadosParams { rgw_bucket domain_root; + rgw_bucket control_pool; + rgw_bucket gc_pool; + rgw_bucket log_pool; + rgw_bucket intent_log_pool; + rgw_bucket usage_log_pool; + + rgw_bucket user_keys_pool; + rgw_bucket user_email_pool; + rgw_bucket user_swift_pool; + rgw_bucket user_uid_pool; void init_default(); }; diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index a61696113334d..a3e19b707d5df 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -14,10 +14,6 @@ using namespace std; -static rgw_bucket ui_key_bucket(USER_INFO_POOL_NAME); -static rgw_bucket ui_email_bucket(USER_INFO_EMAIL_POOL_NAME); -static rgw_bucket ui_swift_bucket(USER_INFO_SWIFT_POOL_NAME); -static rgw_bucket ui_uid_bucket(USER_INFO_UID_POOL_NAME); /** * Get the anonymous (ie, unauthenticated) user info. @@ -78,12 +74,12 @@ int rgw_store_user_info(RGWRados *store, RGWUserInfo& info, bool exclusive) ::encode(ui, uid_bl); ::encode(info, uid_bl); - ret = rgw_put_obj(store, info.user_id, ui_uid_bucket, info.user_id, uid_bl.c_str(), uid_bl.length(), exclusive); + ret = rgw_put_obj(store, info.user_id, store->params.user_uid_pool, info.user_id, uid_bl.c_str(), uid_bl.length(), exclusive); if (ret < 0) return ret; if (info.user_email.size()) { - ret = rgw_put_obj(store, info.user_id, ui_email_bucket, info.user_email, uid_bl.c_str(), uid_bl.length(), exclusive); + ret = rgw_put_obj(store, info.user_id, store->params.user_email_pool, info.user_email, uid_bl.c_str(), uid_bl.length(), exclusive); if (ret < 0) return ret; } @@ -92,7 +88,7 @@ int rgw_store_user_info(RGWRados *store, RGWUserInfo& info, bool exclusive) map::iterator iter = info.access_keys.begin(); for (; iter != info.access_keys.end(); ++iter) { RGWAccessKey& k = iter->second; - ret = rgw_put_obj(store, k.id, ui_key_bucket, k.id, uid_bl.c_str(), uid_bl.length(), exclusive); + ret = rgw_put_obj(store, k.id, store->params.user_keys_pool, k.id, uid_bl.c_str(), uid_bl.length(), exclusive); if (ret < 0) return ret; } @@ -101,7 +97,7 @@ int rgw_store_user_info(RGWRados *store, RGWUserInfo& info, bool exclusive) map::iterator siter; for (siter = info.swift_keys.begin(); siter != info.swift_keys.end(); ++siter) { RGWAccessKey& k = siter->second; - ret = rgw_put_obj(store, info.user_id, ui_swift_bucket, k.id, uid_bl.c_str(), uid_bl.length(), exclusive); + ret = rgw_put_obj(store, info.user_id, store->params.user_swift_pool, k.id, uid_bl.c_str(), uid_bl.length(), exclusive); if (ret < 0) return ret; } @@ -137,7 +133,7 @@ int rgw_get_user_info_from_index(RGWRados *store, string& key, rgw_bucket& bucke */ int rgw_get_user_info_by_uid(RGWRados *store, string& uid, RGWUserInfo& info) { - return rgw_get_user_info_from_index(store, uid, ui_uid_bucket, info); + return rgw_get_user_info_from_index(store, uid, store->params.user_uid_pool, info); } /** @@ -146,7 +142,7 @@ int rgw_get_user_info_by_uid(RGWRados *store, string& uid, RGWUserInfo& info) */ int rgw_get_user_info_by_email(RGWRados *store, string& email, RGWUserInfo& info) { - return rgw_get_user_info_from_index(store, email, ui_email_bucket, info); + return rgw_get_user_info_from_index(store, email, store->params.user_email_pool, info); } /** @@ -155,7 +151,7 @@ int rgw_get_user_info_by_email(RGWRados *store, string& email, RGWUserInfo& info */ extern int rgw_get_user_info_by_swift(RGWRados *store, string& swift_name, RGWUserInfo& info) { - return rgw_get_user_info_from_index(store, swift_name, ui_swift_bucket, info); + return rgw_get_user_info_from_index(store, swift_name, store->params.user_swift_pool, info); } /** @@ -164,7 +160,7 @@ extern int rgw_get_user_info_by_swift(RGWRados *store, string& swift_name, RGWUs */ extern int rgw_get_user_info_by_access_key(RGWRados *store, string& access_key, RGWUserInfo& info) { - return rgw_get_user_info_from_index(store, access_key, ui_key_bucket, info); + return rgw_get_user_info_from_index(store, access_key, store->params.user_keys_pool, info); } static void get_buckets_obj(string& user_id, string& buckets_obj_id) @@ -176,7 +172,7 @@ static void get_buckets_obj(string& user_id, string& buckets_obj_id) static int rgw_read_buckets_from_attr(RGWRados *store, string& user_id, RGWUserBuckets& buckets) { bufferlist bl; - rgw_obj obj(ui_uid_bucket, user_id); + rgw_obj obj(store->params.user_uid_pool, user_id); int ret = store->get_attr(NULL, obj, RGW_ATTR_BUCKETS, bl); if (ret) return ret; @@ -203,7 +199,7 @@ int rgw_read_user_buckets(RGWRados *store, string user_id, RGWUserBuckets& bucke string buckets_obj_id; get_buckets_obj(user_id, buckets_obj_id); bufferlist bl; - rgw_obj obj(ui_uid_bucket, buckets_obj_id); + rgw_obj obj(store->params.user_uid_pool, buckets_obj_id); bufferlist header; map m; @@ -256,7 +252,7 @@ int rgw_write_buckets_attr(RGWRados *store, string user_id, RGWUserBuckets& buck bufferlist bl; buckets.encode(bl); - rgw_obj obj(ui_uid_bucket, user_id); + rgw_obj obj(store->params.user_uid_pool, user_id); int ret = store->set_attr(NULL, obj, RGW_ATTR_BUCKETS, bl); @@ -280,7 +276,7 @@ int rgw_add_bucket(RGWRados *store, string user_id, rgw_bucket& bucket) string buckets_obj_id; get_buckets_obj(user_id, buckets_obj_id); - rgw_obj obj(ui_uid_bucket, buckets_obj_id); + rgw_obj obj(store->params.user_uid_pool, buckets_obj_id); ret = store->omap_set(obj, bucket_name, bl); if (ret < 0) { ldout(store->ctx(), 0) << "ERROR: error adding bucket to directory: " @@ -321,7 +317,7 @@ int rgw_remove_user_bucket_info(RGWRados *store, string user_id, rgw_bucket& buc string buckets_obj_id; get_buckets_obj(user_id, buckets_obj_id); - rgw_obj obj(ui_uid_bucket, buckets_obj_id); + rgw_obj obj(store->params.user_uid_pool, buckets_obj_id); ret = store->omap_del(obj, bucket.name); if (ret < 0) { ldout(store->ctx(), 0) << "ERROR: error removing bucket from directory: " @@ -343,28 +339,28 @@ int rgw_remove_user_bucket_info(RGWRados *store, string user_id, rgw_bucket& buc int rgw_remove_key_index(RGWRados *store, RGWAccessKey& access_key) { - rgw_obj obj(ui_key_bucket, access_key.id); + rgw_obj obj(store->params.user_keys_pool, access_key.id); int ret = store->delete_obj(NULL, obj); return ret; } int rgw_remove_uid_index(RGWRados *store, string& uid) { - rgw_obj obj(ui_uid_bucket, uid); + rgw_obj obj(store->params.user_uid_pool, uid); int ret = store->delete_obj(NULL, obj); return ret; } int rgw_remove_email_index(RGWRados *store, string& email) { - rgw_obj obj(ui_email_bucket, email); + rgw_obj obj(store->params.user_email_pool, email); int ret = store->delete_obj(NULL, obj); return ret; } int rgw_remove_swift_name_index(RGWRados *store, string& swift_name) { - rgw_obj obj(ui_swift_bucket, swift_name); + rgw_obj obj(store->params.user_swift_pool, swift_name); int ret = store->delete_obj(NULL, obj); return ret; } @@ -411,7 +407,7 @@ int rgw_delete_user(RGWRados *store, RGWUserInfo& info) { } } - rgw_obj email_obj(ui_email_bucket, info.user_email); + rgw_obj email_obj(store->params.user_email_pool, info.user_email); ldout(store->ctx(), 10) << "removing email index: " << info.user_email << dendl; ret = store->delete_obj(NULL, email_obj); if (ret < 0 && ret != -ENOENT) { @@ -421,7 +417,7 @@ int rgw_delete_user(RGWRados *store, RGWUserInfo& info) { string buckets_obj_id; get_buckets_obj(info.user_id, buckets_obj_id); - rgw_obj uid_bucks(ui_uid_bucket, buckets_obj_id); + rgw_obj uid_bucks(store->params.user_uid_pool, buckets_obj_id); ldout(store->ctx(), 10) << "removing user buckets index" << dendl; ret = store->delete_obj(NULL, uid_bucks); if (ret < 0 && ret != -ENOENT) { @@ -429,7 +425,7 @@ int rgw_delete_user(RGWRados *store, RGWUserInfo& info) { return ret; } - rgw_obj uid_obj(ui_uid_bucket, info.user_id); + rgw_obj uid_obj(store->params.user_uid_pool, info.user_id); ldout(store->ctx(), 10) << "removing user index: " << info.user_id << dendl; ret = store->delete_obj(NULL, uid_obj); if (ret < 0 && ret != -ENOENT) { diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index 1e570f1b6badb..3ae6b38a15655 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -9,10 +9,6 @@ using namespace std; -#define USER_INFO_POOL_NAME ".users" -#define USER_INFO_EMAIL_POOL_NAME ".users.email" -#define USER_INFO_SWIFT_POOL_NAME ".users.swift" -#define USER_INFO_UID_POOL_NAME ".users.uid" #define RGW_USER_ANON_ID "anonymous" /** -- 2.39.5