diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-02-19 16:34:50 -0800 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-03-22 11:23:57 -0700 |
commit | 50d89d4ac4090842bb2b91d1a9b481c4b63e5f5c (patch) | |
tree | fd122e96f64dd5a40b01465a3d16aebef3440f0c | |
parent | 960d765e5e9e66e028ceb611d3811dc8d7cfccea (diff) | |
download | ceph-50d89d4ac4090842bb2b91d1a9b481c4b63e5f5c.tar.gz |
rgw: admin command to show region info
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/rgw/rgw_admin.cc | 25 | ||||
-rw-r--r-- | src/rgw/rgw_rados.cc | 26 | ||||
-rw-r--r-- | src/rgw/rgw_rados.h | 19 |
3 files changed, 56 insertions, 14 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 6f8ce85092f..756651db28a 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -981,12 +981,19 @@ int main(int argc, char **argv) return usage(); } + bool region_op = (opt_cmd == OPT_REGION_INFO); + + user_modify_op = (opt_cmd == OPT_USER_MODIFY || opt_cmd == OPT_SUBUSER_MODIFY || opt_cmd == OPT_SUBUSER_CREATE || opt_cmd == OPT_SUBUSER_RM || opt_cmd == OPT_KEY_CREATE || opt_cmd == OPT_KEY_RM || opt_cmd == OPT_USER_RM || opt_cmd == OPT_CAPS_ADD || opt_cmd == OPT_CAPS_RM); - store = RGWStoreManager::get_storage(g_ceph_context, false); + if (region_op) { + store = RGWStoreManager::get_raw_storage(g_ceph_context); + } else { + store = RGWStoreManager::get_storage(g_ceph_context, false); + } if (!store) { cerr << "couldn't init storage provider" << std::endl; return 5; //EIO @@ -994,6 +1001,22 @@ int main(int argc, char **argv) StoreDestructor store_destructor(store); + if (region_op) { + if (opt_cmd == OPT_REGION_INFO) { + RGWRegion region; + int ret = region.init(g_ceph_context, store); + if (ret < 0) { + cerr << "failed to init region: " << cpp_strerror(-ret) << std::endl; + } + + encode_json("region", region, formatter); + formatter->flush(cout); + cout << std::endl; + } + + return 0; + } + if (opt_cmd != OPT_USER_CREATE && opt_cmd != OPT_LOG_SHOW && opt_cmd != OPT_LOG_LIST && opt_cmd != OPT_LOG_RM && user_id.empty()) { diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index aac634b3c32..e4e005115c9 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -150,7 +150,7 @@ int RGWRegion::set_as_default() return 0; } -int RGWRegion::init(CephContext *_cct, RGWRados *_store, bool create_region) +int RGWRegion::init(CephContext *_cct, RGWRados *_store) { cct = _cct; store = _store; @@ -162,7 +162,7 @@ int RGWRegion::init(CephContext *_cct, RGWRados *_store, bool create_region) if (name.empty()) { int r = read_default(); if (r == -ENOENT) { - r = init_default(); + r = create_default(); if (r < 0) return r; r = set_as_default(); @@ -180,9 +180,6 @@ int RGWRegion::init(CephContext *_cct, RGWRados *_store, bool create_region) string oid = region_info_oid_prefix + "." + name; int ret = rgw_get_obj(store, NULL, pool, oid, bl); - if (ret == -ENOENT && create_region) { - return init_default(); - } if (ret < 0) { lderr(cct) << "failed reading region info from " << pool << ":" << oid << ": " << cpp_strerror(-ret) << dendl; return ret; @@ -199,7 +196,7 @@ int RGWRegion::init(CephContext *_cct, RGWRados *_store, bool create_region) return 0; } -int RGWRegion::init_default() +int RGWRegion::create_default() { name = "default"; string zone_name = "default"; @@ -393,7 +390,7 @@ int RGWRados::init_complete() { int ret; - ret = region.init(cct, this, create_region); + ret = region.init(cct, this); if (ret < 0) return ret; @@ -4250,6 +4247,21 @@ RGWRados *RGWStoreManager::init_storage_provider(CephContext *cct, bool use_gc_t return store; } +RGWRados *RGWStoreManager::init_raw_storage_provider(CephContext *cct) +{ + RGWRados *store = NULL; + store = new RGWRados; + + store->set_context(cct); + + if (store->init_rados() < 0) { + delete store; + return NULL; + } + + return store; +} + void RGWStoreManager::close_storage(RGWRados *store) { if (!store) diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index ce0ee5d2fdc..6ca34c0337c 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -344,8 +344,8 @@ struct RGWRegion { } string get_pool_name(CephContext *cct); - int init(CephContext *_cct, RGWRados *_store, bool create_zone); - int init_default(); + int init(CephContext *_cct, RGWRados *_store); + int create_default(); int store_info(bool exclusive); int read_default(); int set_as_default(); @@ -477,7 +477,6 @@ protected: string region_name; string zone_name; - bool create_region; bool create_zone; public: @@ -487,11 +486,14 @@ public: bucket_id_lock("rados_bucket_id"), max_bucket_id(0), cct(NULL), rados(NULL), pools_initialized(false), - create_region(false), create_zone(false) {} + create_zone(false) {} + + void set_context(CephContext *_cct) { + cct = _cct; + } void set_region(const string& name, bool create) { region_name = name; - create_region = create; } void set_zone(const string& name, bool create) { @@ -514,7 +516,7 @@ public: CephContext *ctx() { return cct; } /** do all necessary setup of the storage device */ int initialize(CephContext *_cct, bool _use_gc_thread) { - cct = _cct; + set_context(cct); use_gc_thread = _use_gc_thread; return initialize(); } @@ -916,7 +918,12 @@ public: RGWRados *store = init_storage_provider(cct, use_gc_thread); return store; } + static RGWRados *get_raw_storage(CephContext *cct) { + RGWRados *store = init_raw_storage_provider(cct); + return store; + } static RGWRados *init_storage_provider(CephContext *cct, bool use_gc_thread); + static RGWRados *init_raw_storage_provider(CephContext *cct); static void close_storage(RGWRados *store); }; |