From 97d55fd1134f4a68dbdbf76b9200ccdd7d748879 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Wed, 20 Feb 2019 14:14:26 +0800 Subject: [PATCH] mgr: add per pool scrub commands Signed-off-by: xie xingguo --- qa/workunits/cephtool/test.sh | 9 +++++ src/mgr/DaemonServer.cc | 67 +++++++++++++++++++++++++++++++++++ src/mgr/MgrCommands.h | 12 +++++++ 3 files changed, 88 insertions(+) diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 2f7b5da5d4407..0619e184cea70 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -1439,6 +1439,15 @@ function test_mon_osd() ceph osd deep-scrub 0 ceph osd repair 0 + # pool scrub + pool_names=`rados lspools` + for pool_name in $pool_names + do + ceph osd pool scrub $pool_name + ceph osd pool deep-scrub $pool_name + ceph osd pool repair $pool_name + done + for f in noup nodown noin noout noscrub nodeep-scrub nobackfill norebalance norecover notieragent full do ceph osd set $f diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index 7e14bf51dd0db..c7cc8c56565a3 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -1087,6 +1087,73 @@ bool DaemonServer::_handle_command( } cmdctx->reply(0, ss); return true; + } else if (prefix == "osd pool scrub" || + prefix == "osd pool deep-scrub" || + prefix == "osd pool repair") { + vector pool_names; + cmd_getval(g_ceph_context, cmdctx->cmdmap, "who", pool_names); + if (pool_names.empty()) { + ss << "must specify one or more pool names"; + cmdctx->reply(-EINVAL, ss); + return true; + } + epoch_t epoch; + map> pgs_by_primary; // legacy + map> spgs_by_primary; + cluster_state.with_osdmap([&](const OSDMap& osdmap) { + epoch = osdmap.get_epoch(); + for (auto& pool_name : pool_names) { + auto pool_id = osdmap.lookup_pg_pool_name(pool_name); + if (pool_id < 0) { + ss << "unrecognized pool '" << pool_name << "'"; + r = -ENOENT; + return; + } + auto pool_pg_num = osdmap.get_pg_num(pool_id); + for (int i = 0; i < pool_pg_num; i++) { + pg_t pg(i, pool_id); + int primary; + spg_t spg; + auto got = osdmap.get_primary_shard(pg, &primary, &spg); + if (!got) + continue; + pgs_by_primary[primary].push_back(pg); + spgs_by_primary[primary].push_back(spg); + } + } + }); + if (r < 0) { + cmdctx->reply(r, ss); + return true; + } + for (auto& it : spgs_by_primary) { + auto primary = it.first; + auto p = osd_cons.find(primary); + if (p == osd_cons.end()) { + ss << "osd." << primary << " is not currently connected"; + cmdctx->reply(-EAGAIN, ss); + return true; + } + for (auto& con : p->second) { + if (HAVE_FEATURE(con->get_features(), SERVER_MIMIC)) { + con->send_message(new MOSDScrub2(monc->get_fsid(), + epoch, + it.second, + prefix == "osd pool repair", + prefix == "osd pool deep-scrub")); + } else { + // legacy + auto q = pgs_by_primary.find(primary); + ceph_assert(q != pgs_by_primary.end()); + con->send_message(new MOSDScrub(monc->get_fsid(), + q->second, + prefix == "osd pool repair", + prefix == "osd pool deep-scrub")); + } + } + } + cmdctx->reply(0, ""); + return true; } else if (prefix == "osd reweight-by-pg" || prefix == "osd reweight-by-utilization" || prefix == "osd test-reweight-by-pg" || diff --git a/src/mgr/MgrCommands.h b/src/mgr/MgrCommands.h index 11a11361a1a67..674c1d75de926 100644 --- a/src/mgr/MgrCommands.h +++ b/src/mgr/MgrCommands.h @@ -77,6 +77,18 @@ COMMAND("osd pool stats " \ "name=pool_name,type=CephPoolname,req=false", "obtain stats from all pools, or from specified pool", "osd", "r") +COMMAND("osd pool scrub " \ + "name=who,type=CephPoolname,n=N", \ + "initiate scrub on pool ", \ + "osd", "rw") +COMMAND("osd pool deep-scrub " \ + "name=who,type=CephPoolname,n=N", \ + "initiate deep-scrub on pool ", \ + "osd", "rw") +COMMAND("osd pool repair " \ + "name=who,type=CephPoolname,n=N", \ + "initiate repair on pool ", \ + "osd", "rw") COMMAND("osd reweight-by-utilization " \ "name=oload,type=CephInt,req=false " \ "name=max_change,type=CephFloat,req=false " \ -- 2.39.5