From: Sage Weil Date: Fri, 14 Apr 2017 18:16:50 +0000 (-0400) Subject: mon: move 'pg map' to OSDMonitor (from PGMap) X-Git-Tag: v12.0.3~291^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8720ed5124045703e1d02e3fae676cc29a2a65dd;p=ceph.git mon: move 'pg map' to OSDMonitor (from PGMap) 1. this belongs on the mon, operating against the latest osdmap. 2. it shouldn't go in PGMonitor because that is about to be turned off. Signed-off-by: Sage Weil --- diff --git a/src/mgr/MgrCommands.h b/src/mgr/MgrCommands.h index d7335b27eadc..17de3a8c7bba 100644 --- a/src/mgr/MgrCommands.h +++ b/src/mgr/MgrCommands.h @@ -37,8 +37,6 @@ COMMAND("pg ls " \ "name=pool,type=CephInt,req=false " \ "name=states,type=CephChoices,strings=active|clean|down|scrubbing|degraded|inconsistent|peering|repair|recovering|backfill_wait|incomplete|stale|remapped|deep_scrub|backfill|backfill_toofull|recovery_wait|undersized|activating|peered,n=N,req=false ", \ "list pg with specific pool, osd, state", "pg", "r", "cli,rest") -COMMAND("pg map name=pgid,type=CephPgid", "show mapping of pg to osds", \ - "pg", "r", "cli,rest") COMMAND("pg dump_stuck " \ "name=stuckops,type=CephChoices,strings=inactive|unclean|stale|undersized|degraded,n=N,req=false " \ "name=threshold,type=CephInt,req=false", diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 4e816890820b..329d11369ad7 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -131,6 +131,9 @@ COMMAND("pg set_nearfull_ratio name=ratio,type=CephFloat,range=0.0|1.0", \ "set ratio at which pgs are considered nearly full", \ "pg", "rw", "cli,rest") +COMMAND("pg map name=pgid,type=CephPgid", "show mapping of pg to osds", \ + "pg", "r", "cli,rest") + /* * auth commands AuthMonitor.cc */ diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index a80ceaa95c6f..0f9354dee06e 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -2920,7 +2920,7 @@ void Monitor::handle_command(MonOpRequestRef op) mdsmon()->dispatch(op); return; } - if (module == "osd") { + if (module == "osd" || prefix == "pg map") { osdmon()->dispatch(op); return; } diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 4e75d6a3c0f9..e36ecae30d69 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -3823,6 +3823,50 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) << pg_vector_string(acting) << ", p" << acting_p << ")"; rdata.append(ds); } + + } else if (prefix == "pg map") { + pg_t pgid; + string pgidstr; + cmd_getval(g_ceph_context, cmdmap, "pgid", pgidstr); + if (!pgid.parse(pgidstr.c_str())) { + ss << "invalid pgid '" << pgidstr << "'"; + r = -EINVAL; + goto reply; + } + vector up, acting; + if (!osdmap.have_pg_pool(pgid.pool())) { + ss << "pg '" << pgidstr << "' does not exist"; + r = -ENOENT; + goto reply; + } + pg_t mpgid = osdmap.raw_pg_to_pg(pgid); + osdmap.pg_to_up_acting_osds(pgid, up, acting); + if (f) { + f->open_object_section("pg_map"); + f->dump_unsigned("epoch", osdmap.get_epoch()); + f->dump_stream("raw_pgid") << pgid; + f->dump_stream("pgid") << mpgid; + + f->open_array_section("up"); + for (vector::iterator it = up.begin(); it != up.end(); ++it) + f->dump_int("up_osd", *it); + f->close_section(); + + f->open_array_section("acting"); + for (vector::iterator it = acting.begin(); it != acting.end(); ++it) + f->dump_int("acting_osd", *it); + f->close_section(); + + f->close_section(); + f->flush(rdata); + } else { + ds << "osdmap e" << osdmap.get_epoch() + << " pg " << pgid << " (" << mpgid << ")" + << " -> up " << up << " acting " << acting; + rdata.append(ds); + } + goto reply; + } else if ((prefix == "osd scrub" || prefix == "osd deep-scrub" || prefix == "osd repair")) { diff --git a/src/mon/PGMap.cc b/src/mon/PGMap.cc index 320309edd6c4..582bd8b96854 100644 --- a/src/mon/PGMap.cc +++ b/src/mon/PGMap.cc @@ -2315,48 +2315,6 @@ int process_pg_map_command( return 0; } - if (prefix == "pg map") { - pg_t pgid; - string pgidstr; - cmd_getval(g_ceph_context, cmdmap, "pgid", pgidstr); - if (!pgid.parse(pgidstr.c_str())) { - *ss << "invalid pgid '" << pgidstr << "'"; - return -EINVAL; - } - vector up, acting; - if (!osdmap.have_pg_pool(pgid.pool())) { - *ss << "pg '" << pgidstr << "' does not exist"; - return -ENOENT; - } - pg_t mpgid = osdmap.raw_pg_to_pg(pgid); - osdmap.pg_to_up_acting_osds(pgid, up, acting); - if (f) { - f->open_object_section("pg_map"); - f->dump_unsigned("epoch", osdmap.get_epoch()); - f->dump_stream("raw_pgid") << pgid; - f->dump_stream("pgid") << mpgid; - - f->open_array_section("up"); - for (vector::iterator it = up.begin(); it != up.end(); ++it) - f->dump_int("up_osd", *it); - f->close_section(); - - f->open_array_section("acting"); - for (vector::iterator it = acting.begin(); it != acting.end(); ++it) - f->dump_int("acting_osd", *it); - f->close_section(); - - f->close_section(); - f->flush(*odata); - } else { - ds << "osdmap e" << osdmap.get_epoch() - << " pg " << pgid << " (" << mpgid << ")" - << " -> up " << up << " acting " << acting; - odata->append(ds); - } - return 0; - } - if (prefix == "pg debug") { string debugop; cmd_getval(g_ceph_context, cmdmap, "debugop", debugop,