From 08384930d02a47c84861da3571feb99254e85319 Mon Sep 17 00:00:00 2001 From: sageweil Date: Wed, 19 Dec 2007 04:53:48 +0000 Subject: [PATCH] minor mon command handler cleanup git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@2230 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/mon/MDSMonitor.cc | 31 ++++++------------ trunk/ceph/mon/MDSMonitor.h | 4 ++- trunk/ceph/mon/Monitor.cc | 60 +++++++++++++++++++---------------- trunk/ceph/mon/Monitor.h | 5 ++- trunk/ceph/mon/OSDMonitor.cc | 6 ++++ trunk/ceph/mon/OSDMonitor.h | 3 ++ trunk/ceph/mon/Paxos.h | 1 + trunk/ceph/mon/PaxosService.h | 4 +-- 8 files changed, 59 insertions(+), 55 deletions(-) diff --git a/trunk/ceph/mon/MDSMonitor.cc b/trunk/ceph/mon/MDSMonitor.cc index 4905a058a2a85..db71d66cb991f 100644 --- a/trunk/ceph/mon/MDSMonitor.cc +++ b/trunk/ceph/mon/MDSMonitor.cc @@ -22,9 +22,6 @@ #include "messages/MMDSGetMap.h" #include "messages/MMDSBeacon.h" -#include "messages/MMonCommand.h" -#include "messages/MMonCommandAck.h" - #include "messages/MGenericMessage.h" @@ -158,9 +155,6 @@ bool MDSMonitor::preprocess_query(Message *m) handle_mds_getmap((MMDSGetMap*)m); return true; - case MSG_MON_COMMAND: - return false; - default: assert(0); delete m; @@ -258,9 +252,6 @@ bool MDSMonitor::prepare_update(Message *m) case MSG_MDS_BEACON: return handle_beacon((MMDSBeacon*)m); - case MSG_MON_COMMAND: - return handle_command((MMonCommand*)m); - default: assert(0); delete m; @@ -475,14 +466,15 @@ void MDSMonitor::take_over(entity_addr_t addr, int mds) -bool MDSMonitor::handle_command(MMonCommand *m) +int MDSMonitor::do_command(vector& cmd, bufferlist& data, + bufferlist& rdata, string &rs) { int r = -EINVAL; stringstream ss; - if (m->cmd.size() > 1) { - if (m->cmd[1] == "stop" && m->cmd.size() > 2) { - int who = atoi(m->cmd[2].c_str()); + if (cmd.size() > 1) { + if (cmd[1] == "stop" && cmd.size() > 2) { + int who = atoi(cmd[2].c_str()); if (mdsmap.is_active(who)) { r = 0; ss << "telling mds" << who << " to stop"; @@ -492,8 +484,8 @@ bool MDSMonitor::handle_command(MMonCommand *m) ss << "mds" << who << " not active (" << mdsmap.get_state_name(mdsmap.get_state(who)) << ")"; } } - else if (m->cmd[1] == "set_max_mds" && m->cmd.size() > 2) { - pending_mdsmap.max_mds = atoi(m->cmd[2].c_str()); + else if (cmd[1] == "set_max_mds" && cmd.size() > 2) { + pending_mdsmap.max_mds = atoi(cmd[2].c_str()); r = 0; ss << "max_mds = " << pending_mdsmap.max_mds; } @@ -501,13 +493,10 @@ bool MDSMonitor::handle_command(MMonCommand *m) if (r == -EINVAL) { ss << "unrecognized command"; } - + // reply - string rs; - getline(ss,rs); - mon->messenger->send_message(new MMonCommandAck(r, rs), m->get_source_inst()); - delete m; - return r >= 0; + getline(ss, rs); + return r; } diff --git a/trunk/ceph/mon/MDSMonitor.h b/trunk/ceph/mon/MDSMonitor.h index 76420621d07a2..16b7eba71c8bd 100644 --- a/trunk/ceph/mon/MDSMonitor.h +++ b/trunk/ceph/mon/MDSMonitor.h @@ -72,11 +72,13 @@ class MDSMonitor : public PaxosService { bool preprocess_beacon(class MMDSBeacon *m); bool handle_beacon(class MMDSBeacon *m); - bool handle_command(class MMonCommand *m); void handle_mds_getmap(MMDSGetMap *m); void take_over(entity_addr_t addr, int mds); + int do_command(vector& cmd, bufferlist& data, + bufferlist& rdata, string &rs); + // beacons map last_beacon; diff --git a/trunk/ceph/mon/Monitor.cc b/trunk/ceph/mon/Monitor.cc index 0c3dc0452c34d..cac9dd74922bb 100644 --- a/trunk/ceph/mon/Monitor.cc +++ b/trunk/ceph/mon/Monitor.cc @@ -69,7 +69,6 @@ void Monitor::init() pgmon = new PGMonitor(this, &paxos_pgmap); // init paxos - paxos_test.init(); paxos_osdmap.init(); paxos_mdsmap.init(); paxos_clientmap.init(); @@ -148,7 +147,6 @@ void Monitor::call_election() state = STATE_STARTING; // tell paxos - paxos_test.election_starting(); paxos_mdsmap.election_starting(); paxos_osdmap.election_starting(); paxos_clientmap.election_starting(); @@ -166,7 +164,6 @@ void Monitor::win_election(epoch_t epoch, set& active) dout(10) << "win_election, epoch " << mon_epoch << " quorum is " << quorum << dendl; // init paxos - paxos_test.leader_init(); paxos_mdsmap.leader_init(); paxos_osdmap.leader_init(); paxos_clientmap.leader_init(); @@ -187,7 +184,6 @@ void Monitor::lose_election(epoch_t epoch, int l) dout(10) << "lose_election, epoch " << mon_epoch << " leader is mon" << leader << dendl; // init paxos - paxos_test.peon_init(); paxos_mdsmap.peon_init(); paxos_osdmap.peon_init(); paxos_clientmap.peon_init(); @@ -201,37 +197,48 @@ void Monitor::lose_election(epoch_t epoch, int l) } +int Monitor::do_command(vector& cmd, bufferlist& data, + bufferlist& rdata, string &rs) +{ + if (cmd.empty()) { + rs = "no command"; + return -EINVAL; + } + + if (cmd[0] == "stop") { + rs = "stopping"; + do_stop(); + return 0; + } + if (cmd[0] == "mds") + return mdsmon->do_command(cmd, data, rdata, rs); + + if (cmd[0] == "osd") + return osdmon->do_command(cmd, data, rdata, rs); + + // huh. + rs = "unrecognized subsystem '" + cmd[0] + "'"; + return -EINVAL; +} + void Monitor::handle_command(MMonCommand *m) { dout(0) << "handle_command " << *m << dendl; - int r = -1; - string rs = "unrecognized command"; - - if (!m->cmd.empty()) { - if (m->cmd[0] == "stop") { - r = 0; - rs = "stopping"; - do_stop(); - } - else if (m->cmd[0] == "mds") { - mdsmon->dispatch(m); - return; - } - else if (m->cmd[0] == "osd") { - - } - } - - // reply - messenger->send_message(new MMonCommandAck(r, rs), m->get_source_inst()); + string rs; // return string + bufferlist rdata; // return data + int rc = do_command(m->cmd, m->get_data(), rdata, rs); + + MMonCommandAck *reply = new MMonCommandAck(rc, rs); + reply->set_data(rdata); + messenger->send_message(reply, m->get_source_inst()); delete m; } void Monitor::do_stop() { - dout(0) << "do_stop -- shutting down" << dendl; + dout(0) << "do_stop -- initiating shutdown" << dendl; stopping = true; mdsmon->do_stop(); } @@ -304,9 +311,6 @@ void Monitor::dispatch(Message *m) // send it to the right paxos instance switch (pm->machine_id) { - case PAXOS_TEST: - paxos_test.dispatch(m); - break; case PAXOS_OSDMAP: paxos_osdmap.dispatch(m); break; diff --git a/trunk/ceph/mon/Monitor.h b/trunk/ceph/mon/Monitor.h index bd278a2092308..dc06c937a1e6a 100644 --- a/trunk/ceph/mon/Monitor.h +++ b/trunk/ceph/mon/Monitor.h @@ -88,7 +88,6 @@ public: // -- paxos -- - Paxos paxos_test; Paxos paxos_mdsmap; Paxos paxos_osdmap; Paxos paxos_clientmap; @@ -113,7 +112,8 @@ public: void handle_ping_ack(class MPingAck *m); void handle_command(class MMonCommand *m); - + int do_command(vector& cmd, bufferlist& data, + bufferlist& rdata, string &rs); public: Monitor(int w, Messenger *m, MonMap *mm) : @@ -129,7 +129,6 @@ public: mon_epoch(0), leader(0), - paxos_test(this, w, PAXOS_TEST), paxos_mdsmap(this, w, PAXOS_MDSMAP), paxos_osdmap(this, w, PAXOS_OSDMAP), paxos_clientmap(this, w, PAXOS_CLIENTMAP), diff --git a/trunk/ceph/mon/OSDMonitor.cc b/trunk/ceph/mon/OSDMonitor.cc index db3bc57841597..693bb1a1dcae6 100644 --- a/trunk/ceph/mon/OSDMonitor.cc +++ b/trunk/ceph/mon/OSDMonitor.cc @@ -851,3 +851,9 @@ void OSDMonitor::mark_all_down() } +int OSDMonitor::do_command(vector& cmd, bufferlist& data, + bufferlist& rdata, string &rs) +{ + rs = "unknown command"; + return -EINVAL; +} diff --git a/trunk/ceph/mon/OSDMonitor.h b/trunk/ceph/mon/OSDMonitor.h index c22c007f2d9b6..bbaf3762b44f0 100644 --- a/trunk/ceph/mon/OSDMonitor.h +++ b/trunk/ceph/mon/OSDMonitor.h @@ -119,6 +119,9 @@ private: void tick(); // check state, take actions + int do_command(vector& cmd, bufferlist& data, + bufferlist& rdata, string &rs); + void mark_all_down(); void send_latest(entity_inst_t i, epoch_t start=0); diff --git a/trunk/ceph/mon/Paxos.h b/trunk/ceph/mon/Paxos.h index a6d28dd1cea9a..57c0e001495e8 100644 --- a/trunk/ceph/mon/Paxos.h +++ b/trunk/ceph/mon/Paxos.h @@ -44,6 +44,7 @@ e 12v * "read" their copy of the last committed value. * * This provides a simple replication substrate that services can be built on top of. + * See PaxosService.h */ #ifndef __MON_PAXOS_H diff --git a/trunk/ceph/mon/PaxosService.h b/trunk/ceph/mon/PaxosService.h index a0f39c7862273..234f0bf3c4c4f 100644 --- a/trunk/ceph/mon/PaxosService.h +++ b/trunk/ceph/mon/PaxosService.h @@ -89,7 +89,7 @@ public: void propose_pending(); // propose current pending as new paxos state // you implement - virtual bool update_from_paxos() = 0; // assimilate latest paxos state + virtual bool update_from_paxos() = 0; // assimilate latest state from paxos virtual void create_pending() = 0; // [leader] create new pending structures virtual void create_initial() = 0; // [leader] populate pending with initial state (1) virtual void encode_pending(bufferlist& bl) = 0; // [leader] finish and encode pending for next paxos state @@ -99,7 +99,7 @@ public: virtual bool prepare_update(Message *m) = 0; virtual bool should_propose(double &delay); - virtual void committed() = 0; + virtual void committed() = 0; // [leader] called after a proposed value commits }; -- 2.39.5