]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rados: add "list-inconsistent-pg" command
authorKefu Chai <kchai@redhat.com>
Sat, 30 Jan 2016 05:29:05 +0000 (13:29 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 25 Feb 2016 04:40:17 +0000 (12:40 +0800)
to list inconsistent PGs of a given pool. this command exposes
the underlying get_inconsistent_pgs() API to user.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/tools/rados/rados.cc

index 1538ee27527d2b1c40515b98eb80e123a4b49d66..d5848859d68301bc8ed31b20bf03214d8886cbf2 100644 (file)
@@ -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 <pool>      list inconsistent PGs in given pool\n"
+"\n"
 "CACHE POOLS: (for testing/development only)\n"
 "   cache-flush <obj-name>           flush cache pool object (blocking)\n"
 "   cache-try-flush <obj-name>       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<const char*> &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<PlacementGroup> 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();