Skip to content

Commit 04a419f

Browse files
committed
ceph: add feature bits to connection handshake (protocol change)
Define supported and required feature set. Fail connection if the server requires features we do not support (TAG_FEATURES), or if the server does not support features we require. Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 6df058c commit 04a419f

4 files changed

Lines changed: 53 additions & 17 deletions

File tree

‎fs/ceph/ceph_fs.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
#define CEPH_MAX_MON 31
5151

5252

53+
/*
54+
* feature bits
55+
*/
56+
#define CEPH_FEATURE_SUPPORTED 0
57+
#define CEPH_FEATURE_REQUIRED 0
58+
5359

5460
/*
5561
* ceph_file_layout - describe data layout for a file/inode

‎fs/ceph/dir.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,9 @@ void ceph_dentry_lru_add(struct dentry *dn)
11351135
{
11361136
struct ceph_dentry_info *di = ceph_dentry(dn);
11371137
struct ceph_mds_client *mdsc;
1138-
dout("dentry_lru_add %p %p\t%.*s\n",
1139-
di, dn, dn->d_name.len, dn->d_name.name);
11401138

1139+
dout("dentry_lru_add %p %p '%.*s'\n", di, dn,
1140+
dn->d_name.len, dn->d_name.name);
11411141
if (di) {
11421142
mdsc = &ceph_client(dn->d_sb)->mdsc;
11431143
spin_lock(&mdsc->dentry_lru_lock);
@@ -1151,9 +1151,9 @@ void ceph_dentry_lru_touch(struct dentry *dn)
11511151
{
11521152
struct ceph_dentry_info *di = ceph_dentry(dn);
11531153
struct ceph_mds_client *mdsc;
1154-
dout("dentry_lru_touch %p %p\t%.*s\n",
1155-
di, dn, dn->d_name.len, dn->d_name.name);
11561154

1155+
dout("dentry_lru_touch %p %p '%.*s'\n", di, dn,
1156+
dn->d_name.len, dn->d_name.name);
11571157
if (di) {
11581158
mdsc = &ceph_client(dn->d_sb)->mdsc;
11591159
spin_lock(&mdsc->dentry_lru_lock);
@@ -1167,8 +1167,8 @@ void ceph_dentry_lru_del(struct dentry *dn)
11671167
struct ceph_dentry_info *di = ceph_dentry(dn);
11681168
struct ceph_mds_client *mdsc;
11691169

1170-
dout("dentry_lru_del %p %p\t%.*s\n",
1171-
di, dn, dn->d_name.len, dn->d_name.name);
1170+
dout("dentry_lru_del %p %p '%.*s'\n", di, dn,
1171+
dn->d_name.len, dn->d_name.name);
11721172
if (di) {
11731173
mdsc = &ceph_client(dn->d_sb)->mdsc;
11741174
spin_lock(&mdsc->dentry_lru_lock);

‎fs/ceph/messenger.c‎

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ static void prepare_write_connect(struct ceph_messenger *msgr,
631631
dout("prepare_write_connect %p cseq=%d gseq=%d proto=%d\n", con,
632632
con->connect_seq, global_seq, proto);
633633

634+
con->out_connect.features = CEPH_FEATURE_SUPPORTED;
634635
con->out_connect.host_type = cpu_to_le32(CEPH_ENTITY_TYPE_CLIENT);
635636
con->out_connect.connect_seq = cpu_to_le32(con->connect_seq);
636637
con->out_connect.global_seq = cpu_to_le32(global_seq);
@@ -1080,29 +1081,45 @@ static int process_banner(struct ceph_connection *con)
10801081
return 0;
10811082
}
10821083

1084+
static void fail_protocol(struct ceph_connection *con)
1085+
{
1086+
reset_connection(con);
1087+
set_bit(CLOSED, &con->state); /* in case there's queued work */
1088+
1089+
mutex_unlock(&con->mutex);
1090+
if (con->ops->bad_proto)
1091+
con->ops->bad_proto(con);
1092+
mutex_lock(&con->mutex);
1093+
}
1094+
10831095
static int process_connect(struct ceph_connection *con)
10841096
{
1097+
u64 sup_feat = CEPH_FEATURE_SUPPORTED;
1098+
u64 req_feat = CEPH_FEATURE_REQUIRED;
1099+
u64 server_feat = le64_to_cpu(con->in_reply.features);
1100+
10851101
dout("process_connect on %p tag %d\n", con, (int)con->in_tag);
10861102

10871103
switch (con->in_reply.tag) {
1104+
case CEPH_MSGR_TAG_FEATURES:
1105+
pr_err("%s%lld %s feature set mismatch,"
1106+
" my %llx < server's %llx, missing %llx\n",
1107+
ENTITY_NAME(con->peer_name),
1108+
pr_addr(&con->peer_addr.in_addr),
1109+
sup_feat, server_feat, server_feat & ~sup_feat);
1110+
con->error_msg = "missing required protocol features";
1111+
fail_protocol(con);
1112+
return -1;
1113+
10881114
case CEPH_MSGR_TAG_BADPROTOVER:
1089-
dout("process_connect got BADPROTOVER my %d != their %d\n",
1090-
le32_to_cpu(con->out_connect.protocol_version),
1091-
le32_to_cpu(con->in_reply.protocol_version));
10921115
pr_err("%s%lld %s protocol version mismatch,"
10931116
" my %d != server's %d\n",
10941117
ENTITY_NAME(con->peer_name),
10951118
pr_addr(&con->peer_addr.in_addr),
10961119
le32_to_cpu(con->out_connect.protocol_version),
10971120
le32_to_cpu(con->in_reply.protocol_version));
10981121
con->error_msg = "protocol version mismatch";
1099-
reset_connection(con);
1100-
set_bit(CLOSED, &con->state); /* in case there's queued work */
1101-
1102-
mutex_unlock(&con->mutex);
1103-
if (con->ops->bad_proto)
1104-
con->ops->bad_proto(con);
1105-
mutex_lock(&con->mutex);
1122+
fail_protocol(con);
11061123
return -1;
11071124

11081125
case CEPH_MSGR_TAG_BADAUTHORIZER:
@@ -1173,6 +1190,16 @@ static int process_connect(struct ceph_connection *con)
11731190
break;
11741191

11751192
case CEPH_MSGR_TAG_READY:
1193+
if (req_feat & ~server_feat) {
1194+
pr_err("%s%lld %s protocol feature mismatch,"
1195+
" my required %llx > server's %llx, need %llx\n",
1196+
ENTITY_NAME(con->peer_name),
1197+
pr_addr(&con->peer_addr.in_addr),
1198+
req_feat, server_feat, req_feat & ~server_feat);
1199+
con->error_msg = "missing required protocol features";
1200+
fail_protocol(con);
1201+
return -1;
1202+
}
11761203
clear_bit(CONNECTING, &con->state);
11771204
con->peer_global_seq = le32_to_cpu(con->in_reply.global_seq);
11781205
con->connect_seq++;

‎fs/ceph/msgr.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* whenever the wire protocol changes. try to keep this string length
2222
* constant.
2323
*/
24-
#define CEPH_BANNER "ceph v025"
24+
#define CEPH_BANNER "ceph v026"
2525
#define CEPH_BANNER_MAX_LEN 30
2626

2727

@@ -100,12 +100,14 @@ struct ceph_entity_inst {
100100
#define CEPH_MSGR_TAG_KEEPALIVE 9 /* just a keepalive byte! */
101101
#define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */
102102
#define CEPH_MSGR_TAG_BADAUTHORIZER 11 /* bad authorizer */
103+
#define CEPH_MSGR_TAG_FEATURES 12 /* insufficient features */
103104

104105

105106
/*
106107
* connection negotiation
107108
*/
108109
struct ceph_msg_connect {
110+
__le64 features; /* supported feature bits */
109111
__le32 host_type; /* CEPH_ENTITY_TYPE_* */
110112
__le32 global_seq; /* count connections initiated by this host */
111113
__le32 connect_seq; /* count connections initiated in this session */
@@ -117,6 +119,7 @@ struct ceph_msg_connect {
117119

118120
struct ceph_msg_connect_reply {
119121
__u8 tag;
122+
__le64 features; /* feature bits for this session */
120123
__le32 global_seq;
121124
__le32 connect_seq;
122125
__le32 protocol_version;

0 commit comments

Comments
 (0)