summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-02-19 16:34:50 -0800
committerYehuda Sadeh <yehuda@inktank.com>2013-02-25 15:00:06 -0800
commit173cc54eb589b6c6cc77197a0838b60eec5e04f6 (patch)
treed68ae7c7199cb8da5c8cf878f1864372f1b7f76b
parentaaac49b8ef5bf977d1f91b8009f200994499340e (diff)
downloadceph-173cc54eb589b6c6cc77197a0838b60eec5e04f6.tar.gz
rgw: admin command to show region info
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/rgw/rgw_admin.cc25
-rw-r--r--src/rgw/rgw_rados.cc26
-rw-r--r--src/rgw/rgw_rados.h19
3 files changed, 56 insertions, 14 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc
index aac98310ef4..ab946f24716 100644
--- a/src/rgw/rgw_admin.cc
+++ b/src/rgw/rgw_admin.cc
@@ -980,12 +980,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
@@ -993,6 +1000,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 3578bc8b54e..2db32d2055a 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;
@@ -4236,6 +4233,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 5e4796e5ffa..2c38f12b402 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);
};