From: John Spray Date: Tue, 21 Feb 2017 17:27:08 +0000 (+0000) Subject: mon: move `fs reset` into command handler X-Git-Tag: v12.0.1~238^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=758b6c3f04b1e6abf6e46f42e08fa263bf38e637;p=ceph.git mon: move `fs reset` into command handler Signed-off-by: John Spray --- diff --git a/src/mds/FSMap.cc b/src/mds/FSMap.cc index b9e244ab8cdbc..33d70a0e91e9c 100644 --- a/src/mds/FSMap.cc +++ b/src/mds/FSMap.cc @@ -267,6 +267,36 @@ void FSMap::create_filesystem(const std::string &name, } } +void FSMap::reset_filesystem(fs_cluster_id_t fscid) +{ + auto fs = get_filesystem(fscid); + auto new_fs = std::make_shared(); + + // Populate rank 0 as existing (so don't go into CREATING) + // but failed (so that next available MDS is assigned the rank) + new_fs->mds_map.in.insert(mds_rank_t(0)); + new_fs->mds_map.failed.insert(mds_rank_t(0)); + + // Carry forward what makes sense + new_fs->fscid = fs->fscid; + new_fs->mds_map.inline_data_enabled = fs->mds_map.inline_data_enabled; + new_fs->mds_map.max_mds = 1; + new_fs->mds_map.data_pools = fs->mds_map.data_pools; + new_fs->mds_map.metadata_pool = fs->mds_map.metadata_pool; + new_fs->mds_map.cas_pool = fs->mds_map.cas_pool; + new_fs->mds_map.fs_name = fs->mds_map.fs_name; + new_fs->mds_map.max_file_size = g_conf->mds_max_file_size; + new_fs->mds_map.compat = compat; + new_fs->mds_map.created = ceph_clock_now(); + new_fs->mds_map.modified = ceph_clock_now(); + new_fs->mds_map.session_timeout = g_conf->mds_session_timeout; + new_fs->mds_map.session_autoclose = g_conf->mds_session_autoclose; + new_fs->mds_map.enabled = true; + + // Persist the new FSMap + filesystems[new_fs->fscid] = new_fs; +} + void FSMap::get_health(list >& summary, list > *detail) const { diff --git a/src/mds/FSMap.h b/src/mds/FSMap.h index fa2e844953ebf..177b999d51c29 100644 --- a/src/mds/FSMap.h +++ b/src/mds/FSMap.h @@ -323,6 +323,13 @@ public: filesystems.erase(fscid); } + /** + * Reset all the state information (not configuration information) + * in a particular filesystem. Caller must have verified that + * the filesystem already exists. + */ + void reset_filesystem(fs_cluster_id_t fscid); + /** * Mutator helper for Filesystem objects: expose a non-const * Filesystem pointer to `fn` and update epochs appropriately. diff --git a/src/mon/FSCommands.cc b/src/mon/FSCommands.cc index b48ee11a25efa..27d2d0c6dcf4e 100644 --- a/src/mon/FSCommands.cc +++ b/src/mon/FSCommands.cc @@ -570,6 +570,51 @@ class RemoveFilesystemHandler : public FileSystemCommandHandler } }; +class ResetFilesystemHandler : public FileSystemCommandHandler +{ + public: + ResetFilesystemHandler() + : FileSystemCommandHandler("fs reset") + {} + + int handle( + Monitor *mon, + FSMap &fsmap, + MonOpRequestRef op, + map &cmdmap, + std::stringstream &ss) override + { + string fs_name; + cmd_getval(g_ceph_context, cmdmap, "fs_name", fs_name); + auto fs = fsmap.get_filesystem(fs_name); + if (fs == nullptr) { + 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 (fs->mds_map.get_num_up_mds() > 0) { + 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; + } + + // Check for confirmation flag + string sure; + cmd_getval(g_ceph_context, cmdmap, "sure", sure); + if (sure != "--yes-i-really-mean-it") { + ss << "this is a potentially destructive operation, only for use by experts in disaster recovery. " + "Add --yes-i-really-mean-it if you are sure you wish to continue."; + return -EPERM; + } + + fsmap.reset_filesystem(fs->fscid); + + return 0; + } +}; + class RemoveDataPoolHandler : public FileSystemCommandHandler { public: @@ -728,6 +773,7 @@ std::list > FileSystemCommandHandler:: "mds rm_data_pool")); handlers.push_back(std::make_shared()); handlers.push_back(std::make_shared()); + handlers.push_back(std::make_shared()); handlers.push_back(std::make_shared()); handlers.push_back(std::make_shared >( diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index c4d5ca978f7e7..cfc4510dc08cb 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -1239,24 +1239,6 @@ bool MDSMonitor::prepare_command(MonOpRequestRef op) goto out; } - /* Execute filesystem add/remove, or pass through to filesystem_command */ - r = management_command(op, prefix, cmdmap, ss); - if (r >= 0) - goto out; - - if (r == -EAGAIN) { - // message has been enqueued for retry; return. - dout(4) << __func__ << " enqueue for retry by management_command" << dendl; - return false; - } else if (r != -ENOSYS) { - // MDSMonitor::management_command() returns -ENOSYS if it knows nothing - // about the command passed to it, in which case we will check whether - // MDSMonitor::filesystem_command() knows about it. If on the other hand - // the error code is different from -ENOSYS, we will treat it as is and - // behave accordingly. - goto out; - } - r = filesystem_command(op, prefix, cmdmap, ss); if (r >= 0) { goto out; @@ -1303,79 +1285,6 @@ out: } } -/** - * Handle a command for creating or removing a filesystem. - * - * @retval 0 Command was successfully handled and has side effects - * @retval -EAGAIN Message has been queued for retry - * @retval -ENOSYS Unknown command - * @retval < 0 An error has occurred; **ss** may have been set. - */ -int MDSMonitor::management_command( - MonOpRequestRef op, - std::string const &prefix, - map &cmdmap, - std::stringstream &ss) -{ - if (prefix == "fs reset") { - string fs_name; - cmd_getval(g_ceph_context, cmdmap, "fs_name", fs_name); - auto fs = pending_fsmap.get_filesystem(fs_name); - if (fs == nullptr) { - 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 (!fs->mds_map.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; - } - - // Check for confirmation flag - string sure; - cmd_getval(g_ceph_context, cmdmap, "sure", sure); - if (sure != "--yes-i-really-mean-it") { - ss << "this is a potentially destructive operation, only for use by experts in disaster recovery. " - "Add --yes-i-really-mean-it if you are sure you wish to continue."; - return -EPERM; - } - - FSMap newmap; - - auto new_fs = std::make_shared(); - - // Populate rank 0 as existing (so don't go into CREATING) - // but failed (so that next available MDS is assigned the rank) - new_fs->mds_map.in.insert(mds_rank_t(0)); - new_fs->mds_map.failed.insert(mds_rank_t(0)); - - // Carry forward what makes sense - new_fs->fscid = fs->fscid; - new_fs->mds_map.inline_data_enabled = fs->mds_map.inline_data_enabled; - new_fs->mds_map.max_mds = 1; - new_fs->mds_map.data_pools = fs->mds_map.data_pools; - new_fs->mds_map.metadata_pool = fs->mds_map.metadata_pool; - new_fs->mds_map.cas_pool = fs->mds_map.cas_pool; - new_fs->mds_map.fs_name = fs->mds_map.fs_name; - new_fs->mds_map.max_file_size = g_conf->mds_max_file_size; - new_fs->mds_map.compat = fsmap.compat; - new_fs->mds_map.created = ceph_clock_now(); - new_fs->mds_map.modified = ceph_clock_now(); - new_fs->mds_map.session_timeout = g_conf->mds_session_timeout; - new_fs->mds_map.session_autoclose = g_conf->mds_session_autoclose; - new_fs->mds_map.enabled = true; - - // Persist the new FSMap - pending_fsmap.filesystems[new_fs->fscid] = new_fs; - return 0; - } else { - return -ENOSYS; - } -} - /** * Given one of the following forms: diff --git a/src/mon/MDSMonitor.h b/src/mon/MDSMonitor.h index 23a3431a4d66b..eea0737fe474b 100644 --- a/src/mon/MDSMonitor.h +++ b/src/mon/MDSMonitor.h @@ -101,11 +101,6 @@ class MDSMonitor : public PaxosService { mds_role_t *role, std::ostream &ss); - int management_command( - MonOpRequestRef op, - std::string const &prefix, - map &cmdmap, - std::stringstream &ss); void modify_legacy_filesystem( std::function )> fn); int legacy_filesystem_command(