]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-objectstore-tool: On any exit release CephContext so logging can flush
authorDavid Zafman <dzafman@redhat.com>
Mon, 9 Feb 2015 20:46:20 +0000 (12:46 -0800)
committerDavid Zafman <dzafman@redhat.com>
Wed, 13 May 2015 20:09:11 +0000 (13:09 -0700)
Add myexit() which will put() the g_ceph_context if present before exit
Must umount() once the objectstore has been mounted

Fixes: #10809
Signed-off-by: David Zafman <dzafman@redhat.com>
src/test/ceph_objectstore_tool.py
src/tools/ceph_objectstore_tool.cc

index 52ae51ce0257a94d4c63493dc2d45ad729147e32..c84fa4ab2d8c7f66a832594110b284f431324791 100755 (executable)
@@ -474,6 +474,13 @@ def main(argv):
     cmd = "./ceph-objectstore-tool --type filestore --data-path {dir}/{osd} --op list --pgid {pg}".format(dir=OSDDIR, osd=ONEOSD, pg=ONEPG)
     ERRORS += test_failure(cmd, "Must provide --journal-path")
 
+    cmd = (CFSD_PREFIX + "--op remove").format(osd=ONEOSD)
+    ERRORS += test_failure(cmd, "Must provide pgid")
+
+    # Don't secify a --op
+    cmd = CFSD_PREFIX.format(osd=ONEOSD)
+    ERRORS += test_failure(cmd, "Must provide --op or object command...")
+
     # Test --op list and generate json for all objects
     TMPFILE = r"/tmp/tmp.{pid}".format(pid=pid)
     ALLPGS = OBJREPPGS + OBJECPGS
index c9ba9ed1c3d4ba6e292b533c60520d8db8292735..c5640a157e5122b4063fd5ffc35becccb0cbc3f8 100644 (file)
@@ -614,10 +614,17 @@ static int get_fd_data(int fd, bufferlist &bl)
   return 0;
 }
 
+void myexit(int ret)
+{
+  if (g_ceph_context)
+    g_ceph_context->put();
+  exit(ret);
+}
+
 static void invalid_filestore_path(string &path)
 {
   cerr << "Invalid filestore path specified: " << path << "\n";
-  exit(1);
+  myexit(1);
 }
 
 int get_log(ObjectStore *fs, __u8 struct_ver,
@@ -1632,7 +1639,7 @@ int do_import_rados(string pool)
 
   if (!pgid.is_no_shard()) {
     cerr << "Importing Erasure Coded shard is not supported" << std::endl;
-    exit(1);
+    myexit(1);
   }
 
   if (debug) {
@@ -2277,7 +2284,6 @@ void usage(po::options_description &desc)
     cerr << std::endl;
     cerr << "The optional [file] argument will read stdin or write stdout" << std::endl;
     cerr << "if not specified or if '-' specified." << std::endl;
-    exit(1);
 }
 
 bool ends_with(const string& check, const string& ending)
@@ -2346,6 +2352,7 @@ int main(int argc, char **argv)
 
   if (vm.count("help")) {
     usage(desc);
+    myexit(1);
   }
 
   if (!vm.count("debug")) {
@@ -2367,7 +2374,7 @@ int main(int argc, char **argv)
   if (object == "import-rados") {
     if (vm.count("objcmd") == 0) {
       cerr << "ceph-objectstore-tool import-rados <pool> [file]" << std::endl;
-      exit(1);
+      myexit(1);
     }
 
     string pool = objcmd;
@@ -2382,7 +2389,7 @@ int main(int argc, char **argv)
     if (arg1 == "-") {
       if (isatty(STDIN_FILENO)) {
         cerr << "stdin is a tty and no file specified" << std::endl;
-        exit(1);
+        myexit(1);
       }
       file_fd = STDIN_FILENO;
     } else {
@@ -2399,12 +2406,13 @@ int main(int argc, char **argv)
     int ret = do_import_rados(pool);
     if (ret == 0)
       cout << "Import successful" << std::endl;
-    return ret != 0;
+    myexit(ret != 0);
   }
 
   if (!vm.count("data-path")) {
     cerr << "Must provide --data-path" << std::endl;
     usage(desc);
+    myexit(1);
   }
   if (!vm.count("type")) {
     type = "filestore";
@@ -2412,18 +2420,22 @@ int main(int argc, char **argv)
   if (type == "filestore" && !vm.count("journal-path")) {
     cerr << "Must provide --journal-path" << std::endl;
     usage(desc);
+    myexit(1);
   }
   if (op != "list" && vm.count("object") && !vm.count("objcmd")) {
     cerr << "Invalid syntax, missing command" << std::endl;
     usage(desc);
+    myexit(1);
   }
   if (!vm.count("op") && !(vm.count("object") && vm.count("objcmd"))) {
     cerr << "Must provide --op or object command..." << std::endl;
     usage(desc);
+    myexit(1);
   }
   if (op != "list" && vm.count("op") && vm.count("object")) {
     cerr << "Can't specify both --op and object command syntax" << std::endl;
     usage(desc);
+    myexit(1);
   }
   outistty = isatty(STDOUT_FILENO);
 
@@ -2432,7 +2444,7 @@ int main(int argc, char **argv)
     if (!vm.count("file") || file == "-") {
       if (outistty) {
         cerr << "stdout is a tty and no --file filename specified" << std::endl;
-        exit(1);
+        myexit(1);
       }
       file_fd = STDOUT_FILENO;
     } else {
@@ -2442,7 +2454,7 @@ int main(int argc, char **argv)
     if (!vm.count("file") || file == "-") {
       if (isatty(STDIN_FILENO)) {
         cerr << "stdin is a tty and no --file filename specified" << std::endl;
-        exit(1);
+        myexit(1);
       }
       file_fd = STDIN_FILENO;
     } else {
@@ -2482,7 +2494,7 @@ int main(int argc, char **argv)
   struct stat st;
   if (::stat(dpath.c_str(), &st) == -1) {
      perror("data-path");
-     exit(1);
+     myexit(1);
   }
   //Verify data data-path really is a filestore
   if (type == "filestore") {
@@ -2509,12 +2521,12 @@ int main(int argc, char **argv)
 
   if (op == "import" && pgidstr.length()) {
     cerr << "--pgid option invalid with import" << std::endl;
-    return 1;
+    myexit(1);
   }
 
   if (pgidstr.length() && !pgid.parse(pgidstr.c_str())) {
     cerr << "Invalid pgid '" << pgidstr << "' specified" << std::endl;
-    return 1;
+    myexit(1);
   }
 
   ObjectStore *fs = ObjectStore::create(g_ceph_context, type, dpath, jpath, flags);
@@ -2525,7 +2537,7 @@ int main(int argc, char **argv)
            << "enable_experimental_unrecoverable_data_corrupting_features"
            << std::endl;
     }
-    exit(1);
+    myexit(1);
   }
 
   int r = fs->mount();
@@ -2535,7 +2547,7 @@ int main(int argc, char **argv)
     } else {
       cerr << "Mount failed with '" << cpp_strerror(-r) << "'" << std::endl;
     }
-    return 1;
+    myexit(1);
   }
 
   bool fs_sharded_objects = fs->get_allow_sharded_objects();
@@ -2666,6 +2678,8 @@ int main(int argc, char **argv)
       (pgidstr.length() == 0)) {
     cerr << "Must provide pgid" << std::endl;
     usage(desc);
+    ret = 1;
+    goto out;
   }
 
   if (op == "set-allow-sharded-objects") {
@@ -2942,15 +2956,20 @@ int main(int argc, char **argv)
           ret = 1;
         goto out;
       } else if (objcmd == "get-attr") {
-       if (vm.count("arg1") == 0)
+       if (vm.count("arg1") == 0) {
          usage(desc);
+          ret = 1;
+          goto out;
+        }
        r = do_get_attr(fs, coll, ghobj, arg1);
        if (r)
          ret = 1;
         goto out;
       } else if (objcmd == "set-attr") {
-       if (vm.count("arg1") == 0)
+       if (vm.count("arg1") == 0) {
          usage(desc);
+          ret = 1;
+        }
 
        int fd;
        if (vm.count("arg2") == 0 || arg2 == "-") {
@@ -2976,23 +2995,31 @@ int main(int argc, char **argv)
          ret = 1;
         goto out;
       } else if (objcmd == "rm-attr") {
-       if (vm.count("arg1") == 0)
+       if (vm.count("arg1") == 0) {
          usage(desc);
+          ret = 1;
+          goto out;
+        }
        r = do_rm_attr(fs, coll, ghobj, arg1);
        if (r)
          ret = 1;
         goto out;
       } else if (objcmd == "get-omap") {
-       if (vm.count("arg1") == 0)
+       if (vm.count("arg1") == 0) {
          usage(desc);
+          ret = 1;
+          goto out;
+        }
        r = do_get_omap(fs, coll, ghobj, arg1);
        if (r)
          ret = 1;
         goto out;
       } else if (objcmd == "set-omap") {
-       if (vm.count("arg1") == 0)
+       if (vm.count("arg1") == 0) {
          usage(desc);
-
+          ret = 1;
+          goto out;
+        }
        int fd;
        if (vm.count("arg2") == 0 || arg2 == "-") {
           // Since read_fd() doesn't handle ^D from a tty stdin, don't allow it.
@@ -3017,23 +3044,32 @@ int main(int argc, char **argv)
          ret = 1;
         goto out;
       } else if (objcmd == "rm-omap") {
-       if (vm.count("arg1") == 0)
+       if (vm.count("arg1") == 0) {
          usage(desc);
+          ret = 1;
+          goto out;
+        }
        r = do_rm_omap(fs, coll, ghobj, arg1);
        if (r)
          ret = 1;
         goto out;
       } else if (objcmd == "get-omaphdr") {
-       if (vm.count("arg1"))
+       if (vm.count("arg1")) {
          usage(desc);
+          ret = 1;
+          goto out;
+        }
        r = do_get_omaphdr(fs, coll, ghobj);
        if (r)
          ret = 1;
         goto out;
       } else if (objcmd == "set-omaphdr") {
         // Extra arg
-       if (vm.count("arg2"))
+       if (vm.count("arg2")) {
          usage(desc);
+          ret = 1;
+          goto out;
+        }
        int fd;
        if (vm.count("arg1") == 0 || arg1 == "-") {
           // Since read_fd() doesn't handle ^D from a tty stdin, don't allow it.
@@ -3060,6 +3096,8 @@ int main(int argc, char **argv)
       }
       cerr << "Unknown object command '" << objcmd << "'" << std::endl;
       usage(desc);
+      ret = 1;
+      goto out;
     }
 
     bufferlist bl;
@@ -3137,6 +3175,7 @@ int main(int argc, char **argv)
       cerr << "Must provide --op (info, log, remove, export, import, list, list-lost, fix-lost, list-pgs, rm-past-intervals)"
        << std::endl;
       usage(desc);
+      ret = 1;
     }
   } else {
     cerr << "PG '" << pgid << "' not found" << std::endl;
@@ -3146,11 +3185,11 @@ int main(int argc, char **argv)
 out:
   if (fs->umount() < 0) {
     cerr << "umount failed" << std::endl;
-    return 1;
+    if (ret == 0) ret = 1;
   }
 
   // Check for -errno accidentally getting here
   if (ret < 0)
     ret = 1;
-  return ret;
+  myexit(ret);
 }