From 54b8cd34fef2ed9bdf116efd86caed0f185ab8d3 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Tue, 15 Dec 2009 15:50:00 -0800 Subject: [PATCH] Make a more flexible 'tell' command to replace injectargs osd/mds: make a handle_command function; don't parse all MMonCommands as config mon: Send injectargs to osd/mds in new format; accept tells for mds and osd --- src/mds/MDS.cc | 12 ++++++++++-- src/mds/MDS.h | 1 + src/mon/MDSMonitor.cc | 25 +++++++++++++++++++++++++ src/mon/Monitor.cc | 13 ++++++++++--- src/mon/Monitor.h | 2 ++ src/mon/OSDMonitor.cc | 24 ++++++++++++++++++++++++ src/osd/OSD.cc | 13 +++++++++++-- src/osd/OSD.h | 2 ++ 8 files changed, 85 insertions(+), 7 deletions(-) diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index ebc39a4c5c15d..78ba9eb8ae1fc 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -569,6 +569,15 @@ void MDS::beacon_kill(utime_t lab) } +void MDS::handle_command(MMonCommand *m) +{ + dout(20) << "handle_command args: " << m->cmd << dendl; + if (m->cmd[0] == "injectargs") + parse_config_option_string(m->cmd[1]); + else + dout(0) << "unrecognized command! " << m->cmd << dendl; + delete m; +} void MDS::handle_mds_map(MMDSMap *m) { @@ -1239,8 +1248,7 @@ do { \ // misc case MSG_MON_COMMAND: ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON); - parse_config_option_string(((MMonCommand*)m)->cmd[0]); - delete m; + handle_command((MMonCommand*)m); break; default: diff --git a/src/mds/MDS.h b/src/mds/MDS.h index 5c296417162c3..cf77a34fde26c 100644 --- a/src/mds/MDS.h +++ b/src/mds/MDS.h @@ -375,6 +375,7 @@ class MDS : public Dispatcher { void ms_handle_remote_reset(Connection *con); // special message types + void handle_command(class MMonCommand *m); void handle_mds_map(class MMDSMap *m); }; diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index 43763a5a6e8d9..248ca5d2208c0 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -449,6 +449,31 @@ bool MDSMonitor::preprocess_command(MMonCommand *m) ss << "specify mds number or *"; } } + else if (m->cmd[1] == "tell") { + m->cmd.erase(m->cmd.begin()); //take out first two args; don't need them + m->cmd.erase(m->cmd.begin()); + if (m->cmd[0] == "*") { + m->cmd.erase(m->cmd.begin()); //and now we're done with the target num + for (unsigned i = 0; i < mdsmap.get_max_mds(); ++i) { + if (mdsmap.is_active(i)) + mon->send_command(mdsmap.get_inst(i), m->cmd, paxos->get_version()); + } + } else { + errno = 0; + int who = strtol(m->cmd[0].c_str(), 0, 10); + m->cmd.erase(m->cmd.begin()); //done with target num now + if (!errno && who >= 0) { + if (mdsmap.is_up(who)) { + mon->send_command(mdsmap.get_inst(who), m->cmd, paxos->get_version()); + r = 0; + ss << "ok"; + } else { + ss << "mds" << who << " no up"; + r = -ENOENT; + } + } else ss << "specify mds number or *"; + } + } } if (r != -1) { diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index caac0fc49f2dc..5ac53ccd26a89 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -454,14 +454,21 @@ void Monitor::handle_observe(MMonObserve *m) void Monitor::inject_args(const entity_inst_t& inst, vector& args, version_t version) { dout(10) << "inject_args " << inst << " " << args << dendl; + vector new_args = args; + new_args.insert(new_args.begin(), "injectargs"); + send_command(inst, new_args, version); +} + +void Monitor::send_command(const entity_inst_t& inst, + const vector& com, version_t version) +{ + dout(10) << "send_command " << inst << "" << com << dendl; MMonCommand *c = new MMonCommand(monmap->fsid, version); - c->cmd = args; + c->cmd = com; try_send_message(c, inst); } - - void Monitor::stop_cluster() { dout(0) << "stop_cluster -- initiating shutdown" << dendl; diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 073aa0de13e27..6f161caed1b4a 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -185,6 +185,8 @@ public: inject_args(inst, a, version); } void inject_args(const entity_inst_t& inst, vector& args, version_t version); +void send_command(const entity_inst_t& inst, + const vector& com, version_t version); public: struct C_Command : public Context { diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index af6c3378f097f..92cb41df23fb2 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -937,6 +937,30 @@ bool OSDMonitor::preprocess_command(MMonCommand *m) ss << "specify osd number or *"; } } + else if (m->cmd[1] == "tell") { + m->cmd.erase(m->cmd.begin()); //take out first two args; don't need them + m->cmd.erase(m->cmd.begin()); + if (m->cmd[0] == "*") { + m->cmd.erase(m->cmd.begin()); //and now we're done with the target num + for (int i = 0; i < osdmap.get_max_osd(); ++i) { + mon->send_command(osdmap.get_inst(i), m->cmd, paxos->get_version()); + } + } else { + errno = 0; + int who = strtol(m->cmd[0].c_str(), 0, 10); + m->cmd.erase(m->cmd.begin()); //done with target num now + if (!errno && who >= 0) { + if (osdmap.is_up(who)) { + mon->send_command(osdmap.get_inst(who), m->cmd, paxos->get_version()); + r = 0; + ss << "ok"; + } else { + ss << "osd" << who << " no up"; + r = -ENOENT; + } + } else ss << "specify osd number or *"; + } + } else if ((m->cmd[1] == "scrub" || m->cmd[1] == "repair") && m->cmd.size() > 2) { if (m->cmd[2] == "*") { ss << "osds "; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index c7d256087c71d..c28c63804bfd3 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1415,6 +1415,16 @@ void OSD::handle_pg_stats_ack(MPGStatsAck *ack) delete ack; } +void OSD::handle_command(MMonCommand *m) +{ + dout(20) << "handle_command args: " << m->cmd << dendl; + if (m->cmd[0] == "injectargs") + parse_config_option_string(m->cmd[1]); + else + dout(0) << "unrecognized command! " << m->cmd << dendl; + delete m; +} + @@ -1657,8 +1667,7 @@ do { \ case MSG_MON_COMMAND: ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON); - parse_config_option_string(((MMonCommand*)m)->cmd[0]); - delete m; + handle_command((MMonCommand*) m); break; case MSG_OSD_SCRUB: diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 9b1ab2041f39d..93a9942ec4a46 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -537,6 +537,8 @@ protected: void send_pg_stats(); void handle_pg_stats_ack(class MPGStatsAck *ack); + void handle_command(class MMonCommand *m); + void pg_stat_queue_enqueue(PG *pg) { pg_stat_queue_lock.Lock(); if (pg->is_primary() && !pg->stat_queue_item.is_on_xlist()) { -- 2.39.5