From d06992d70fe7facee37713f40ee97e2badd8b17c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 22 Dec 2009 11:42:29 -0800 Subject: [PATCH] msgr: include features in connection handshake (protocol change) --- src/include/ceph_fs.h | 6 ++++++ src/include/msgr.h | 5 ++++- src/msg/SimpleMessenger.cc | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index e87dfa6ec8e52..db3fed33c4aac 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -50,6 +50,12 @@ #define CEPH_MAX_MON 31 +/* + * feature bits + */ +#define CEPH_FEATURE_SUPPORTED 0 +#define CEPH_FEATURE_REQUIRED 0 + /* * ceph_file_layout - describe data layout for a file/inode diff --git a/src/include/msgr.h b/src/include/msgr.h index e46d8b806dea7..be83f93182ee8 100644 --- a/src/include/msgr.h +++ b/src/include/msgr.h @@ -21,7 +21,7 @@ * whenever the wire protocol changes. try to keep this string length * constant. */ -#define CEPH_BANNER "ceph v025" +#define CEPH_BANNER "ceph v026" #define CEPH_BANNER_MAX_LEN 30 @@ -100,12 +100,14 @@ struct ceph_entity_inst { #define CEPH_MSGR_TAG_KEEPALIVE 9 /* just a keepalive byte! */ #define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */ #define CEPH_MSGR_TAG_BADAUTHORIZER 11 /* bad authorizer */ +#define CEPH_MSGR_TAG_FEATURES 12 /* insufficient features */ /* * connection negotiation */ struct ceph_msg_connect { + __le64 features; /* supported feature bits */ __le32 host_type; /* CEPH_ENTITY_TYPE_* */ __le32 global_seq; /* count connections initiated by this host */ __le32 connect_seq; /* count connections initiated in this session */ @@ -117,6 +119,7 @@ struct ceph_msg_connect { struct ceph_msg_connect_reply { __u8 tag; + __le64 features; /* feature bits for this session */ __le32 global_seq; __le32 connect_seq; __le32 protocol_version; diff --git a/src/msg/SimpleMessenger.cc b/src/msg/SimpleMessenger.cc index fef87a8d54afa..f07df1492b094 100644 --- a/src/msg/SimpleMessenger.cc +++ b/src/msg/SimpleMessenger.cc @@ -608,6 +608,7 @@ int SimpleMessenger::Pipe::accept() bufferptr bp; bufferlist authorizer, authorizer_reply; bool authorizer_valid; + __u64 feat_missing; // this should roughly mirror pseudocode at // http://ceph.newdream.net/wiki/Messaging_protocol @@ -655,6 +656,14 @@ int SimpleMessenger::Pipe::accept() rank->lock.Unlock(); goto reply; } + + feat_missing = CEPH_FEATURE_REQUIRED & ~(__u64)connect.features; + if (feat_missing) { + dout(1) << "peer missing required features " << std::hex << feat_missing << std::dec << dendl; + reply.tag = CEPH_MSGR_TAG_FEATURES; + rank->lock.Unlock(); + goto reply; + } if (rank->verify_authorizer(connection_state, peer_type, connect.authorizer_protocol, authorizer, authorizer_reply, authorizer_valid) && @@ -779,6 +788,7 @@ int SimpleMessenger::Pipe::accept() assert(0); reply: + reply.features = ((__u64)connect.features & CEPH_FEATURE_SUPPORTED) | CEPH_FEATURE_REQUIRED; reply.authorizer_len = authorizer_reply.length(); rc = tcp_write(sd, (char*)&reply, sizeof(reply)); if (rc < 0) @@ -995,6 +1005,7 @@ int SimpleMessenger::Pipe::connect() bufferlist authorizer_reply; ceph_msg_connect connect; + connect.features = CEPH_FEATURE_SUPPORTED; connect.host_type = rank->my_type; connect.global_seq = gseq; connect.connect_seq = cseq; @@ -1066,6 +1077,14 @@ int SimpleMessenger::Pipe::connect() goto stop_locked; } + if (reply.tag == CEPH_MSGR_TAG_FEATURES) { + dout(0) << "connect protocol feature mismatch, my " << std::hex + << connect.features << " < peer " << reply.features + << " missing " << (reply.features & ~CEPH_FEATURE_SUPPORTED) + << std::dec << dendl; + goto fail_locked; + } + if (reply.tag == CEPH_MSGR_TAG_BADPROTOVER) { dout(0) << "connect protocol version mismatch, my " << connect.protocol_version << " != " << reply.protocol_version << dendl; @@ -1111,6 +1130,12 @@ int SimpleMessenger::Pipe::connect() } if (reply.tag == CEPH_MSGR_TAG_READY) { + __u64 feat_missing = CEPH_FEATURE_REQUIRED & ~(__u64)reply.features; + if (feat_missing) { + dout(1) << "missing required features " << std::hex << feat_missing << std::dec << dendl; + goto fail_locked; + } + // hooray! peer_global_seq = reply.global_seq; policy.lossy = reply.flags & CEPH_MSG_CONNECT_LOSSY; -- 2.39.5