From d2109c7386533ef985b0480a07c82a3ea5036a44 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 16 Oct 2015 13:50:22 -0700 Subject: [PATCH] rgw_admin: update zone set zone set was broken, now it can update the zone params correctly. Also inheriting the id from the current zone if exists, or uses the zone name. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 38 +++++++++++++++++++++++++++----------- src/rgw/rgw_rados.cc | 29 +++++++++++++++++++++++++++-- src/rgw/rgw_rados.h | 4 +++- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 3d981a87b39c0..5342e234a7bc6 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -2887,31 +2887,47 @@ int main(int argc, char **argv) return -ret; } + ret = zone.read(); + if (ret < 0 && ret != -ENOENT) { + cerr << "zone.read() returned ret=" << ret << std::endl; + return -ret; + } + + string orig_id = zone.get_id(); + ret = read_decode_json(infile, zone); if (ret < 0) { return 1; } - if (zone.get_id().empty() && zone.get_name().empty()) { - cerr << "no zone name id or name in the json provided , assuming old format" << std::endl; + if (zone.get_name().empty()) { + zone.set_name(zone_name); + if (zone.get_name().empty()) { + cerr << "no zone name specified" << std::endl; + return EINVAL; + } + } + + zone_name = zone.get_name(); + + if (zone.get_id().empty()) { + zone.set_id(orig_id); + } + + if (zone.get_id().empty()) { + cerr << "no zone name id the json provided, assuming old format" << std::endl; if (zone_name.empty()) { cerr << "missing zone name" << std::endl; - return -EINVAL; + return EINVAL; } zone.set_name(zone_name); zone.set_id(zone_name); } - ret = zone.create(); - if (ret < 0 && ret != -EEXIST) { + ret = zone.write(false); + if (ret < 0) { cerr << "ERROR: couldn't create zone: " << cpp_strerror(-ret) << std::endl; return 1; - } if (ret == -EEXIST) { - ret = zone.update(); - if (ret < 0) { - cerr << "ERROR: couldn't update zone: " << cpp_strerror(-ret) << std::endl; - return 1; - } } encode_json("zone", zone, formatter); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index cf6cda2ac03e1..118d8d4558477 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -563,6 +563,16 @@ int RGWSystemMetaObj::read_info(const string& obj_id, bool old_format) return 0; } +int RGWSystemMetaObj::read() +{ + int ret = read_id(name, id); + if (ret < 0) { + return ret; + } + + return read_info(id); +} + int RGWSystemMetaObj::create(bool exclusive) { int ret; @@ -572,7 +582,7 @@ int RGWSystemMetaObj::create(bool exclusive) if (exclusive && ret == 0) { ldout(cct, 0) << "ERROR: name " << name << " already in use for obj id " << id << dendl; return -EEXIST; - } else if ( ret != -ENOENT) { + } else if ( ret < 0 && ret != -ENOENT) { lderr(cct) << "failed reading obj id " << id << ": " << cpp_strerror(-ret) << dendl; return ret; } @@ -586,7 +596,7 @@ int RGWSystemMetaObj::create(bool exclusive) id = uuid_str; } - ret = store_info(true); + ret = store_info(exclusive); if (ret < 0) { ldout(cct, 0) << "ERROR: storing info for " << id << ": " << cpp_strerror(-ret) << dendl; return ret; @@ -608,6 +618,21 @@ int RGWSystemMetaObj::store_info(bool exclusive) return rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), exclusive, NULL, 0, NULL); } +int RGWSystemMetaObj::write(bool exclusive) +{ + int ret = store_info(exclusive); + if (ret < 0) { + ldout(cct, 20) << __func__ << "(): store_info() returned ret=" << ret << dendl; + return ret; + } + ret = store_name(exclusive); + if (ret < 0) { + ldout(cct, 20) << __func__ << "(): store_name() returned ret=" << ret << dendl; + return ret; + } + return 0; +} + const string& RGWRealm::get_predefined_name() { return cct->_conf->rgw_realm; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 8952b28850699..085d74db4dfc9 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -791,6 +791,8 @@ public: int delete_obj(bool old_format = false); int rename(const string& new_name); int update() { return store_info(false);} + int read(); + int write(bool exclusive); virtual const string& get_pool_name(CephContext *cct) = 0; virtual const string& get_default_oid(bool old_format = false) = 0; @@ -907,7 +909,7 @@ struct RGWZoneParams : RGWSystemMetaObj { RGWSystemMetaObj::decode(bl); } else if (struct_v >= 2) { ::decode(name, bl); - id = name; + id = name; } if (struct_v >= 3) ::decode(system_key, bl); -- 2.39.5