From: John Spray Date: Mon, 5 Jan 2015 19:34:57 +0000 (+0000) Subject: mon: implement `fs reset` X-Git-Tag: v0.92~27^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1713ffd898ef700fe55b6fd46c7814cab1fc9d42;p=ceph.git mon: implement `fs reset` 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 --- diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index 399dd2e38700..9ee5958d8b52 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -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; } diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index cdac6d1096af..6292e302d6ac 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -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")