]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-journal-tool: make "--rank" argument mandatory
authorVenky Shankar <vshankar@redhat.com>
Mon, 23 Jul 2018 06:35:05 +0000 (02:35 -0400)
committerVenky Shankar <vshankar@redhat.com>
Fri, 21 Sep 2018 10:09:39 +0000 (06:09 -0400)
... and do not silenty act on the default filesystem.
Force users to specify the filesystem name and rank.

Signed-off-by: Venky Shankar <vshankar@redhat.com>
src/tools/cephfs/JournalTool.cc
src/tools/cephfs/JournalTool.h
src/tools/cephfs/RoleSelector.cc
src/tools/cephfs/RoleSelector.h

index 8be2cd85034ff4b850d7498e9d18615f9eec7abe..37f3b5e165a5cdbf3779a8dfbf4c721c97c6c242 100644 (file)
@@ -62,9 +62,7 @@ void JournalTool::usage()
     << "    <output>: [summary|list|binary|json] [--path <path>]\n"
     << "\n"
     << "General options:\n"
-    << "  --rank=filesystem:mds-rank  Journal rank (required if multiple\n"
-    << "                              file systems, default is rank 0 on\n"
-    << "                              the only filesystem otherwise.)\n"
+    << "  --rank=filesystem:mds-rank|all Journal rank (mandatory)\n"
     << "  --journal=<mdlog|purge_queue>  Journal type (purge_queue means\n"
     << "                                 this journal is used to queue for purge operation,\n"
     << "                                 default is mdlog, and only mdlog support event mode)\n" 
@@ -96,9 +94,8 @@ int JournalTool::main(std::vector<const char*> &argv)
 
   std::string rank_str;
   if (!ceph_argparse_witharg(argv, arg, &rank_str, "--rank", (char*)NULL)) {
-    // Default: act on rank 0.  Will give the user an error if they
-    // try invoking this way when they have more than one filesystem.
-    rank_str = "0";
+    derr << "missing mandatory \"--rank\" argument" << dendl;
+    return -EINVAL;
   }
 
   if (!ceph_argparse_witharg(argv, arg, &type, "--journal", (char*)NULL)) {
@@ -112,7 +109,7 @@ int JournalTool::main(std::vector<const char*> &argv)
     return r;
   }
 
-  r = role_selector.parse(*fsmap, rank_str);
+  r = role_selector.parse(*fsmap, rank_str, false);
   if (r != 0) {
     derr << "Couldn't determine MDS rank." << dendl;
     return r;
@@ -161,7 +158,18 @@ int JournalTool::main(std::vector<const char*> &argv)
   // =========
   // journal and header are general journal mode
   // event mode is only specific for mdlog
-  for (auto role : role_selector.get_roles()) {
+  auto roles = role_selector.get_roles();
+  if (roles.size() > 1) {
+    const std::string &command = argv[0];
+    bool allowed = can_execute_for_all_ranks(mode, command);
+    if (!allowed) {
+      derr << "operation not allowed for all ranks" << dendl;
+      return -EINVAL;
+    }
+
+    all_ranks = true;
+  }
+  for (auto role : roles) {
     rank = role.rank;
     std::vector<const char *> rank_argv(argv);
     dout(4) << "Executing for rank " << rank << dendl;
@@ -200,6 +208,15 @@ std::string JournalTool::gen_dump_file_path(const std::string &prefix) {
   return prefix + "." + std::to_string(rank);
 }
 
+bool JournalTool::can_execute_for_all_ranks(const std::string &mode,
+                                            const std::string &command) {
+  if (mode == "journal" && command == "import") {
+    return false;
+  }
+
+  return true;
+}
+
 /**
  * Handle arguments for 'journal' mode
  *
index 081e140e8f21e1c7d421d51d870d258450413a29..8d610a8665f1e89e6154465a14b0cf9beacbb8c2 100644 (file)
@@ -87,6 +87,11 @@ class JournalTool : public MDSUtility
 
     // generate output file path for dump/export
     std::string gen_dump_file_path(const std::string &prefix);
+
+    // check if an operation (mode, command) is safe to be
+    // executed on all ranks.
+    bool can_execute_for_all_ranks(const std::string &mode,
+                                   const std::string &command);
   public:
     static void usage();
     JournalTool() :
index 3c7932a5eb9e6fa50f1b97d39411ed2cb3be182d..e2d53b86ea790b21f06a8b85dde2ba5412aade66 100644 (file)
@@ -29,13 +29,14 @@ int MDSRoleSelector::parse_rank(
   }
 }
 
-int MDSRoleSelector::parse(const FSMap &fsmap, std::string const &str)
+int MDSRoleSelector::parse(const FSMap &fsmap, std::string const &str,
+                           bool allow_unqualified_rank)
 {
   auto colon_pos = str.find(":");
   if (colon_pos == std::string::npos) {
     // An unqualified rank.  Only valid if there is only one
     // namespace.
-    if (fsmap.filesystem_count() == 1) {
+    if (fsmap.filesystem_count() == 1 && allow_unqualified_rank) {
       fscid = fsmap.get_filesystem()->fscid;
       return parse_rank(fsmap, str);
     } else {
index 933c51d0f78fd1dacfbd45ba8e178f7168f16c8b..9090b7200fb6d9d1396b87f6068f3d35cd33611d 100644 (file)
@@ -15,7 +15,8 @@ class MDSRoleSelector
 {
   public:
     const std::vector<mds_role_t> &get_roles() const {return roles;}
-    int parse(const FSMap &fsmap, std::string const &str);
+    int parse(const FSMap &fsmap, std::string const &str,
+            bool allow_unqualified_rank=true);
     MDSRoleSelector()
       : fscid(FS_CLUSTER_ID_NONE)
     {}