From fccde5c4cdab69c09e1bc7135d80c4132be1d3f8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 4 Dec 2008 14:58:58 -0800 Subject: [PATCH] set/check subprotocol versions --- src/include/ceph_fs.h | 26 +++++++++++++++++--------- src/kernel/messenger.c | 9 ++++++--- src/mds/MDS.cc | 31 +++++++++++++++++++++++++++++++ src/mon/Monitor.cc | 15 +++++++++++++++ src/msg/SimpleMessenger.cc | 7 +++++++ src/osd/OSD.cc | 24 ++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 12 deletions(-) diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index 2bdb2899a4549..004f1adb357a1 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -27,12 +27,16 @@ /* * subprotocol versions. when specific messages types or high-level - * protocols change, bump the affected components. + * protocols change, bump the affected components. we keep rev + * internal cluster protocols separately from the public, + * client-facing protocol. */ -#define CEPH_OSD_PROTOCOL 3 -#define CEPH_MDS_PROTOCOL 2 -#define CEPH_MON_PROTOCOL 2 -#define CEPH_CLIENT_PROTOCOL 1 +#define CEPH_OSD_PROTOCOL 3 /* cluster internal */ +#define CEPH_MDS_PROTOCOL 2 /* cluster internal */ +#define CEPH_MON_PROTOCOL 2 /* cluster internal */ +#define CEPH_OSDC_PROTOCOL 3 /* public/client */ +#define CEPH_MDSC_PROTOCOL 2 /* public/client */ +#define CEPH_MONC_PROTOCOL 2 /* public/client */ /* @@ -458,12 +462,16 @@ struct ceph_msg_header { __le64 seq; /* message seq# for this session */ __le16 type; /* message type */ __le16 priority; /* priority. higher value == higher priority */ - __le16 mon_protocol, osd_protocol, mds_protocol, - client_protocol; /* protocol versions */ + __le32 front_len; /* bytes in main payload */ - __le32 data_off; /* sender: include full offset; - receiver: mask against ~PAGE_MASK */ __le32 data_len; /* bytes of data payload */ + __le16 data_off; /* sender: include full offset; + receiver: mask against ~PAGE_MASK */ + + __u8 mon_protocol, monc_protocol; /* protocol versions, */ + __u8 osd_protocol, osdc_protocol; /* internal and public */ + __u8 mds_protocol, mdsc_protocol; + struct ceph_entity_inst src, orig_src, dst; __le32 crc; /* header crc32c */ } __attribute__ ((packed)); diff --git a/src/kernel/messenger.c b/src/kernel/messenger.c index 0bfa440637074..fa7d6417f5733 100644 --- a/src/kernel/messenger.c +++ b/src/kernel/messenger.c @@ -2297,9 +2297,12 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, m->hdr.data_len = cpu_to_le32(page_len); m->hdr.data_off = cpu_to_le32(page_off); m->hdr.priority = 0; - m->hdr.mon_protocol = 0; - m->hdr.osd_protocol = 0; - m->hdr.mds_protocol = 0; + m->hdr.mon_protocol = CEPH_MON_PROTOCOL; + m->hdr.monc_protocol = CEPH_MONC_PROTOCOL; + m->hdr.osd_protocol = CEPH_OSD_PROTOCOL; + m->hdr.osdc_protocol = CEPH_OSDC_PROTOCOL; + m->hdr.mds_protocol = CEPH_MDS_PROTOCOL; + m->hdr.mdsc_protocol = CEPH_MDSC_PROTOCOL; m->footer.front_crc = 0; m->footer.data_crc = 0; m->front_is_vmalloc = false; diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index e976fed12ad5d..020345e5fae88 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -1100,6 +1100,37 @@ void MDS::suicide() bool MDS::dispatch_impl(Message *m) { bool ret; + + // verify protocol version + if (m->get_orig_source().is_mds() && + m->get_header().mds_protocol != CEPH_MDS_PROTOCOL) { + dout(0) << "mds protocol v " << (int)m->get_header().mds_protocol << " != my " << CEPH_MDS_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + + if (m->get_header().mdsc_protocol != CEPH_MDSC_PROTOCOL) { + dout(0) << "mdsc protocol v " << (int)m->get_header().mdsc_protocol << " != my " << CEPH_MDSC_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + if (m->get_orig_source().is_mon() && + m->get_header().monc_protocol != CEPH_MONC_PROTOCOL) { + dout(0) << "monc protocol v " << (int)m->get_header().monc_protocol << " != my " << CEPH_MONC_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + if (m->get_orig_source().is_osd() && + m->get_header().osdc_protocol != CEPH_OSDC_PROTOCOL) { + dout(0) << "osdc protocol v " << (int)m->get_header().osdc_protocol << " != my " << CEPH_OSDC_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + mds_lock.Lock(); ret = _dispatch(m); mds_lock.Unlock(); diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 4ec1bf63be133..85b289ba1e272 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -303,6 +303,21 @@ void Monitor::stop_cluster() bool Monitor::dispatch_impl(Message *m) { + // verify protocol version + if (m->get_orig_source().is_mon() && + m->get_header().mon_protocol != CEPH_MON_PROTOCOL) { + dout(0) << "mon protocol v " << (int)m->get_header().mon_protocol << " != my " << CEPH_MON_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + if (m->get_header().monc_protocol != CEPH_MONC_PROTOCOL) { + dout(0) << "monc protocol v " << (int)m->get_header().monc_protocol << " != my " << CEPH_MONC_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + lock.Lock(); { switch (m->get_type()) { diff --git a/src/msg/SimpleMessenger.cc b/src/msg/SimpleMessenger.cc index 3e90fa4072c2c..97f9b5a27f476 100644 --- a/src/msg/SimpleMessenger.cc +++ b/src/msg/SimpleMessenger.cc @@ -451,6 +451,13 @@ void Rank::submit_message(Message *m, const entity_addr_t& dest_addr, bool lazy) assert(m->nref.test() == 0); + m->get_header().mon_protocol = CEPH_MON_PROTOCOL; + m->get_header().monc_protocol = CEPH_MONC_PROTOCOL; + m->get_header().mds_protocol = CEPH_MDS_PROTOCOL; + m->get_header().mdsc_protocol = CEPH_MDSC_PROTOCOL; + m->get_header().osd_protocol = CEPH_OSD_PROTOCOL; + m->get_header().osdc_protocol = CEPH_OSDC_PROTOCOL; + // lookup entity_addr_t dest_proc_addr = dest_addr; dest_proc_addr.erank = 0; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 094f02a6dc734..db8faa5a998fa 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1454,6 +1454,30 @@ bool OSD::heartbeat_dispatch(Message *m) bool OSD::dispatch_impl(Message *m) { + // verify protocol version + if (m->get_orig_source().is_osd() && + m->get_header().osd_protocol != CEPH_OSD_PROTOCOL) { + dout(0) << "osd protocol v " << (int)m->get_header().osd_protocol << " != my " << CEPH_OSD_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + + if (m->get_header().osdc_protocol != CEPH_OSDC_PROTOCOL) { + dout(0) << "osdc protocol v " << (int)m->get_header().osdc_protocol << " != my " << CEPH_OSDC_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + if (m->get_orig_source().is_mon() && + m->get_header().monc_protocol != CEPH_MONC_PROTOCOL) { + dout(0) << "monc protocol v " << (int)m->get_header().monc_protocol << " != my " << CEPH_MONC_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + + // lock! osd_lock.Lock(); dout(20) << "dispatch " << m << dendl; -- 2.39.5