From: Sage Weil Date: Mon, 3 Feb 2014 21:19:14 +0000 (-0800) Subject: mon: fix 'mds set allow_new_snaps' X-Git-Tag: v0.77~9^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=408b0c8e759b153b038ddeb6eca8ddfd92b75dd8;p=ceph.git mon: fix 'mds set allow_new_snaps' We had already added this as a flag (set/unset) when I generalized the 'mds set_max_mds' to be 'ceph mds set '. 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 Reviewed-by: Greg Farnum --- diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 1808d2c2a34d..0e61f9feb74a 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -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 diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index e19c8a9d1458..e24b1d01d1b9 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -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); diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 6dd23f3a7863..de84997db559 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -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 to ", "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 ", \ - "mds", "rw", "cli,rest") -COMMAND("mds unset " \ - "name=key,type=CephChoices,strings=allow_new_snaps " \ - "name=sure,type=CephString,req=false", \ - "unset ", "mds", "rw", "cli,rest") COMMAND("mds add_data_pool " \ "name=pool,type=CephString", \ "add data pool ", "mds", "rw", "cli,rest") diff --git a/src/test/pybind/test_ceph_argparse.py b/src/test/pybind/test_ceph_argparse.py index 48dea81447a8..89cf6c9a6a04 100755 --- a/src/test/pybind/test_ceph_argparse.py +++ b/src/test/pybind/test_ceph_argparse.py @@ -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'])