From 87a7f991d1f2f1a05fff18accc7e31ff393083f1 Mon Sep 17 00:00:00 2001 From: David Zafman Date: Tue, 9 Jun 2015 18:14:09 -0700 Subject: [PATCH] tools: For ec pools list objects in all shards if the pgid doesn't specify Signed-off-by: David Zafman (cherry picked from commit 1aa9655f10b0fcc42cb5114681b8b24a2ccb68f4) --- src/tools/ceph_objectstore_tool.cc | 55 +++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 396964f295e42..70209496a60ae 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -434,7 +434,54 @@ int _action_on_all_objects_in_pg(ObjectStore *store, coll_t coll, action_on_obje return 0; } -int action_on_all_objects_in_pg(ObjectStore *store, coll_t coll, action_on_object_t &action, bool debug) +int action_on_all_objects_in_pg(ObjectStore *store, string pgidstr, action_on_object_t &action, bool debug) +{ + spg_t pgid; + // Scan collections in case this is an ec pool but no shard specified + unsigned scanned = 0; + int r = 0; + vector colls_to_check; + vector candidates; + r = store->list_collections(candidates); + if (r < 0) { + cerr << "Error listing collections: " << cpp_strerror(r) << std::endl; + return r; + } + pgid.parse(pgidstr.c_str()); + for (vector::iterator i = candidates.begin(); + i != candidates.end(); + ++i) { + spg_t cand_pgid; + snapid_t snap; + if (!i->is_pg(cand_pgid, snap)) + continue; + if (snap != CEPH_NOSNAP) + continue; + + // If an exact match or treat no shard as any shard + if (cand_pgid == pgid || + (pgid.is_no_shard() && pgid.pgid == cand_pgid.pgid)) { + colls_to_check.push_back(*i); + } + } + + if (debug) + cerr << colls_to_check.size() << " pgs to scan" << std::endl; + for (vector::iterator i = colls_to_check.begin(); + i != colls_to_check.end(); + ++i, ++scanned) { + if (debug) + cerr << "Scanning " << *i << ", " << scanned << "/" + << colls_to_check.size() << " completed" << std::endl; + r = _action_on_all_objects_in_pg(store, *i, action, debug); + if (r < 0) + break; + } + store->sync_and_flush(); + return r; +} + +int action_on_all_objects_in_exact_pg(ObjectStore *store, coll_t coll, action_on_object_t &action, bool debug) { int r = _action_on_all_objects_in_pg(store, coll, action, debug); store->sync_and_flush(); @@ -2125,9 +2172,7 @@ int do_list(ObjectStore *store, string pgidstr, string object, Formatter *format 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); + r = action_on_all_objects_in_pg(store, pgidstr, lookup, debug); } else { r = action_on_all_objects(store, lookup, debug); } @@ -3139,7 +3184,7 @@ int main(int argc, char **argv) boost::scoped_ptr action; action.reset(new do_fix_lost()); if (pgidstr.length()) - ret = action_on_all_objects_in_pg(fs, coll_t(pgid), *action, debug); + ret = action_on_all_objects_in_exact_pg(fs, coll_t(pgid), *action, debug); else ret = action_on_all_objects(fs, *action, debug); goto out; -- 2.39.5