From 4c3270692e26a3fd630e49ec3b8ce40b73e66331 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 30 Jan 2016 13:29:05 +0800 Subject: [PATCH] rados: add "list-inconsistent-pg" command to list inconsistent PGs of a given pool. this command exposes the underlying get_inconsistent_pgs() API to user. Signed-off-by: Kefu Chai --- src/tools/rados/rados.cc | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 1538ee27527..d5848859d68 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -143,6 +143,9 @@ void usage(ostream& out) " --lock-duration Lock duration (in seconds)\n" " --lock-type Lock type (shared, exclusive)\n" "\n" +"SCRUB AND REPAIR:\n" +" list-inconsistent-pg list inconsistent PGs in given pool\n" +"\n" "CACHE POOLS: (for testing/development only)\n" " cache-flush flush cache pool object (blocking)\n" " cache-try-flush flush cache pool object (non-blocking)\n" @@ -1210,6 +1213,33 @@ static int do_cache_flush_evict_all(IoCtx& io_ctx, bool blocking) return errors ? -1 : 0; } +static int do_get_inconsistent_pg_cmd(const std::vector &nargs, + Rados& rados, + Formatter& formatter) +{ + if (nargs.size() < 2) { + usage_exit(); + } + int64_t pool_id = rados.pool_lookup(nargs[1]); + if (pool_id < 0) { + cerr << "pool \"" << nargs[1] << "\" not found" << std::endl; + return (int)pool_id; + } + std::vector pgs; + int ret = rados.get_inconsistent_pgs(pool_id, &pgs); + if (ret) { + return ret; + } + formatter.open_array_section("pgs"); + for (auto& pg : pgs) { + formatter.dump_stream("pg") << pg; + } + formatter.close_section(); + formatter.flush(cout); + cout << std::endl; + return 0; +} + /********************************************** **********************************************/ @@ -2830,7 +2860,11 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, } else { cout << std::endl; } - + } else if (strcmp(nargs[0], "list-inconsistent-pg") == 0) { + if (!formatter) { + formatter = new JSONFormatter(pretty_format); + } + ret = do_get_inconsistent_pg_cmd(nargs, rados, *formatter); } else if (strcmp(nargs[0], "cache-flush") == 0) { if (!pool_name || nargs.size() < 2) usage_exit(); -- 2.47.3