]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: fix 'mds set allow_new_snaps'
authorSage Weil <sage@inktank.com>
Mon, 3 Feb 2014 21:19:14 +0000 (13:19 -0800)
committerSage Weil <sage@inktank.com>
Tue, 4 Feb 2014 01:50:18 +0000 (17:50 -0800)
We had already added this as a flag (set/unset) when I generalized the
'mds set_max_mds' to be 'ceph mds set <var> <val>'.  Switch the snaps
flag to be a key/value to with true/false (similar to the hashpspool
pool flag) since there are fewer users and the var/val approach is more
general.

Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Greg Farnum <greg@inktank.com>
qa/workunits/cephtool/test.sh
src/mon/MDSMonitor.cc
src/mon/MonCommands.h
src/test/pybind/test_ceph_argparse.py

index 1808d2c2a34d8bf505f8356b206bfc6c8a3e08ef..0e61f9feb74a98c126ce3395d5091792feb9fbef 100755 (executable)
@@ -162,6 +162,15 @@ ceph mds set max_mds 4
 expect_false ceph mds set max_mds asdf
 ceph mds set max_file_size 1000000000
 expect_false ceph mds set max_file_size 123asdf
+
+expect_false ceph mds set allow_new_snaps
+expect_false ceph mds set allow_new_snaps true
+ceph mds set allow_new_snaps true --yes-i-really-mean-it
+ceph mds set allow_new_snaps 0
+ceph mds set allow_new_snaps false
+ceph mds set allow_new_snaps no
+expect_false ceph mds set allow_new_snaps taco
+
 ceph mds stat
 # ceph mds tell mds.a getmap
 # ceph mds rm
index e19c8a9d1458610cff52ef4bb576683b3875ccf4..e24b1d01d1b91f2b0dea073e6c8e02123778cee0 100644 (file)
@@ -853,6 +853,25 @@ bool MDSMonitor::prepare_command(MMonCommand *m)
        goto out;
       }
       pending_mdsmap.max_file_size = n;
+    } else if (var == "allow_new_snaps") {
+      if (val == "false" || val == "no" || (interr.length() == 0 && n == 0)) {
+       pending_mdsmap.clear_snaps_allowed();
+       ss << "disabled new snapshots";
+      } else if (val == "true" || val == "yes" || (interr.length() == 0 && n == 1)) {
+       string confirm;
+       if (!cmd_getval(g_ceph_context, cmdmap, "confirm", confirm) ||
+           confirm != "--yes-i-really-mean-it") {
+         ss << "Snapshots are unstable and will probably break your FS! Set to --yes-i-really-mean-it if you are sure you want to enable them";
+         r = -EPERM;
+         goto out;
+       }
+       pending_mdsmap.set_snaps_allowed();
+       ss << "enabled new snapshots";
+      } else {
+       ss << "value must be true|yes|1 or false|no|0";
+       r = -EINVAL;
+       goto out;
+      }
     } else {
       ss << "unknown variable " << var;
       goto out;
@@ -982,36 +1001,6 @@ bool MDSMonitor::prepare_command(MMonCommand *m)
   } else if (prefix == "mds inline disable") {
     pending_mdsmap.set_inline_data_enabled(false);
     r = 0;
-  } else if (prefix == "mds set") {
-    string key;
-    cmd_getval(g_ceph_context, cmdmap, "key", key);
-    string sure;
-    cmd_getval(g_ceph_context, cmdmap, "sure", sure);
-    if (key == "allow_new_snaps") {
-      if (sure != "--yes-i-really-mean-it") {
-       ss << "Snapshots are unstable and will probably break your FS! Add --yes-i-really-mean-it if you are sure";
-       r = -EPERM;
-      } else {
-       pending_mdsmap.set_snaps_allowed();
-       ss << "turned on snaps";
-       r = 0;
-      }
-    }
-  } else if (prefix == "mds unset") {
-    string key;
-    cmd_getval(g_ceph_context, cmdmap, "key", key);
-    string sure;
-    cmd_getval(g_ceph_context, cmdmap, "sure", sure);
-    if (key == "allow_new_snaps") {
-      if (sure != "--yes-i-really-mean-it") {
-       ss << "this won't get rid of snapshots or restore the cluster if it's broken. Add --yes-i-really-mean-it if you are sure";
-       r = -EPERM;
-      } else {
-       pending_mdsmap.clear_snaps_allowed();
-       ss << "disabled new snapshots";
-       r = 0;
-      }
-    }
   } else if (prefix == "mds add_data_pool") {
     string poolname;
     cmd_getval(g_ceph_context, cmdmap, "pool", poolname);
index 6dd23f3a7863b9833b497ca7d3e12a3d774995b4..de84997db5596804449ec59f586194a34571c624 100644 (file)
@@ -249,8 +249,9 @@ COMMAND("mds set_max_mds " \
        "name=maxmds,type=CephInt,range=0", \
        "set max MDS index", "mds", "rw", "cli,rest")
 COMMAND("mds set " \
-       "name=var,type=CephChoices,strings=max_mds|max_file_size " \
-       "name=val,type=CephString", \
+       "name=var,type=CephChoices,strings=max_mds|max_file_size|allow_new_snaps " \
+       "name=val,type=CephString "                                     \
+       "name=confirm,type=CephString,req=false",                       \
        "set mds parameter <var> to <val>", "mds", "rw", "cli,rest")
 COMMAND("mds setmap " \
        "name=epoch,type=CephInt,range=0", \
@@ -284,15 +285,6 @@ COMMAND("mds inline enable", \
 COMMAND("mds inline disable", \
         "disable inline data feature", \
         "mds", "rw", "cli,rest")
-COMMAND("mds set " \
-        "name=key,type=CephChoices,strings=allow_new_snaps " \
-        "name=sure,type=CephString,req=false", \
-        "set <key>", \
-        "mds", "rw", "cli,rest")
-COMMAND("mds unset " \
-        "name=key,type=CephChoices,strings=allow_new_snaps " \
-        "name=sure,type=CephString,req=false", \
-        "unset <key>", "mds", "rw", "cli,rest")
 COMMAND("mds add_data_pool " \
        "name=pool,type=CephString", \
        "add data pool <pool>", "mds", "rw", "cli,rest")
index 48dea81447a887d72a09e6163e3a787a1d7ddbbf..89cf6c9a6a040a6c4354f9dd71906d9ae5c6c8e3 100755 (executable)
@@ -435,28 +435,12 @@ class TestMDS(TestArgparse):
                                                     'rm_incompat', '1', '1']))
 
     def test_mds_set(self):
-        self.assert_valid_command(['mds', 'set', 'allow_new_snaps'])
-        self.assert_valid_command(['mds', 'set', 'allow_new_snaps', 'sure'])
+        self.assert_valid_command(['mds', 'set', 'max_mds', '2'])
+        self.assert_valid_command(['mds', 'set', 'max_file_size', '2'])
+        self.assert_valid_command(['mds', 'set', 'allow_new_snaps', 'no'])
         assert_equal({}, validate_command(sigdict, ['mds',
                                                     'set',
                                                     'invalid']))
-        assert_equal({}, validate_command(sigdict, ['mds',
-                                                    'set',
-                                                    'allow_new_snaps',
-                                                                                                       'sure',
-                                                                                                       'toomany']))
-
-    def test_mds_unset(self):
-        self.assert_valid_command(['mds', 'unset', 'allow_new_snaps'])
-        self.assert_valid_command(['mds', 'unset', 'allow_new_snaps', 'sure'])
-        assert_equal({}, validate_command(sigdict, ['mds',
-                                                    'unset',
-                                                    'invalid']))
-        assert_equal({}, validate_command(sigdict, ['mds',
-                                                    'unset',
-                                                    'allow_new_snaps',
-                                                                                                       'sure',
-                                                                                                       'toomany']))
 
     def test_add_data_pool(self):
         self.assert_valid_command(['mds', 'add_data_pool', '1'])