]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: move `fs reset` into command handler 13581/head
authorJohn Spray <john.spray@redhat.com>
Tue, 21 Feb 2017 17:27:08 +0000 (17:27 +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.cc
src/mds/FSMap.h
src/mon/FSCommands.cc
src/mon/MDSMonitor.cc
src/mon/MDSMonitor.h

index b9e244ab8cdbc88a4c9c2ce8d899d7cafa5d5458..33d70a0e91e9c4dc9c64aef592136eb9d6936272 100644 (file)
@@ -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<Filesystem>();
+
+  // 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<pair<health_status_t,string> >& summary,
                        list<pair<health_status_t,string> > *detail) const
 {
index fa2e844953ebfe3ae00184cebcb94b0aa0fac44a..177b999d51c2949888ddd8df334417302c689e58 100644 (file)
@@ -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.
index b48ee11a25efa83ad8a6dc91c23f0d702d463d19..27d2d0c6dcf4e48b6f268bb563d69bb3f7e14cd5 100644 (file)
@@ -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<string, cmd_vartype> &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<std::shared_ptr<FileSystemCommandHandler> > FileSystemCommandHandler::
         "mds rm_data_pool"));
   handlers.push_back(std::make_shared<FsNewHandler>());
   handlers.push_back(std::make_shared<RemoveFilesystemHandler>());
+  handlers.push_back(std::make_shared<ResetFilesystemHandler>());
 
   handlers.push_back(std::make_shared<SetDefaultHandler>());
   handlers.push_back(std::make_shared<AliasHandler<SetDefaultHandler> >(
index c4d5ca978f7e7acd3434ccdf94d68810817e840d..cfc4510dc08cb639e8e8351188f60a95a053b332 100644 (file)
@@ -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<string, cmd_vartype> &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<Filesystem>();
-
-    // 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:
index 23a3431a4d66ba4985546d72e2200738446e4f68..eea0737fe474b07e1157867458f58c039e7f39a6 100644 (file)
@@ -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<string, cmd_vartype> &cmdmap,
-      std::stringstream &ss);
   void modify_legacy_filesystem(
       std::function<void(std::shared_ptr<Filesystem> )> fn);
   int legacy_filesystem_command(