]> git-server-git.apps.pok.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>
Mon, 3 Dec 2018 07:39:49 +0000 (02:39 -0500)
... 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>
(cherry picked from commit 5e4702e303bd70b4ff1de973375bef952c0d8b6a)

 Conflicts:
src/tools/cephfs/JournalTool.cc
src/tools/cephfs/JournalTool.h

src/tools/cephfs/JournalTool.cc
src/tools/cephfs/JournalTool.h
src/tools/cephfs/RoleSelector.cc
src/tools/cephfs/RoleSelector.h

index a5f927431c477ca84fef24ada0e14c486f76bb94..a9756f73e2a9d6696b2ea567663348137909b93a 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"
     << "\n"
     << "Special options\n"
     << "  --alternate-pool <name>     Alternative metadata pool to target\n"
@@ -92,13 +90,12 @@ int JournalTool::main(std::vector<const char*> &argv)
   std::vector<const char*>::iterator arg = argv.begin();
 
   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";
+  if (!ceph_argparse_witharg(argv, arg, &rank_str, "--rank", (char*)NULL)) {
+    derr << "missing mandatory \"--rank\" argument" << dendl;
+    return -EINVAL;
   }
 
-  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;
@@ -145,7 +142,18 @@ int JournalTool::main(std::vector<const char*> &argv)
 
   // Execution
   // =========
-  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;
@@ -178,6 +186,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 2f904e2397ca691f751d6b73b710076ddcf054c1..4dccd92f12b5448b9c47dcd66c7df4028b056828 100644 (file)
@@ -84,6 +84,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:
     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)
     {}