summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-02-21 17:46:24 -0800
committerYehuda Sadeh <yehuda@inktank.com>2013-02-25 15:01:20 -0800
commit8b626203e300d4d4b3d0b4b296e491895025fd62 (patch)
treec0e74444133e8b402643ed2fc5bd0cca1cd6f6b7
parentea7b0bdc94a7f5dfe5e4492928c8804d38457174 (diff)
downloadceph-8b626203e300d4d4b3d0b4b296e491895025fd62.tar.gz
rgw: get/set region map
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/rgw/rgw_admin.cc41
-rw-r--r--src/rgw/rgw_rados.cc49
-rw-r--r--src/rgw/rgw_rados.h4
3 files changed, 94 insertions, 0 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc
index 7bfff58106b..941fb28ce67 100644
--- a/src/rgw/rgw_admin.cc
+++ b/src/rgw/rgw_admin.cc
@@ -64,6 +64,8 @@ void _usage()
cerr << " regions list list all regions set on this cluster\n";
cerr << " region set set region info\n";
cerr << " region default set default region\n";
+ cerr << " region-map show show region-map\n";
+ cerr << " region-map set set region-map\n";
cerr << " zone info show zone cluster params\n";
cerr << " zone set set zone cluster params\n";
cerr << " zone list list all zones set on this cluster\n";
@@ -174,6 +176,8 @@ enum {
OPT_REGION_LIST,
OPT_REGION_SET,
OPT_REGION_DEFAULT,
+ OPT_REGIONMAP_SHOW,
+ OPT_REGIONMAP_SET,
OPT_ZONE_INFO,
OPT_ZONE_SET,
OPT_ZONE_LIST,
@@ -212,6 +216,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
strcmp(cmd, "object") == 0 ||
strcmp(cmd, "region") == 0 ||
strcmp(cmd, "regions") == 0 ||
+ strcmp(cmd, "region-map") == 0 ||
+ strcmp(cmd, "regionmap") == 0 ||
strcmp(cmd, "zone") == 0 ||
strcmp(cmd, "temp") == 0 ||
strcmp(cmd, "caps") == 0 ||
@@ -316,6 +322,12 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
} else if (strcmp(prev_cmd, "regions") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_REGION_LIST;
+ } else if (strcmp(prev_cmd, "region-map") == 0 ||
+ strcmp(prev_cmd, "regionmap") == 0) {
+ if (strcmp(cmd, "show") == 0)
+ return OPT_REGIONMAP_SHOW;
+ if (strcmp(cmd, "set") == 0)
+ return OPT_REGIONMAP_SET;
} else if (strcmp(prev_cmd, "zone") == 0) {
if (strcmp(cmd, "info") == 0)
return OPT_ZONE_INFO;
@@ -1008,6 +1020,7 @@ int main(int argc, char **argv)
bool raw_storage_op = (opt_cmd == OPT_REGION_INFO || opt_cmd == OPT_REGION_LIST ||
opt_cmd == OPT_REGION_SET || opt_cmd == OPT_REGION_DEFAULT ||
+ opt_cmd == OPT_REGIONMAP_SHOW || opt_cmd == OPT_REGIONMAP_SET ||
opt_cmd == OPT_ZONE_INFO || opt_cmd == OPT_ZONE_SET ||
opt_cmd == OPT_ZONE_LIST);
@@ -1104,6 +1117,34 @@ int main(int argc, char **argv)
}
}
+ if (opt_cmd == OPT_REGIONMAP_SHOW) {
+ RGWRegionMap regionmap;
+ int ret = regionmap.read(g_ceph_context, store);
+ if (ret < 0) {
+ cerr << "failed to read region map: " << cpp_strerror(-ret) << std::endl;
+ return -ret;
+ }
+ encode_json("region-map", regionmap, formatter);
+ formatter->flush(cout);
+ }
+
+ if (opt_cmd == OPT_REGIONMAP_SET) {
+ RGWRegionMap regionmap;
+ int ret = read_decode_json(infile, regionmap);
+ if (ret < 0) {
+ return 1;
+ }
+
+ ret = regionmap.store(g_ceph_context, store);
+ if (ret < 0) {
+ cerr << "ERROR: couldn't store region map info: " << cpp_strerror(-ret) << std::endl;
+ return 1;
+ }
+
+ encode_json("region-map", regionmap, formatter);
+ formatter->flush(cout);
+ }
+
if (opt_cmd == OPT_ZONE_INFO) {
RGWRegion region;
int ret = region.init(g_ceph_context, store);
diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc
index cbff6c70f18..f94c9c06ee0 100644
--- a/src/rgw/rgw_rados.cc
+++ b/src/rgw/rgw_rados.cc
@@ -52,6 +52,7 @@ static string zone_info_oid_prefix = "zone_info.";
static string region_info_oid_prefix = "region_info.";
static string default_region_info_oid = "default.region";
+static string region_map_oid = "region_map";
static RGWObjCategory shadow_category = RGW_OBJ_CATEGORY_SHADOW;
@@ -305,6 +306,54 @@ int RGWZoneParams::store_info(CephContext *cct, RGWRados *store, RGWRegion& regi
return ret;
}
+void RGWRegionMap::get_params(CephContext *cct, string& pool_name, string& oid)
+{
+ pool_name = cct->_conf->rgw_zone_root_pool;
+ if (pool_name.empty()) {
+ pool_name = RGW_DEFAULT_ZONE_ROOT_POOL;
+ }
+ oid = region_map_oid;
+}
+
+int RGWRegionMap::read(CephContext *cct, RGWRados *store)
+{
+ string pool_name, oid;
+
+ get_params(cct, pool_name, oid);
+
+ rgw_bucket pool(pool_name.c_str());
+
+ bufferlist bl;
+ int ret = rgw_get_obj(store, NULL, pool, oid, bl);
+ if (ret < 0)
+ return ret;
+
+ try {
+ bufferlist::iterator iter = bl.begin();
+ ::decode(*this, iter);
+ } catch (buffer::error& err) {
+ ldout(cct, 0) << "ERROR: failed to decode region map info from " << pool << ":" << oid << dendl;
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int RGWRegionMap::store(CephContext *cct, RGWRados *store)
+{
+ string pool_name, oid;
+
+ get_params(cct, pool_name, oid);
+
+ rgw_bucket pool(pool_name.c_str());
+
+ bufferlist bl;
+ ::encode(*this, bl);
+ int ret = rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), false, NULL);
+
+ return ret;
+}
+
void RGWObjManifest::append(RGWObjManifest& m)
{
map<uint64_t, RGWObjManifestPart>::iterator iter;
diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h
index 043b9844607..5c65cc4e476 100644
--- a/src/rgw/rgw_rados.h
+++ b/src/rgw/rgw_rados.h
@@ -402,6 +402,10 @@ struct RGWRegionMap {
DECODE_FINISH(bl);
}
+ void get_params(CephContext *cct, string& pool_name, string& oid);
+ int read(CephContext *cct, RGWRados *store);
+ int store(CephContext *cct, RGWRados *store);
+
void dump(Formatter *f) const;
void decode_json(JSONObj *obj);
};