diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-01-31 17:13:06 -0800 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-02-12 14:47:37 -0800 |
commit | 58517569cc2747b28ecd1cdbdac06b756e1ae64d (patch) | |
tree | 768c9937dd6a84857866744587e4f7b0106445d0 | |
parent | 01b177e35f464e62e7330060d03c286731a5900c (diff) | |
download | ceph-58517569cc2747b28ecd1cdbdac06b756e1ae64d.tar.gz |
rgw: zone info is configurable
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/rgw/rgw_admin.cc | 86 | ||||
-rw-r--r-- | src/rgw/rgw_rados.cc | 35 | ||||
-rw-r--r-- | src/rgw/rgw_rados.h | 2 |
3 files changed, 121 insertions, 2 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index a2b80d34e51..5235fcf5377 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" @@ -159,6 +161,7 @@ enum { OPT_GC_LIST, OPT_GC_PROCESS, OPT_ZONE_INFO, + OPT_ZONE_SET, OPT_CAPS_ADD, OPT_CAPS_RM, }; @@ -280,6 +283,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; @@ -563,6 +568,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: @@ -616,6 +680,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; @@ -715,6 +780,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; } @@ -1663,5 +1730,24 @@ next: store->params.dump(formatter); 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); + } + return 0; } diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index b66761ebb94..fb9ab3fc715 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" @@ -53,7 +55,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 @@ -88,11 +90,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; @@ -116,6 +132,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 e2ab4e24499..9e8d3cc359f 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -246,6 +246,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); @@ -277,6 +278,7 @@ struct RGWRadosParams { DECODE_FINISH(bl); } void dump(Formatter *f) const; + void decode_json(JSONObj *obj); }; WRITE_CLASS_ENCODER(RGWRadosParams); |