]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: move "fs set-default" into handler class
authorJohn Spray <john.spray@redhat.com>
Tue, 21 Feb 2017 13:33:56 +0000 (13:33 +0000)
committerJohn Spray <john.spray@redhat.com>
Wed, 22 Feb 2017 09:51:47 +0000 (09:51 +0000)
Signed-off-by: John Spray <john.spray@redhat.com>
src/mds/FSMap.h
src/mon/FSCommands.cc
src/mon/MDSMonitor.cc

index e44ffcdd20790ff13cec551d7ffc9475c1671848..7a2252359b93ab7c4aefc30852a7e564efd0ca85 100644 (file)
@@ -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)
    */
index 76e5ad3507c9dfec1c9a72425102db3511ffe389..ac2fbcbf64fb27a9e5d8b032af432bcc7a889436 100644 (file)
@@ -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<string, cmd_vartype> &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<typename T>
+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<string, cmd_vartype> &cmdmap,
+      std::stringstream &ss) override
+  {
+    return T::handle(mon, fsmap, op, cmdmap, ss);
+  }
+};
+
 
 std::list<std::shared_ptr<FileSystemCommandHandler> > FileSystemCommandHandler::load()
 {
@@ -609,6 +663,10 @@ std::list<std::shared_ptr<FileSystemCommandHandler> > FileSystemCommandHandler::
         "mds rm_data_pool"));
   handlers.push_back(std::make_shared<FsNewHandler>());
 
+  handlers.push_back(std::make_shared<SetDefaultHandler>());
+  handlers.push_back(std::make_shared<AliasHandler<SetDefaultHandler> >(
+        "fs set_default"));
+
   return handlers;
 }
 
index 266874f631360324ac0dbbb0ee01efd56a126846..07ed67d5cdfa0a114ee9355c290218d9ebb7a08f 100644 (file)
@@ -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<string, cmd_vartype> &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;
   }