summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-01-31 17:13:06 -0800
committerYehuda Sadeh <yehuda@inktank.com>2013-03-22 11:23:57 -0700
commitddeceda8d7eb734e9b6da5242ecc6212df5ffb73 (patch)
tree503926bade99d39b9c39cfc5c44d23d372965958
parent020fb1a02ccb460108902790d3419835744a2660 (diff)
downloadceph-ddeceda8d7eb734e9b6da5242ecc6212df5ffb73.tar.gz
rgw: zone info is configurable
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/rgw/rgw_admin.cc85
-rw-r--r--src/rgw/rgw_rados.cc35
-rw-r--r--src/rgw/rgw_rados.h2
3 files changed, 120 insertions, 2 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc
index d940dbc08d9..96fe9271bae 100644
--- a/src/rgw/rgw_admin.cc
+++ b/src/rgw/rgw_admin.cc
@@ -6,6 +6,8 @@
using namespace std;
+#include "common/ceph_json.h"
+
#include "common/config.h"
#include "common/ceph_argparse.h"
#include "common/Formatter.h"
@@ -163,6 +165,7 @@ enum {
OPT_GC_LIST,
OPT_GC_PROCESS,
OPT_ZONE_INFO,
+ OPT_ZONE_SET,
OPT_CAPS_ADD,
OPT_CAPS_RM,
};
@@ -291,6 +294,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
} else if (strcmp(prev_cmd, "zone") == 0) {
if (strcmp(cmd, "info") == 0)
return OPT_ZONE_INFO;
+ if (strcmp(cmd, "set") == 0)
+ return OPT_ZONE_SET;
} else if (strcmp(prev_cmd, "gc") == 0) {
if (strcmp(cmd, "list") == 0)
return OPT_GC_LIST;
@@ -694,6 +699,65 @@ static bool bucket_object_check_filter(const string& name)
return rgw_obj::translate_raw_obj_to_obj_in_ns(obj, ns);
}
+static int read_input(const string& infile, bufferlist& bl)
+{
+ int fd = 0;
+ if (infile.size()) {
+ fd = open(infile.c_str(), O_RDONLY);
+ if (fd < 0) {
+ int err = -errno;
+ cerr << "error reading input file " << infile << std::endl;
+ return err;
+ }
+ }
+
+#define READ_CHUNK 8196
+ int r;
+
+ do {
+ char buf[READ_CHUNK];
+
+ r = read(fd, buf, READ_CHUNK);
+ if (r < 0) {
+ int err = -errno;
+ cerr << "error while reading input" << std::endl;
+ return err;
+ }
+ bl.append(buf, r);
+ } while (r > 0);
+
+ if (infile.size()) {
+ close(fd);
+ }
+
+ return 0;
+}
+
+template <class T>
+static int read_decode_json(const string& infile, T& t)
+{
+ bufferlist bl;
+ int ret = read_input(infile, bl);
+ if (ret < 0) {
+ cerr << "ERROR: failed to read input: " << cpp_strerror(-ret) << std::endl;
+ return ret;
+ }
+ JSONParser p;
+ ret = p.parse(bl.c_str(), bl.length());
+ if (ret < 0) {
+ cout << "failed to parse JSON" << std::endl;
+ return ret;
+ }
+
+ try {
+ t.decode_json(&p);
+ } catch (JSONDecoder::err& e) {
+ cout << "failed to decode JSON input: " << e.message << std::endl;
+ return -EINVAL;
+ }
+ return 0;
+}
+
class StoreDestructor {
RGWRados *store;
public:
@@ -747,6 +811,7 @@ int main(int argc, char **argv)
map<string, bool> categories;
string caps;
int check_objects = false;
+ string infile;
std::string val;
std::ostringstream errs;
@@ -846,6 +911,8 @@ int main(int argc, char **argv)
// do nothing
} else if (ceph_argparse_witharg(args, i, &val, "--caps", (char*)NULL)) {
caps = val;
+ } else if (ceph_argparse_witharg(args, i, &val, "-i", "--infile", (char*)NULL)) {
+ infile = val;
} else {
++i;
}
@@ -1805,6 +1872,24 @@ next:
formatter->flush(cout);
}
+ if (opt_cmd == OPT_ZONE_SET) {
+ RGWRadosParams params;
+ params.init_default();
+ int ret = read_decode_json(infile, params);
+ if (ret < 0) {
+ return 1;
+ }
+
+ ret = params.store_info(g_ceph_context, store);
+ if (ret < 0) {
+ cerr << "ERROR: couldn't store zone info: " << cpp_strerror(-ret) << std::endl;
+ return 1;
+ }
+
+ params.dump(formatter);
+ formatter->flush(cout);
+ }
+
if (opt_cmd == OPT_USER_CHECK) {
check_bad_user_bucket_mapping(store, user_id, fix);
}
diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc
index b79dd84873d..6e9c62b3793 100644
--- a/src/rgw/rgw_rados.cc
+++ b/src/rgw/rgw_rados.cc
@@ -2,6 +2,8 @@
#include <stdlib.h>
#include <sys/types.h>
+#include "common/ceph_json.h"
+
#include "common/errno.h"
#include "common/Formatter.h"
#include "common/Throttle.h"
@@ -54,7 +56,7 @@ static RGWObjCategory main_category = RGW_OBJ_CATEGORY_MAIN;
#define RGW_USAGE_OBJ_PREFIX "usage."
-#define RGW_DEFAULT_zone_ROOT_POOL ".rgw.root"
+#define RGW_DEFAULT_ZONE_ROOT_POOL ".rgw.root"
#define dout_subsys ceph_subsys_rgw
@@ -89,11 +91,25 @@ void RGWRadosParams::dump(Formatter *f) const
f->close_section();
}
+void RGWRadosParams::decode_json(JSONObj *obj)
+{
+ JSONDecoder::decode_json("domain_root", domain_root.pool, obj);
+ JSONDecoder::decode_json("control_pool", control_pool.pool, obj);
+ JSONDecoder::decode_json("gc_pool", gc_pool.pool, obj);
+ JSONDecoder::decode_json("log_pool", log_pool.pool, obj);
+ JSONDecoder::decode_json("intent_log_pool", intent_log_pool.pool, obj);
+ JSONDecoder::decode_json("usage_log_pool", usage_log_pool.pool, obj);
+ JSONDecoder::decode_json("user_keys_pool", user_keys_pool.pool, obj);
+ JSONDecoder::decode_json("user_email_pool", user_email_pool.pool, obj);
+ JSONDecoder::decode_json("user_swift_pool", user_swift_pool.pool, obj);
+ JSONDecoder::decode_json("user_uid_pool ", user_uid_pool.pool, obj);
+}
+
int RGWRadosParams::init(CephContext *cct, RGWRados *store)
{
string pool_name = cct->_conf->rgw_zone_root_pool;
if (pool_name.empty())
- pool_name = RGW_DEFAULT_zone_ROOT_POOL;
+ pool_name = RGW_DEFAULT_ZONE_ROOT_POOL;
rgw_bucket pool(pool_name.c_str());
bufferlist bl;
@@ -117,6 +133,21 @@ int RGWRadosParams::init(CephContext *cct, RGWRados *store)
return 0;
}
+int RGWRadosParams::store_info(CephContext *cct, RGWRados *store)
+{
+ string pool_name = cct->_conf->rgw_zone_root_pool;
+ if (pool_name.empty())
+ pool_name = RGW_DEFAULT_ZONE_ROOT_POOL;
+
+ rgw_bucket pool(pool_name.c_str());
+
+ bufferlist bl;
+ ::encode(*this, bl);
+ int ret = rgw_put_system_obj(store, pool, zone_info_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 ed6f35eca72..c919af457e8 100644
--- a/src/rgw/rgw_rados.h
+++ b/src/rgw/rgw_rados.h
@@ -253,6 +253,7 @@ struct RGWRadosParams {
int init(CephContext *cct, RGWRados *store);
void init_default();
+ int store_info(CephContext *cct, RGWRados *store);
void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
@@ -284,6 +285,7 @@ struct RGWRadosParams {
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
+ void decode_json(JSONObj *obj);
};
WRITE_CLASS_ENCODER(RGWRadosParams);