From 207494ebc07f3baf3ad395400409582062fcf688 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 8 Apr 2008 11:29:17 -0700 Subject: [PATCH] tag monitor messages with fsid --- src/cmonctl.cc | 2 +- src/fakefuse.cc | 2 +- src/fakesyn.cc | 2 +- src/include/ceph_fs.h | 11 +++++++++++ src/kernel/mon_client.c | 16 +++++++++++----- src/mds/MDS.cc | 2 +- src/messages/MMonCommand.h | 7 +++++-- src/messages/MMonGetMap.h | 2 +- src/messages/MOSDFailure.h | 9 ++++++--- src/messages/MOSDGetMap.h | 6 ++++-- src/mon/Monitor.cc | 6 ++++++ src/mon/OSDMonitor.cc | 20 ++++++++++++++++++++ src/osd/OSD.cc | 9 +++++---- src/osdc/Objecter.cc | 7 ++++--- 14 files changed, 77 insertions(+), 24 deletions(-) diff --git a/src/cmonctl.cc b/src/cmonctl.cc index 8ea5b78895c55..28958c2c0f740 100644 --- a/src/cmonctl.cc +++ b/src/cmonctl.cc @@ -140,7 +140,7 @@ int main(int argc, const char **argv, const char *envp[]) { messenger->set_dispatcher(&dispatcher); // build command - MMonCommand *m = new MMonCommand(messenger->get_myinst()); + MMonCommand *m = new MMonCommand(monmap.fsid, messenger->get_myinst()); m->set_data(indata); m->cmd.swap(vcmd); int mon = monmap.pick_mon(); diff --git a/src/fakefuse.cc b/src/fakefuse.cc index 9861ff86c4e81..f799b1ff1c8a6 100644 --- a/src/fakefuse.cc +++ b/src/fakefuse.cc @@ -127,7 +127,7 @@ int main(int argc, const char **argv) { bufferlist bl; map.encode(bl); Messenger *messenger = new FakeMessenger(entity_name_t::ADMIN(-1)); - MMonCommand *m = new MMonCommand(messenger->get_myinst()); + MMonCommand *m = new MMonCommand(monmap->fsid, messenger->get_myinst()); m->set_data(bl); m->cmd.push_back("osd"); m->cmd.push_back("setmap"); diff --git a/src/fakesyn.cc b/src/fakesyn.cc index c2c7c7a3dfc97..4828238689383 100644 --- a/src/fakesyn.cc +++ b/src/fakesyn.cc @@ -126,7 +126,7 @@ int main(int argc, const char **argv) bufferlist bl; map.encode(bl); Messenger *messenger = new FakeMessenger(entity_name_t::ADMIN(-1)); - MMonCommand *m = new MMonCommand(messenger->get_myinst()); + MMonCommand *m = new MMonCommand(monmap->fsid, messenger->get_myinst()); m->set_data(bl); m->cmd.push_back("osd"); m->cmd.push_back("setmap"); diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index 67bc33de23304..b77e0d160eb48 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -286,6 +286,17 @@ struct ceph_statfs { __le64 f_objects; }; +struct ceph_osd_getmap { + struct ceph_fsid fsid; + __le64 start, want; +} __attribute__ ((packed)); + +struct ceph_mds_getmap { + struct ceph_fsid fsid; + __le64 have; +} __attribute__ ((packed)); + + /* * mds states * > 0 -> in diff --git a/src/kernel/mon_client.c b/src/kernel/mon_client.c index 6252bae2f8c2e..7802c3e8af249 100644 --- a/src/kernel/mon_client.c +++ b/src/kernel/mon_client.c @@ -119,13 +119,16 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl) int ceph_monc_request_mdsmap(struct ceph_mon_client *monc, __u32 have) { int mon = pick_mon(monc, -1); + struct ceph_mds_getmap *h; dout(5, "ceph_monc_request_mdsmap from mon%d have %u\n", mon, have); monc->want_mdsmap = have; - monc->msg = ceph_msg_new(CEPH_MSG_MDS_GETMAP, sizeof(__u32), 0, 0, 0); + monc->msg = ceph_msg_new(CEPH_MSG_MDS_GETMAP, sizeof(*h), 0, 0, 0); if (IS_ERR(monc->msg)) return PTR_ERR(monc->msg); - *(__le32*)monc->msg->front.iov_base = cpu_to_le32(have); + h = monc->msg->front.iov_base; + h->fsid = monc->monmap->fsid; + h->have = cpu_to_le32(have); monc->msg->hdr.dst = monc->monmap->mon_inst[mon]; ceph_delayed_work(&monc->delayed_work, &monc->delay); return 0; @@ -152,16 +155,19 @@ int ceph_monc_request_osdmap(struct ceph_mon_client *monc, __u32 have, __u32 want) { struct ceph_msg *msg; + struct ceph_osd_getmap *h; int mon = pick_mon(monc, -1); dout(5, "ceph_monc_request_osdmap from mon%d have %u want %u\n", mon, have, want); monc->want_mdsmap = have; - msg = ceph_msg_new(CEPH_MSG_OSD_GETMAP, 2*sizeof(__u32), 0, 0, 0); + msg = ceph_msg_new(CEPH_MSG_OSD_GETMAP, sizeof(*h), 0, 0, 0); if (IS_ERR(msg)) return PTR_ERR(msg); - *(__le32*)msg->front.iov_base = cpu_to_le32(have); - *(((__le32*)msg->front.iov_base)+1) = cpu_to_le32(want); + h = msg->front.iov_base; + h->fsid = monc->monmap->fsid; + h->start = cpu_to_le32(have); + h->want = cpu_to_le32(want); msg->hdr.dst = monc->monmap->mon_inst[mon]; ceph_msg_send(monc->client->msgr, msg, 0); return 0; diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 6440c7f00853d..9278f3520276e 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -509,7 +509,7 @@ void MDS::handle_mds_map(MMDSMap *m) if (oldwhoami < 0) { // we need an osdmap too. int mon = monmap->pick_mon(); - messenger->send_message(new MOSDGetMap(0), + messenger->send_message(new MOSDGetMap(monmap->fsid, 0), monmap->get_inst(mon)); } } diff --git a/src/messages/MMonCommand.h b/src/messages/MMonCommand.h index ca2f7dc96ed8b..f982d23034aad 100644 --- a/src/messages/MMonCommand.h +++ b/src/messages/MMonCommand.h @@ -22,13 +22,14 @@ using std::vector; class MMonCommand : public Message { public: + ceph_fsid fsid; entity_inst_t inst; vector cmd; MMonCommand() : Message(MSG_MON_COMMAND) {} - MMonCommand(entity_inst_t i) : + MMonCommand(ceph_fsid &f, entity_inst_t i) : Message(MSG_MON_COMMAND), - inst(i) { } + fsid(f), inst(i) { } const char *get_type_name() { return "mon_command"; } void print(ostream& o) { @@ -41,11 +42,13 @@ class MMonCommand : public Message { } void encode_payload() { + ::_encode(fsid, payload); ::_encode(inst, payload); ::_encode(cmd, payload); } void decode_payload() { int off = 0; + ::_decode(fsid, payload, off); ::_decode(inst, payload, off); ::_decode(cmd, payload, off); } diff --git a/src/messages/MMonGetMap.h b/src/messages/MMonGetMap.h index b942fe1b56067..5e28cac8d8c44 100644 --- a/src/messages/MMonGetMap.h +++ b/src/messages/MMonGetMap.h @@ -24,7 +24,7 @@ class MMonGetMap : public Message { public: MMonGetMap() : Message(CEPH_MSG_MON_GET_MAP) { } - const char *get_type_name() { return "mongetmap"; } + const char *get_type_name() { return "mon_getmap"; } void encode_payload() { } void decode_payload() { } diff --git a/src/messages/MOSDFailure.h b/src/messages/MOSDFailure.h index 9f709bc7deeb0..f5ca4a0d218f4 100644 --- a/src/messages/MOSDFailure.h +++ b/src/messages/MOSDFailure.h @@ -21,14 +21,15 @@ class MOSDFailure : public Message { public: + ceph_fsid fsid; entity_inst_t from; entity_inst_t failed; epoch_t epoch; - MOSDFailure() {} - MOSDFailure(entity_inst_t fr, entity_inst_t f, epoch_t e) : + MOSDFailure() : Message(MSG_OSD_FAILURE) {} + MOSDFailure(ceph_fsid &fs, entity_inst_t fr, entity_inst_t f, epoch_t e) : Message(MSG_OSD_FAILURE), - from(fr), failed(f), epoch(e) {} + fsid(fs), from(fr), failed(f), epoch(e) {} entity_inst_t get_from() { return from; } entity_inst_t get_failed() { return failed; } @@ -36,11 +37,13 @@ class MOSDFailure : public Message { void decode_payload() { int off = 0; + ::_decode(fsid, payload, off); ::_decode(from, payload, off); ::_decode(failed, payload, off); ::_decode(epoch, payload, off); } void encode_payload() { + ::_encode(fsid, payload); ::_encode(from, payload); ::_encode(failed, payload); ::_encode(epoch, payload); diff --git a/src/messages/MOSDGetMap.h b/src/messages/MOSDGetMap.h index bd4dd586e5ee8..8111964777ad4 100644 --- a/src/messages/MOSDGetMap.h +++ b/src/messages/MOSDGetMap.h @@ -21,11 +21,13 @@ class MOSDGetMap : public Message { public: + ceph_fsid fsid; epoch_t start, want; - MOSDGetMap(epoch_t s=0, epoch_t w=0) : + MOSDGetMap() : Message(CEPH_MSG_OSD_GETMAP) {} + MOSDGetMap(ceph_fsid& f, epoch_t s=0, epoch_t w=0) : Message(CEPH_MSG_OSD_GETMAP), - start(s), want(w) { } + fsid(f), start(s), want(w) { } epoch_t get_start_epoch() { return start; } epoch_t get_want_epoch() { return want; } diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 9b9f7a94dace2..1b7784dff80a3 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -193,6 +193,12 @@ void Monitor::lose_election(epoch_t epoch, int l) void Monitor::handle_command(MMonCommand *m) { + if (!ceph_fsid_equal(&m->fsid, &monmap->fsid)) { + dout(0) << "handle_command on fsid " << m->fsid << " != " << monmap->fsid << dendl; + reply_command(m, -EPERM, "wrong fsid"); + return; + } + dout(0) << "handle_command " << *m << dendl; string rs; if (!m->cmd.empty()) { diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 295757fc36b24..4e4018c36f0fb 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -344,6 +344,11 @@ void OSDMonitor::handle_osd_getmap(MOSDGetMap *m) { dout(7) << "handle_osd_getmap from " << m->get_source() << " from " << m->get_start_epoch() << dendl; + if (!ceph_fsid_equal(&m->fsid, &mon->monmap->fsid)) { + dout(0) << "handle_osd_getmap on fsid " << m->fsid << " != " << mon->monmap->fsid << dendl; + delete m; + } + if (m->get_start_epoch()) { if (m->get_want_epoch() <= osdmap.get_epoch()) send_incremental(m->get_source_inst(), m->get_start_epoch()); @@ -365,6 +370,12 @@ void OSDMonitor::handle_osd_getmap(MOSDGetMap *m) bool OSDMonitor::preprocess_failure(MOSDFailure *m) { + if (!ceph_fsid_equal(&m->fsid, &mon->monmap->fsid)) { + dout(0) << "preprocess_failure on fsid " << m->fsid << " != " << mon->monmap->fsid << dendl; + delete m; + return true; + } + /* * FIXME * this whole thing needs a rework of some sort. we shouldn't @@ -394,6 +405,7 @@ bool OSDMonitor::preprocess_failure(MOSDFailure *m) dout(5) << "preprocess_failure dne(/dup?): " << m->get_failed() << ", from " << m->get_from() << dendl; if (m->get_epoch() < osdmap.get_epoch()) send_incremental(m->get_from(), m->get_epoch()+1); + delete m; return true; } if (osdmap.get_inst(badboy) != m->get_failed()) { @@ -401,6 +413,7 @@ bool OSDMonitor::preprocess_failure(MOSDFailure *m) << ", from " << m->get_from() << dendl; if (m->get_epoch() < osdmap.get_epoch()) send_incremental(m->get_from(), m->get_epoch()+1); + delete m; return true; } // already reported? @@ -408,6 +421,7 @@ bool OSDMonitor::preprocess_failure(MOSDFailure *m) dout(5) << "preprocess_failure dup: " << m->get_failed() << ", from " << m->get_from() << dendl; if (m->get_epoch() < osdmap.get_epoch()) send_incremental(m->get_from(), m->get_epoch()+1); + delete m; return true; } @@ -446,6 +460,12 @@ void OSDMonitor::_reported_failure(MOSDFailure *m) bool OSDMonitor::preprocess_boot(MOSDBoot *m) { + if (!ceph_fsid_equal(&m->sb.fsid, &mon->monmap->fsid)) { + dout(0) << "preprocess_boot on fsid " << m->sb.fsid << " != " << mon->monmap->fsid << dendl; + delete m; + return true; + } + assert(m->inst.name.is_osd()); int from = m->inst.name.num(); diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index bbbb92b10a3a9..255edd1e37e4b 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -883,7 +883,7 @@ void OSD::heartbeat() dout(0) << "no heartbeat from osd" << *p << " since " << heartbeat_from_stamp[*p] << " (cutoff " << grace << ")" << dendl; int mon = monmap->pick_mon(); - messenger->send_message(new MOSDFailure(messenger->get_myinst(), osdmap->get_inst(*p), osdmap->get_epoch()), + messenger->send_message(new MOSDFailure(monmap->fsid, messenger->get_myinst(), osdmap->get_inst(*p), osdmap->get_epoch()), monmap->get_inst(mon)); } } else @@ -1165,7 +1165,8 @@ void OSD::ms_handle_failure(Message *m, const entity_inst_t& inst) << ", dropping and reporting to mon" << mon << " " << *m << dendl; - messenger->send_message(new MOSDFailure(messenger->get_myinst(), inst, osdmap->get_epoch()), + messenger->send_message(new MOSDFailure(monmap->fsid, messenger->get_myinst(), inst, + osdmap->get_epoch()), monmap->get_inst(mon)); } delete m; @@ -1213,7 +1214,7 @@ void OSD::wait_for_new_map(Message *m) // ask if (waiting_for_osdmap.empty()) { int mon = monmap->pick_mon(); - messenger->send_message(new MOSDGetMap(osdmap->get_epoch()+1), + messenger->send_message(new MOSDGetMap(osdmap->get_fsid(), osdmap->get_epoch()+1), monmap->get_inst(mon)); } @@ -1371,7 +1372,7 @@ void OSD::handle_osd_map(MOSDMap *m) else { dout(10) << "handle_osd_map missing epoch " << cur+1 << dendl; int mon = monmap->pick_mon(); - messenger->send_message(new MOSDGetMap(cur+1), monmap->get_inst(mon)); + messenger->send_message(new MOSDGetMap(monmap->fsid, cur+1), monmap->get_inst(mon)); break; } diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index 90be9b57a394b..3f5bad4c245f8 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -107,7 +107,7 @@ void Objecter::handle_osd_map(MOSDMap *m) else { dout(3) << "handle_osd_map requesting missing epoch " << osdmap->get_epoch()+1 << dendl; int mon = monmap->pick_mon(); - messenger->send_message(new MOSDGetMap(osdmap->get_epoch()+1), + messenger->send_message(new MOSDGetMap(osdmap->get_fsid(), osdmap->get_epoch()+1), monmap->get_inst(mon)); break; } @@ -140,7 +140,7 @@ void Objecter::maybe_request_map() dout(10) << "maybe_request_map requesting next osd map" << dendl; last_epoch_requested_stamp = now; last_epoch_requested = osdmap->get_epoch()+1; - messenger->send_message(new MOSDGetMap(osdmap->get_epoch(), last_epoch_requested), + messenger->send_message(new MOSDGetMap(osdmap->get_fsid(), osdmap->get_epoch(), last_epoch_requested), monmap->get_inst(monmap->pick_mon())); } @@ -999,7 +999,8 @@ void Objecter::ms_handle_failure(Message *m, entity_name_t dest, const entity_in dout(0) << "ms_handle_failure " << dest << " inst " << inst << ", dropping, reporting to mon" << mon << dendl; - messenger->send_message(new MOSDFailure(messenger->get_myinst(), inst, osdmap->get_epoch()), + messenger->send_message(new MOSDFailure(monmap->fsid, messenger->get_myinst(), inst, + osdmap->get_epoch()), monmap->get_inst(mon)); } delete m; -- 2.39.5