]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
objectstore_tool: filter --op list and explore all PGs
authorLoic Dachary <ldachary@redhat.com>
Wed, 26 Nov 2014 22:35:21 +0000 (23:35 +0100)
committerLoic Dachary <ldachary@redhat.com>
Fri, 5 Dec 2014 12:01:36 +0000 (13:01 +0100)
The positional object name is used to filter the output of --op list and
only show the objects with a matching name. If both the object name and
the pgid are omitted, all objects from all PGs are displayed.

The output format is changed from

    {"oid":"GROUP","key":"","snapid":-2,
     "hash":2659194943,"max":0,"pool":0,"namespace":""}

to

    [["0.7_head",{"oid":"GROUP","key":"","snapid":-2,
                  "hash":2659194943,"max":0,"pool":0,
                  "namespace":""}]]

where the first member is the pgid where the object is found.

Signed-off-by: Loic Dachary <ldachary@redhat.com>
src/tools/ceph_objectstore_tool.cc

index a3b45d58cfc7b7a9aecf8dafb5569f0505bc62f3..ed1df237a3e57d4102067321655ed842ed77f945 100644 (file)
@@ -1619,25 +1619,22 @@ int do_import(ObjectStore *store, OSDSuperblock& sb)
   return 0;
 }
 
-int do_list(ObjectStore *store, coll_t coll, Formatter *formatter)
+int do_list(ObjectStore *store, string pgidstr, string object, Formatter *formatter, bool debug)
 {
-  ghobject_t next;
-  while (!next.is_max()) {
-    vector<ghobject_t> objects;
-    int r = store->collection_list_partial(coll, next, 200, 300, 0,
-      &objects, &next);
-    if (r < 0)
-      return r;
-    for (vector<ghobject_t>::iterator i = objects.begin();
-        i != objects.end(); ++i) {
-
-      formatter->open_object_section("list");
-      i->dump(formatter);
-      formatter->close_section();
-      formatter->flush(cout);
-      cout << std::endl;
-    }
+  int r;
+  lookup_ghobject lookup(object);
+  if (pgidstr.length() > 0) {
+    spg_t pgid;
+    pgid.parse(pgidstr.c_str());
+    r = action_on_all_objects_in_pg(store, coll_t(pgid), lookup, debug);
+  } else {
+    r = action_on_all_objects(store, lookup, debug);
   }
+  if (r)
+    return r;
+  lookup.dump(formatter);
+  formatter->flush(cout);
+  cout << std::endl;
   return 0;
 }
 
@@ -2128,7 +2125,7 @@ int main(int argc, char **argv)
     cerr << "Must provide --journal-path" << std::endl;
     usage(desc);
   }
-  if (vm.count("object") && !vm.count("objcmd")) {
+  if (op != "list" && vm.count("object") && !vm.count("objcmd")) {
     cerr << "Invalid syntax, missing command" << std::endl;
     usage(desc);
   }
@@ -2136,7 +2133,7 @@ int main(int argc, char **argv)
     cerr << "Must provide --op or object command..." << std::endl;
     usage(desc);
   }
-  if (vm.count("op") && vm.count("object")) {
+  if (op != "list" && vm.count("op") && vm.count("object")) {
     cerr << "Can't specify both --op and object command syntax" << std::endl;
     usage(desc);
   }
@@ -2305,7 +2302,7 @@ int main(int argc, char **argv)
     return 1;
   }
 
-  if (vm.count("object")) {
+  if (op != "list" && vm.count("object")) {
     json_spirit::Value v;
     try {
       if (!json_spirit::read(object, v)) {
@@ -2334,7 +2331,7 @@ int main(int argc, char **argv)
     }
   }
 
-  if (op != "import" && op != "list-lost" && op != "fix-lost"
+  if (op != "list" && op != "import" && op != "list-lost" && op != "fix-lost"
       && op != "list-pgs"  && op != "set-allow-sharded-objects" &&
       (pgidstr.length() == 0)) {
     cerr << "Must provide pgid" << std::endl;
@@ -2475,6 +2472,15 @@ int main(int argc, char **argv)
       ret = action_on_all_objects(fs, *action, debug);
     goto out;
   }
+
+  if (op == "list") {
+    Formatter *formatter = new JSONFormatter(false);
+    r = do_list(fs, pgidstr, object, formatter, debug);
+    if (r) {
+      cerr << "do_list failed with " << r << std::endl;
+      ret = 1;
+    }
+    goto out;
   }
 
   r = fs->list_collections(ls);
@@ -2687,16 +2693,6 @@ int main(int argc, char **argv)
       usage(desc);
     }
 
-    if (op == "list") {
-      Formatter *formatter = new JSONFormatter(false);
-      r = do_list(fs, coll, formatter);
-      if (r) {
-        cerr << "do_list failed with " << r << std::endl;
-        ret = 1;
-      }
-      goto out;
-    }
-
     Formatter *formatter = new JSONFormatter(true);
     bufferlist bl;
     map_epoch = PG::peek_map_epoch(fs, coll, infos_oid, &bl);