]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw_admin: update zone set
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 16 Oct 2015 20:50:22 +0000 (13:50 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:15 +0000 (16:13 -0800)
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 <yehuda@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 3d981a87b39c0c1739a687a68f9cd94f8cf1f7d4..5342e234a7bc6e1328fd871068e39a795adb0cba 100644 (file)
@@ -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);
index cf6cda2ac03e15b5c76babdcd1456b24b75ce096..118d8d4558477de6821d77c62ca473efbcc0ef4e 100644 (file)
@@ -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;
index 8952b288506998833d111b53d595a5aaee47bf76..085d74db4dfc9e85a9cfe25632ddeadb1c70fbf3 100644 (file)
@@ -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);