]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
radosgw-admin: realm set should create a new realm
authorOrit Wasserman <owasserm@redhat.com>
Sun, 1 Jan 2017 10:36:04 +0000 (12:36 +0200)
committerNathan Cutler <ncutler@suse.com>
Sun, 29 Jan 2017 11:30:38 +0000 (12:30 +0100)
Fixes: http://tracker.ceph.com/issues/18333
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
(cherry picked from commit e23339c9ef34f6b9df90b1ab64b550af9b541d9e)

src/rgw/rgw_admin.cc
src/rgw/rgw_rados.h

index a2d93148345661922879e8e3e3d03060ebeff18f..294d9e130b2c89f4002a8f992a657e38d402f0d0 100644 (file)
@@ -2649,7 +2649,7 @@ int main(int argc, char **argv)
          cerr << "failed to list realmss: " << cpp_strerror(-ret) << std::endl;
          return -ret;
        }
-       formatter->open_object_section("realmss_list");
+       formatter->open_object_section("realms_list");
        encode_json("default_info", default_id, formatter);
        encode_json("realms", realms, formatter);
        formatter->close_section();
@@ -2712,19 +2712,33 @@ int main(int argc, char **argv)
          return -EINVAL;
         }
        RGWRealm realm(realm_id, realm_name);
-       int ret = realm.init(g_ceph_context, store, false);
-       if (ret < 0) {
+       bool new_realm = false;
+       int ret = realm.init(g_ceph_context, store);
+       if (ret < 0 && ret != -ENOENT) {
          cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl;
          return -ret;
+       } else if (ret == -ENOENT) {
+         new_realm = true;
        }
        ret = read_decode_json(infile, realm);
        if (ret < 0) {
          return 1;
        }
-       ret = realm.update();
-       if (ret < 0) {
-         cerr << "ERROR: couldn't store realm info: " << cpp_strerror(-ret) << std::endl;
-         return 1;
+       /* new realm */
+       if (new_realm) {
+         cout << "clearing period and epoch for new realm" << std::endl;
+         realm.clear_current_period_and_epoch();
+         ret = realm.create();
+         if (ret < 0) {
+           cerr << "ERROR: couldn't create new realm: " << cpp_strerror(-ret) << std::endl;
+           return 1;
+         }
+       } else {
+         ret = realm.update();
+         if (ret < 0) {
+           cerr << "ERROR: couldn't store realm info: " << cpp_strerror(-ret) << std::endl;
+           return 1;
+         }
        }
 
         if (set_default) {
index 0d3db37b5ef659eabad3af104e0a6e9c0a59fd69..bb54b31d246b4e39859bee241a140af04c17c7ea 100644 (file)
@@ -1383,7 +1383,10 @@ public:
     return current_period;
   }
   int set_current_period(RGWPeriod& period);
-
+  void clear_current_period_and_epoch() {
+    current_period.clear();
+    epoch = 0;
+  }
   epoch_t get_epoch() const { return epoch; }
 
   string get_control_oid();