]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: implement `fs reset`
authorJohn Spray <john.spray@redhat.com>
Mon, 5 Jan 2015 19:34:57 +0000 (19:34 +0000)
committerJohn Spray <john.spray@redhat.com>
Mon, 12 Jan 2015 15:00:14 +0000 (15:00 +0000)
This is for use in CephFS disaster recovery.  When
the metadata pool has been forcibly reset to a single-MDS
metadata tree, we would like to reset the MDSMap to match.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mon/MDSMonitor.cc
src/mon/MonCommands.h

index 399dd2e387006989d9a4a23fc3786ea90f279ead..9ee5958d8b520b3566edb9cb10e68dfbfbccf7f2 100644 (file)
@@ -1212,6 +1212,44 @@ int MDSMonitor::management_command(
     pending_mdsmap.created = ceph_clock_now(g_ceph_context);
 
     return 0;
+  } else if (prefix == "fs reset") {
+    string fs_name;
+    cmd_getval(g_ceph_context, cmdmap, "fs_name", fs_name);
+    if (!pending_mdsmap.get_enabled() || fs_name != pending_mdsmap.fs_name) {
+        ss << "filesystem '" << fs_name << "' does not exist";
+        // Unlike fs rm, we consider this case an error
+        return -ENOENT;
+    }
+
+    // Check that no MDS daemons are active
+    if (!pending_mdsmap.up.empty()) {
+      ss << "all MDS daemons must be inactive before resetting filesystem: set the cluster_down flag"
+            " and use `ceph mds fail` to make this so";
+      return -EINVAL;
+    }
+
+    MDSMap newmap;
+
+    // Populate rank 0 as existing (so don't go into CREATING)
+    // but failed (so that next available MDS is assigned the rank)
+    newmap.in.insert(mds_rank_t(0));
+    newmap.failed.insert(mds_rank_t(0));
+
+    // Carry forward what makes sense
+    newmap.data_pools = mdsmap.data_pools;
+    newmap.metadata_pool = mdsmap.metadata_pool;
+    newmap.cas_pool = mdsmap.cas_pool;
+    newmap.fs_name = mdsmap.fs_name;
+    newmap.created = ceph_clock_now(g_ceph_context);
+    newmap.epoch = mdsmap.epoch + 1;
+    newmap.inc = mdsmap.inc;
+    newmap.enabled = mdsmap.enabled;
+    newmap.inline_data_enabled = mdsmap.inline_data_enabled;
+
+    // Persist the new MDSMap
+    pending_mdsmap = newmap;
+    return 0;
+
   } else {
     return -ENOSYS;
   }
index cdac6d1096aff2eaa22ccbf2b48e676de8630914..6292e302d6ac1ff9fac1696103be1bc2a2df7385 100644 (file)
@@ -307,6 +307,11 @@ COMMAND("fs rm " \
        "name=sure,type=CephChoices,strings=--yes-i-really-mean-it,req=false", \
        "disable the named filesystem", \
        "fs", "rw", "cli,rest")
+COMMAND("fs reset " \
+       "name=fs_name,type=CephString " \
+       "name=sure,type=CephChoices,strings=--yes-i-really-mean-it,req=false", \
+       "disaster recovery only: reset to a single-MDS map", \
+       "fs", "rw", "cli,rest")
 COMMAND("fs ls ", \
        "list filesystems", \
        "fs", "r", "cli,rest")