]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: split "fs rm" into command handler
authorJohn Spray <john.spray@redhat.com>
Tue, 21 Feb 2017 15:50:32 +0000 (15:50 +0000)
committerJohn Spray <john.spray@redhat.com>
Wed, 22 Feb 2017 09:51:48 +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
src/mon/MDSMonitor.h

index 7a2252359b93ab7c4aefc30852a7e564efd0ca85..fa2e844953ebfe3ae00184cebcb94b0aa0fac44a 100644 (file)
@@ -177,6 +177,11 @@ public:
     legacy_client_fscid = fscid;
   }
 
+  fs_cluster_id_t get_legacy_client_fscid() const
+  {
+    return legacy_client_fscid;
+  }
+
   /**
    * Get state of all daemons (for all filesystems, including all standbys)
    */
@@ -309,6 +314,15 @@ public:
                          int64_t metadata_pool, int64_t data_pool,
                          uint64_t features);
 
+  /**
+   * Remove the filesystem (it must exist).  Caller should already
+   * have failed out any MDSs that were assigned to the filesystem.
+   */
+  void erase_filesystem(fs_cluster_id_t fscid)
+  {
+    filesystems.erase(fscid);
+  }
+
   /**
    * Mutator helper for Filesystem objects: expose a non-const
    * Filesystem pointer to `fn` and update epochs appropriately.
index ac2fbcbf64fb27a9e5d8b032af432bcc7a889436..693bf0d5e36e106aeb42bb12aec228d83087c0a8 100644 (file)
@@ -17,6 +17,7 @@
 #include "PGMonitor.h"
 
 #include "FSCommands.h"
+#include "MDSMonitor.h"
 
 
 
@@ -505,6 +506,66 @@ class SetDefaultHandler : public FileSystemCommandHandler
   }
 };
 
+class RemoveFilesystemHandler : public FileSystemCommandHandler
+{
+  public:
+  RemoveFilesystemHandler()
+    : FileSystemCommandHandler("fs rm")
+  {}
+
+  int handle(
+      Monitor *mon,
+      FSMap &fsmap,
+      MonOpRequestRef op,
+      map<string, cmd_vartype> &cmdmap,
+      std::stringstream &ss) override
+  {
+    // 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)
+    string fs_name;
+    cmd_getval(g_ceph_context, cmdmap, "fs_name", fs_name);
+    auto fs = fsmap.get_filesystem(fs_name);
+    if (fs == nullptr) {
+        // Consider absence success to make deletes idempotent
+        ss << "filesystem '" << fs_name << "' does not exist";
+        return 0;
+    }
+
+    // Check that no MDS daemons are active
+    if (fs->mds_map.get_num_up_mds() > 0) {
+      ss << "all MDS daemons must be inactive before removing filesystem";
+      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 DESTRUCTIVE operation and will make data in your filesystem permanently" \
+            " inaccessible.  Add --yes-i-really-mean-it if you are sure you wish to continue.";
+      return -EPERM;
+    }
+
+    if (fsmap.get_legacy_client_fscid() == fs->fscid) {
+      fsmap.set_legacy_client_fscid(FS_CLUSTER_ID_NONE);
+    }
+
+    // There may be standby_replay daemons left here
+    for (const auto &i : fs->mds_map.get_mds_info()) {
+      assert(i.second.state == MDSMap::STATE_STANDBY_REPLAY);
+
+      // Standby replays don't write, so it isn't important to
+      // wait for an osdmap propose here: ignore return value.
+      mon->mdsmon()->fail_mds_gid(i.first);
+    }
+
+    fsmap.erase_filesystem(fs->fscid);
+
+    return 0;
+  }
+};
+
 class RemoveDataPoolHandler : public FileSystemCommandHandler
 {
   public:
@@ -662,6 +723,7 @@ std::list<std::shared_ptr<FileSystemCommandHandler> > FileSystemCommandHandler::
   handlers.push_back(std::make_shared<LegacyHandler<RemoveDataPoolHandler> >(
         "mds rm_data_pool"));
   handlers.push_back(std::make_shared<FsNewHandler>());
+  handlers.push_back(std::make_shared<RemoveFilesystemHandler>());
 
   handlers.push_back(std::make_shared<SetDefaultHandler>());
   handlers.push_back(std::make_shared<AliasHandler<SetDefaultHandler> >(
index 07ed67d5cdfa0a114ee9355c290218d9ebb7a08f..c4d5ca978f7e7acd3434ccdf94d68810817e840d 100644 (file)
@@ -1317,48 +1317,7 @@ int MDSMonitor::management_command(
     map<string, cmd_vartype> &cmdmap,
     std::stringstream &ss)
 {
-  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)
-    string fs_name;
-    cmd_getval(g_ceph_context, cmdmap, "fs_name", fs_name);
-    auto fs = pending_fsmap.get_filesystem(fs_name);
-    if (fs == nullptr) {
-        // Consider absence success to make deletes idempotent
-        ss << "filesystem '" << fs_name << "' does not exist";
-        return 0;
-    }
-
-    // Check that no MDS daemons are active
-    if (!fs->mds_map.up.empty()) {
-      ss << "all MDS daemons must be inactive before removing filesystem";
-      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 DESTRUCTIVE operation and will make data in your filesystem permanently" \
-            " inaccessible.  Add --yes-i-really-mean-it if you are sure you wish to continue.";
-      return -EPERM;
-    }
-
-    if (pending_fsmap.legacy_client_fscid == fs->fscid) {
-      pending_fsmap.legacy_client_fscid = FS_CLUSTER_ID_NONE;
-    }
-
-    // There may be standby_replay daemons left here
-    for (const auto &i : fs->mds_map.mds_info) {
-      assert(i.second.state == MDSMap::STATE_STANDBY_REPLAY);
-      fail_mds_gid(i.first);
-    }
-
-    pending_fsmap.filesystems.erase(fs->fscid);
-
-    return 0;
-  } else if (prefix == "fs reset") {
+  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);
index bf88c69f086355d0f63754d0fee2075db47a2be1..23a3431a4d66ba4985546d72e2200738446e4f68 100644 (file)
@@ -65,6 +65,10 @@ class MDSMonitor : public PaxosService {
   void dump_info(Formatter *f);
   int print_nodes(Formatter *f);
 
+  /**
+   * Return true if a blacklist was done (i.e. OSD propose needed)
+   */
+  bool fail_mds_gid(mds_gid_t gid);
  protected:
   // mds maps
   FSMap fsmap;           // current
@@ -88,10 +92,6 @@ class MDSMonitor : public PaxosService {
                  list<pair<health_status_t,string> > *detail,
                  CephContext *cct) const override;
   int fail_mds(std::ostream &ss, const std::string &arg);
-  /**
-   * Return true if a blacklist was done (i.e. OSD propose needed)
-   */
-  bool fail_mds_gid(mds_gid_t gid);
 
   bool preprocess_command(MonOpRequestRef op);
   bool prepare_command(MonOpRequestRef op);