From 117bb62d3b73945f1b1d6204235dc754c6475e03 Mon Sep 17 00:00:00 2001 From: Orit Wasserman Date: Wed, 23 Sep 2015 13:41:45 +0200 Subject: [PATCH] rgw: backward compatabilty for zone set command Signed-off-by: Orit Wasserman --- src/rgw/rgw_admin.cc | 31 +++++++++++++++++-------------- src/rgw/rgw_rados.h | 3 +++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index b6532d26ff27a..a8a71df53b3b6 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -2548,34 +2548,37 @@ int main(int argc, char **argv) break; case OPT_ZONE_SET: { + if (zone_name.empty() && zone_id.empty()) { + cerr << "Missing zone name or id " << std::endl; + return -EINVAL; + } RGWZoneGroup zonegroup(zonegroup_id,zonegroup_name); int ret = zonegroup.init(g_ceph_context, store); if (ret < 0) { cerr << "WARNING: failed to initialize zonegroup" << std::endl; } - RGWZoneParams zone; + RGWZoneParams zone(zone_name); ret = zone.init(g_ceph_context, store, zonegroup, false); if (ret < 0) { + return -ret; + } + ret = zone.create(); + if (ret < 0 && ret != -EEXIST) { + cerr << "ERROR: couldn't create zone: " << cpp_strerror(-ret) << std::endl; return 1; } + zone_id = zone.get_id(); ret = read_decode_json(infile, zone); if (ret < 0) { return 1; } - if (zone.get_name().empty() && zone.get_id().empty()) { - cerr << "ERROR: missing zone name " << cpp_strerror(-ret) << std::endl; - return 1; - } - ret = zone.create(); - if (ret < 0 && ret != -EEXIST) { - cerr << "ERROR: couldn't create zone: " << cpp_strerror(-ret) << std::endl; + /* old version may overide the name and id */ + zone.set_name(zone_name); + zone.set_id(zone_id); + ret = zone.update(); + if (ret < 0) { + cerr << "ERROR: couldn't update zone: " << cpp_strerror(-ret) << std::endl; return 1; - } else if (ret == -EEXIST) { - ret = zone.update(); - if (ret < 0) { - cerr << "ERROR: couldn't update zone: " << cpp_strerror(-ret) << std::endl; - return 1; - } } ret = zonegroup.add_zone(zone); if (ret < 0) { diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index a00a5bcfc3978..4446db32c3a63 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -873,6 +873,9 @@ struct RGWZoneParams : RGWSystemMetaObj { void init_id(CephContext *cct, RGWZoneGroup& zonegroup); int create_default(bool old_format = false); + void set_name(const string& _name) { name = _name;} + void set_id(const string& _id) { id = _id;} + void encode(bufferlist& bl) const { ENCODE_START(6, 1, bl); ::encode(domain_root, bl); -- 2.39.5