]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/ceph-objectstore-tool: add "get-osdmap" command
authorKefu Chai <kchai@redhat.com>
Fri, 3 Jul 2015 15:09:54 +0000 (23:09 +0800)
committerDavid Zafman <dzafman@redhat.com>
Thu, 25 Feb 2016 20:50:24 +0000 (12:50 -0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit f0c130d6b1bc2a8a0cce6d78a6e69995fe00a427)

Conflicts:
src/tools/ceph_objectstore_tool.cc (trivial)

src/tools/ceph_objectstore_tool.cc

index b62c210ce0894d6c37757f26658454c1f7bda4f9..70020cc215f63575830c37a19ed8d4686b256501 100644 (file)
@@ -2721,6 +2721,7 @@ int main(int argc, char **argv)
 {
   string dpath, jpath, pgidstr, op, file, object, objcmd, arg1, arg2, type, format;
   spg_t pgid;
+  unsigned epoch = 0;
   ghobject_t ghobj;
   bool human_readable, no_overwrite;
   bool force;
@@ -2738,9 +2739,12 @@ int main(int argc, char **argv)
     ("pgid", po::value<string>(&pgidstr),
      "PG id, mandatory for info, log, remove, export, rm-past-intervals")
     ("op", po::value<string>(&op),
-     "Arg is one of [info, log, remove, export, import, list, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects, dump-journal, dump-super]")
+     "Arg is one of [info, log, remove, export, import, list, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects, dump-journal, dump-super, "
+        "get-osdmap, set-osdmap]")
+    ("epoch", po::value<unsigned>(&epoch),
+     "epoch# for get-osdmap, the current epoch in use if not specified")
     ("file", po::value<string>(&file),
-     "path of file to export or import")
+     "path of file to export, import, get-osdmap or set-osdmap")
     ("format", po::value<string>(&format)->default_value("json-pretty"),
      "Output format which may be json, json-pretty, xml, xml-pretty")
     ("debug", "Enable diagnostic output to stderr")
@@ -2888,7 +2892,7 @@ int main(int argc, char **argv)
   outistty = isatty(STDOUT_FILENO);
 
   file_fd = fd_none;
-  if (op == "export" && !dry_run) {
+  if ((op == "export" || op == "get-osdmap") && !dry_run) {
     if (!vm.count("file") || file == "-") {
       if (outistty) {
         cerr << "stdout is a tty and no --file filename specified" << std::endl;
@@ -2911,7 +2915,8 @@ int main(int argc, char **argv)
   }
 
   if (vm.count("file") && file_fd == fd_none && !dry_run) {
-    cerr << "--file option only applies to import, export or set-osdmap" << std::endl;
+    cerr << "--file option only applies to import, export, "
+        << "get-osdmap or set-osdmap" << std::endl;
     myexit(1);
   }
 
@@ -3264,6 +3269,25 @@ int main(int argc, char **argv)
       }
     }
     goto out;
+  } else if (op == "get-osdmap") {
+    bufferlist bl;
+    OSDMap osdmap;
+    if (epoch == 0) {
+      epoch = superblock.current_epoch;
+    }
+    ret = get_osdmap(fs, epoch, osdmap, bl);
+    if (ret) {
+      cerr << "Failed to get osdmap#" << epoch << ": "
+          << cpp_strerror(ret) << std::endl;
+      goto out;
+    }
+    ret = bl.write_fd(file_fd);
+    if (ret) {
+      cerr << "Failed to write to " << file << ": " << cpp_strerror(ret) << std::endl;
+    } else {
+      cout << "osdmap#" << epoch << " exported." << std::endl;
+    }
+    goto out;
   } else if (op == "set-osdmap") {
     bufferlist bl;
     ret = get_fd_data(file_fd, bl);
@@ -3364,7 +3388,7 @@ int main(int argc, char **argv)
   // before complaining about a bad pgid
   if (!vm.count("objcmd") && op != "export" && op != "info" && op != "log" && op != "rm-past-intervals") {
     cerr << "Must provide --op (info, log, remove, export, import, list, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects, dump-journal, dump-super, "
-      "set-osdmap)"
+      "set-osdmap, get-osdmap)"
         << std::endl;
     usage(desc);
     ret = 1;