From: Yehuda Sadeh Date: Wed, 3 Aug 2016 17:24:44 +0000 (-0700) Subject: rgw_admin: can set/modify zone tier's config X-Git-Tag: v11.1.0~681^2~29 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ddbda514d8a664e9037d8dd94fdf3a1aede4ab5e;p=ceph.git rgw_admin: can set/modify zone tier's config Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 4dbac39ac1c8..dac0aef83927 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -209,6 +209,12 @@ void _usage() cout << " --default set entity (realm, zonegroup, zone) as default\n"; cout << " --read-only set zone as read-only (when adding to zonegroup)\n"; cout << " --endpoints= zone endpoints\n"; + cout << " --tier-type= zone tier type\n"; + cout << " --tier-config==[,...]\n"; + cout << " set zone tier config keys, values\n"; + cout << " --tier-config-rm=[,...]\n"; + cout << " unset zone tier config keys\n"; + cout << " --tier_type= zone tier type\n"; cout << " --fix besides checking bucket index, will also fix it\n"; cout << " --check-objects bucket check: rebuilds bucket index according to\n"; cout << " actual objects state\n"; @@ -1966,7 +1972,21 @@ static void sync_status(Formatter *formatter) tab_dump("data sync", width, data_status); } -int main(int argc, char **argv) +static void parse_tier_config_param(const string& s, map& out) +{ + list confs; + get_str_list(s, ",", confs); + for (auto c : confs) { + ssize_t pos = c.find("="); + if (pos < 0) { + out[c] = ""; + } else { + out[c.substr(0, pos)] = c.substr(pos + 1); + } + } +} + +int main(int argc, char **argv) { vector args; argv_to_vec(argc, (const char **)argv, args); @@ -2087,6 +2107,13 @@ int main(int argc, char **argv) string source_zone_name; string source_zone; /* zone id */ + string tier_type; + bool tier_type_specified = false; + + map tier_config_add; + map tier_config_rm; + + for (std::vector::iterator i = args.begin(); i != args.end(); ) { if (ceph_argparse_double_dash(args, i)) { break; @@ -2351,6 +2378,13 @@ int main(int argc, char **argv) get_str_list(val, endpoints); } else if (ceph_argparse_witharg(args, i, &val, "--source-zone", (char*)NULL)) { source_zone_name = val; + } else if (ceph_argparse_witharg(args, i, &val, "--tier-type", (char*)NULL)) { + tier_type = val; + tier_type_specified = true; + } else if (ceph_argparse_witharg(args, i, &val, "--tier-config", (char*)NULL)) { + parse_tier_config_param(val, tier_config_add); + } else if (ceph_argparse_witharg(args, i, &val, "--tier-config-rm", (char*)NULL)) { + parse_tier_config_param(val, tier_config_rm); } else if (strncmp(*i, "-", 1) == 0) { cerr << "ERROR: invalid flag " << *i << std::endl; return EINVAL; @@ -2884,10 +2918,13 @@ int main(int argc, char **argv) cerr << "unable to initialize zone: " << cpp_strerror(-ret) << std::endl; return -ret; } + string *ptier_type = (tier_type_specified ? &tier_type : nullptr); + zone.tier_config = tier_config_add; + ret = zonegroup.add_zone(zone, (is_master_set ? &is_master : NULL), (is_read_only_set ? &read_only : NULL), - endpoints); + endpoints, ptier_type); if (ret < 0) { cerr << "failed to add zone " << zone_name << " to zonegroup " << zonegroup.get_name() << ": " << cpp_strerror(-ret) << std::endl; @@ -3302,10 +3339,12 @@ int main(int argc, char **argv) } if (!zonegroup_id.empty() || !zonegroup_name.empty()) { + string *ptier_type = (tier_type_specified ? &tier_type : nullptr); ret = zonegroup.add_zone(zone, (is_master_set ? &is_master : NULL), (is_read_only_set ? &read_only : NULL), - endpoints); + endpoints, + ptier_type); if (ret < 0) { cerr << "failed to add zone " << zone_name << " to zonegroup " << zonegroup.get_name() << ": " << cpp_strerror(-ret) << std::endl; @@ -3547,6 +3586,16 @@ int main(int argc, char **argv) need_zone_update = true; } + for (auto add : tier_config_add) { + zone.tier_config[add.first] = add.second; + need_zone_update = true; + } + + for (auto rm : tier_config_rm) { + zone.tier_config.erase(rm.first); + need_zone_update = true; + } + if (need_zone_update) { ret = zone.update(); if (ret < 0) { @@ -3561,11 +3610,12 @@ int main(int argc, char **argv) cerr << "failed to init zonegroup: " << cpp_strerror(-ret) << std::endl; return -ret; } + string *ptier_type = (tier_type_specified ? &tier_type : nullptr); ret = zonegroup.add_zone(zone, (is_master_set ? &is_master : NULL), (is_read_only_set ? &read_only : NULL), - endpoints); + endpoints, ptier_type); if (ret < 0) { cerr << "failed to update zonegroup: " << cpp_strerror(-ret) << std::endl; return -ret; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 6c41f7d8cebf..84b63bd0e87a 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -247,7 +247,8 @@ int RGWZoneGroup::equals(const string& other_zonegroup) const return (id == other_zonegroup); } -int RGWZoneGroup::add_zone(const RGWZoneParams& zone_params, bool *is_master, bool *read_only, const list& endpoints) +int RGWZoneGroup::add_zone(const RGWZoneParams& zone_params, bool *is_master, bool *read_only, const list& endpoints, + const string *ptier_type) { auto& zone_id = zone_params.get_id(); auto& zone_name = zone_params.get_name(); @@ -283,6 +284,9 @@ int RGWZoneGroup::add_zone(const RGWZoneParams& zone_params, bool *is_master, bo if (read_only) { zone.read_only = *read_only; } + if (ptier_type) { + zone.tier_type = *ptier_type; + } post_process_params(); diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 13e1a7b3c97f..209269332cf4 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1216,7 +1216,7 @@ struct RGWZoneGroup : public RGWSystemMetaObj { int set_as_default(bool exclusive = false) override; int create_default(bool old_format = false); int equals(const string& other_zonegroup) const; - int add_zone(const RGWZoneParams& zone_params, bool *is_master, bool *read_only, const list& endpoints); + int add_zone(const RGWZoneParams& zone_params, bool *is_master, bool *read_only, const list& endpoints, const string *ptier_type); int remove_zone(const std::string& zone_id); int rename_zone(const RGWZoneParams& zone_params); const string& get_pool_name(CephContext *cct);