From: John Spray Date: Tue, 21 Feb 2017 13:33:56 +0000 (+0000) Subject: mon: move "fs set-default" into handler class X-Git-Tag: v12.0.1~238^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2d1671cca7bab83b01d5da5e3509dd7a88d650f0;p=ceph.git mon: move "fs set-default" into handler class Signed-off-by: John Spray --- diff --git a/src/mds/FSMap.h b/src/mds/FSMap.h index e44ffcdd207..7a2252359b9 100644 --- a/src/mds/FSMap.h +++ b/src/mds/FSMap.h @@ -171,6 +171,12 @@ public: return enable_multiple; } + void set_legacy_client_fscid(fs_cluster_id_t fscid) + { + assert(fscid == FS_CLUSTER_ID_NONE || filesystems.count(fscid)); + legacy_client_fscid = fscid; + } + /** * Get state of all daemons (for all filesystems, including all standbys) */ diff --git a/src/mon/FSCommands.cc b/src/mon/FSCommands.cc index 76e5ad3507c..ac2fbcbf64f 100644 --- a/src/mon/FSCommands.cc +++ b/src/mon/FSCommands.cc @@ -478,6 +478,32 @@ class AddDataPoolHandler : public FileSystemCommandHandler } }; +class SetDefaultHandler : public FileSystemCommandHandler +{ + public: + SetDefaultHandler() + : FileSystemCommandHandler("fs set-default") + {} + + int handle( + Monitor *mon, + FSMap &fsmap, + MonOpRequestRef op, + map &cmdmap, + std::stringstream &ss) override + { + std::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"; + return -ENOENT; + } + + fsmap.set_legacy_client_fscid(fs->fscid); + return 0; + } +}; class RemoveDataPoolHandler : public FileSystemCommandHandler { @@ -591,6 +617,34 @@ class LegacyHandler : public T } }; +/** + * For commands with an alternative prefix + */ +template +class AliasHandler : public T +{ + std::string alias_prefix; + + public: + AliasHandler(const std::string &new_prefix) + : T() + { + alias_prefix = new_prefix; + } + + std::string const &get_prefix() override {return alias_prefix;} + + int handle( + Monitor *mon, + FSMap &fsmap, + MonOpRequestRef op, + map &cmdmap, + std::stringstream &ss) override + { + return T::handle(mon, fsmap, op, cmdmap, ss); + } +}; + std::list > FileSystemCommandHandler::load() { @@ -609,6 +663,10 @@ 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 >( + "fs set_default")); + return handlers; } diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index 266874f6313..07ed67d5cdf 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -1230,6 +1230,15 @@ bool MDSMonitor::prepare_command(MonOpRequestRef op) } } + if (prefix == "mds newfs") { + // newfs is the legacy command that in single-filesystem times + // used to be equivalent to doing an "fs rm ; fs new". We + // can't do this in a sane way in multi-filesystem world. + ss << "'newfs' no longer available. Please use 'fs new'."; + r = -EINVAL; + goto out; + } + /* Execute filesystem add/remove, or pass through to filesystem_command */ r = management_command(op, prefix, cmdmap, ss); if (r >= 0) @@ -1308,15 +1317,7 @@ int MDSMonitor::management_command( map &cmdmap, std::stringstream &ss) { - op->mark_mdsmon_event(__func__); - - if (prefix == "mds newfs") { - // newfs is the legacy command that in single-filesystem times - // used to be equivalent to doing an "fs rm ; fs new". We - // can't do this in a sane way in multi-filesystem world. - ss << "'newfs' no longer available. Please use 'fs new'."; - return -EINVAL; - } else if (prefix == "fs rm") { + if (prefix == "fs rm") { // Check caller has correctly named the FS to delete // (redundant while there is only one FS, but command // syntax should apply to multi-FS future) @@ -1411,18 +1412,6 @@ int MDSMonitor::management_command( // Persist the new FSMap pending_fsmap.filesystems[new_fs->fscid] = new_fs; return 0; - } else if (prefix == "fs set_default" || - prefix == "fs set-default") { - 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"; - return -ENOENT; - } - - pending_fsmap.legacy_client_fscid = fs->fscid; - return 0; } else { return -ENOSYS; }