From: Loic Dachary Date: Wed, 26 Nov 2014 22:35:21 +0000 (+0100) Subject: objectstore_tool: filter --op list and explore all PGs X-Git-Tag: v0.92~32^2~7^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c69aaceac7f370e5369d511bf17898adc338ae43;p=ceph.git objectstore_tool: filter --op list and explore all PGs 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 --- diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index a3b45d58cfc7..ed1df237a3e5 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -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 objects; - int r = store->collection_list_partial(coll, next, 200, 300, 0, - &objects, &next); - if (r < 0) - return r; - for (vector::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);