From: Sage Weil Date: Wed, 14 Apr 2010 22:18:52 +0000 (-0700) Subject: osd: fix source type checks (osd, mon) X-Git-Tag: v0.20~53 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=198d7106818e91c655740f3a41c2390af36e069e;p=ceph.git osd: fix source type checks (osd, mon) The peer type is on the connection, no need to look at Session. Also, we don't currently have Sessions for outgoing connections. --- diff --git a/src/msg/Message.h b/src/msg/Message.h index a89fbd144399..97bca7172f39 100644 --- a/src/msg/Message.h +++ b/src/msg/Message.h @@ -199,6 +199,11 @@ public: int get_peer_type() { return peer_type; } void set_peer_type(int t) { peer_type = t; } + + bool peer_is_mon() { return peer_type == CEPH_ENTITY_TYPE_MON; } + bool peer_is_mds() { return peer_type == CEPH_ENTITY_TYPE_MDS; } + bool peer_is_osd() { return peer_type == CEPH_ENTITY_TYPE_OSD; } + bool peer_is_client() { return peer_type == CEPH_ENTITY_TYPE_CLIENT; } const entity_addr_t& get_peer_addr() { return peer_addr; } void set_peer_addr(const entity_addr_t& a) { peer_addr = a; } diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index c72024f736bd..1c3ae2d72b17 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1507,12 +1507,9 @@ void OSD::send_pg_stats() void OSD::handle_pg_stats_ack(MPGStatsAck *ack) { dout(10) << "handle_pg_stats_ack " << dendl; - if (!message_from_mon(ack)) { - dout(0) << "handle_pg_stats_ack received from non-osd connection " - << ack->get_connection() << dendl; - delete ack; + + if (!require_mon_peer(ack)) return; - } pg_stat_queue_lock.Lock(); @@ -1549,12 +1546,9 @@ void OSD::handle_pg_stats_ack(MPGStatsAck *ack) void OSD::handle_command(MMonCommand *m) { - if (!message_from_mon(m)) { - dout(0) << "handle_command received from non-mon connection " - << m->get_connection() << dendl; - delete m; + if (!require_mon_peer(m)) return; - } + dout(20) << "handle_command args: " << m->cmd << dendl; if (m->cmd[0] == "injectargs") parse_config_option_string(m->cmd[1]); @@ -1866,12 +1860,8 @@ void OSD::_dispatch(Message *m) void OSD::handle_scrub(MOSDScrub *m) { dout(10) << "handle_scrub " << *m << dendl; - if (!message_from_mon(m)) { - dout(0) << "handle_scrub received from non-mon connection " - << m->get_connection() << dendl; - delete m; + if (!require_mon_peer(m)) return; - } if (ceph_fsid_compare(&m->fsid, &monc->get_fsid())) { dout(0) << "handle_scrub fsid " << m->fsid << " != " << monc->get_fsid() << dendl; delete m; @@ -2664,7 +2654,27 @@ bool OSD::get_inc_map(epoch_t e, OSDMap::Incremental &inc) +bool OSD::require_mon_peer(Message *m) +{ + if (!m->get_connection()->peer_is_mon()) { + dout(0) << "require_mon_peer received from non-mon " << m->get_connection()->get_peer_addr() + << " " << *m << dendl; + delete m; + return false; + } + return true; +} +bool OSD::require_osd_peer(Message *m) +{ + if (!m->get_connection()->peer_is_osd()) { + dout(0) << "require_osd_peer received from non-osd " << m->get_connection()->get_peer_addr() + << " " << *m << dendl; + delete m; + return false; + } + return true; +} bool OSD::require_current_map(Message *m, epoch_t ep) { @@ -2944,12 +2954,9 @@ void OSD::split_pg(PG *parent, map& children, ObjectStore::Transaction void OSD::handle_pg_create(MOSDPGCreate *m) { dout(10) << "handle_pg_create " << *m << dendl; - if (!message_from_mon(m)) { - dout(0) << "handle_pg_create received from non-mon connection " - << m->get_connection() << dendl; - delete m; + if (!require_mon_peer(m)) return; - } + if (!require_same_or_newer_map(m, m->epoch)) return; map< int, map > query_map; @@ -3115,15 +3122,10 @@ void OSD::handle_pg_notify(MOSDPGNotify *m) { dout(7) << "handle_pg_notify from " << m->get_source() << dendl; int from = m->get_source().num(); - Session *session = (Session *)m->get_connection()->get_priv(); - if (!session || !session->caps.is_osd()) { - dout(0) << "handle_pg_notify received from non-osd connection " - << m->get_connection() << dendl; - delete m; - session->put(); + + if (!require_osd_peer(m)) return; - } - session->put(); + if (!require_same_or_newer_map(m, m->get_epoch())) return; // look for unknown PGs i'm primary for @@ -3354,15 +3356,8 @@ void OSD::handle_pg_log(MOSDPGLog *m) { dout(7) << "handle_pg_log " << *m << " from " << m->get_source() << dendl; - Session *session = (Session *)m->get_connection()->get_priv(); - if (!session || !session->caps.is_osd()) { - dout(0) << "handle_scrub received from non-osd connection " - << m->get_connection() << dendl; - delete m; - session->put(); + if (!require_osd_peer(m)) return; - } - session->put(); int from = m->get_source().num(); int created = 0; @@ -3380,15 +3375,9 @@ void OSD::handle_pg_log(MOSDPGLog *m) void OSD::handle_pg_info(MOSDPGInfo *m) { dout(7) << "handle_pg_info " << *m << " from " << m->get_source() << dendl; - Session *session = (Session *)m->get_connection()->get_priv(); - if (!session || !session->caps.is_osd()) { - dout(0) << "handle_scrub received from non-osd connection " - << m->get_connection() << dendl; - delete m; - session->put(); + + if (!require_osd_peer(m)) return; - } - session->put(); int from = m->get_source().num(); if (!require_same_or_newer_map(m, m->get_epoch())) return; @@ -3414,15 +3403,8 @@ void OSD::handle_pg_trim(MOSDPGTrim *m) { dout(7) << "handle_pg_trim " << *m << " from " << m->get_source() << dendl; - Session *session = (Session *)m->get_connection()->get_priv(); - if (!session || !session->caps.is_osd()) { - dout(0) << "handle_scrub received from non-osd connection " - << m->get_connection() << dendl; - delete m; - session->put(); + if (!require_osd_peer(m)) return; - } - session->put(); int from = m->get_source().num(); if (!require_same_or_newer_map(m, m->epoch)) return; @@ -3469,15 +3451,9 @@ void OSD::handle_pg_trim(MOSDPGTrim *m) void OSD::handle_pg_query(MOSDPGQuery *m) { assert(osd_lock.is_locked()); - Session *session = (Session *)m->get_connection()->get_priv(); - if (!session || !session->caps.is_osd()) { - dout(0) << "handle_scrub received from non-osd connection " - << m->get_connection() << dendl; - delete m; - session->put(); + + if (!require_osd_peer(m)) return; - } - session->put(); dout(7) << "handle_pg_query from " << m->get_source() << " epoch " << m->get_epoch() << dendl; int from = m->get_source().num(); @@ -3607,15 +3583,9 @@ void OSD::handle_pg_query(MOSDPGQuery *m) void OSD::handle_pg_remove(MOSDPGRemove *m) { assert(osd_lock.is_locked()); - Session *session = (Session *)m->get_connection()->get_priv(); - if (!session || !session->caps.is_osd()) { - dout(0) << "handle_scrub received from non-osd connection " - << m->get_connection() << dendl; - delete m; - session->put(); + + if (!require_osd_peer(m)) return; - } - session->put(); dout(7) << "handle_pg_remove from " << m->get_source() << " on " << m->pg_list.size() << " pgs" << dendl; @@ -4293,15 +4263,8 @@ void OSD::handle_sub_op(MOSDSubOp *op) return; } - Session *session = (Session *)op->get_connection()->get_priv(); - if (!session || !session->caps.is_osd()) { - dout(0) << "handle_scrub received from non-osd connection " - << op->get_connection() << dendl; - delete op; - session->put(); + if (!require_osd_peer(op)) return; - } - session->put(); // must be a rep op. assert(op->get_source().is_osd()); @@ -4352,15 +4315,8 @@ void OSD::handle_sub_op_reply(MOSDSubOpReply *op) return; } - Session *session = (Session *)op->get_connection()->get_priv(); - if (!session || !session->caps.is_osd()) { - dout(0) << "handle_scrub received from non-osd connection " - << op->get_connection() << dendl; - delete op; - session->put(); + if (!require_osd_peer(op)) return; - } - session->put(); // must be a rep op. assert(op->get_source().is_osd()); @@ -4535,12 +4491,9 @@ void OSD::got_class(const nstring& cname) void OSD::handle_class(MClass *m) { - if (!message_from_mon(m)) { - dout(0) << "handle_class received from non-mon connection " - << m->get_connection() << dendl; - delete m; + if (!require_mon_peer(m)) return; - } + Mutex::Locker l(class_lock); dout(0) << "handle_class action=" << m->action << dendl; diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 9d67ded5406b..6f6de45e9558 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -195,14 +195,6 @@ public: }; private: - inline bool message_from_mon(Message *m) { - Session *session = (Session *)m->get_connection()->get_priv(); - if (!session) return true; //this must be an outgoing connection we opened - bool ret = session->caps.is_mon(); - session->put(); - return ret; - } - // -- heartbeat -- Mutex heartbeat_lock; Cond heartbeat_cond; @@ -603,6 +595,9 @@ protected: void do_infos(map& info_map); void repeer(PG *pg, map< int, map >& query_map); + bool require_mon_peer(Message *m); + bool require_osd_peer(Message *m); + bool require_current_map(Message *m, epoch_t v); bool require_same_or_newer_map(Message *m, epoch_t e);