[Sheepdog] [PATCH 3/3] check protocol version
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Mon May 10 00:41:03 CEST 2010
We should avoid wrong version members coming in the cluster.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
collie/group.c | 20 +++++++++++++++-----
include/collie.h | 8 ++++++++
include/sheepdog_proto.h | 3 +++
shepherd/shepherd.c | 1 +
4 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/collie/group.c b/collie/group.c
index c41f918..91b0f4e 100644
--- a/collie/group.c
+++ b/collie/group.c
@@ -43,9 +43,10 @@ enum deliver_msg_state {
};
struct message_header {
+ uint8_t proto_ver;
+ uint8_t pad;
uint8_t op;
uint8_t state;
- uint8_t pad[2];
uint32_t msg_length;
uint32_t nodeid;
uint32_t pid;
@@ -475,6 +476,12 @@ static void join(struct join_message *msg)
struct sheepdog_node_list_entry entry[SD_MAX_NODES];
int i;
+ if (msg->header.proto_ver != SD_COLLIE_PROTO_VER) {
+ eprintf("joining node send a wrong version message\n");
+ msg->result = SD_RES_VER_MISMATCH;
+ return;
+ }
+
if (msg->nr_sobjs)
sys->nr_sobjs = msg->nr_sobjs;
@@ -581,9 +588,8 @@ static void update_cluster_info(struct join_message *msg)
if (is_myself(&msg->header.from)) {
eprintf("failed to join sheepdog, %d\n", msg->result);
sys->status = SD_STATUS_JOIN_FAILED;
- return;
- } else
- return;
+ }
+ return;
}
if (!sys->nr_sobjs)
@@ -656,7 +662,7 @@ out:
sys->epoch = get_latest_epoch();
}
- if (sys->status != SD_STATUS_INCONSISTENT_EPOCHS) {
+ if (sys->status != SD_STATUS_INCONSISTENT_EPOCHS || sys->status != SD_STATUS_JOIN_FAILED) {
if (msg->cluster_status == SD_STATUS_OK) {
get_vdi_bitmap_from_all();
set_global_nr_copies(sys->nr_sobjs);
@@ -690,6 +696,10 @@ static void vdi_op(struct vdi_op_message *msg)
break;
case SD_OP_LOCK_VDI:
case SD_OP_GET_VDI_INFO:
+ if (hdr->proto_ver != SD_PROTO_VER) {
+ ret = SD_RES_VER_MISMATCH;
+ break;
+ }
ret = lookup_vdi(hdr->epoch, data, hdr->data_length, &vid, hdr->snapid);
if (ret != SD_RES_SUCCESS)
break;
diff --git a/include/collie.h b/include/collie.h
index b3c8264..e4019d2 100644
--- a/include/collie.h
+++ b/include/collie.h
@@ -15,9 +15,12 @@
#include "util.h"
#include "list.h"
+#define SD_COLLIE_PROTO_VER 0x01
+
#define SD_MAX_NODES 1024
#define SD_MAX_VMS 4096 /* FIXME: should be removed */
+#define SD_OP_COLLIE 0x80
#define SD_OP_DEL_VDI 0x81
#define SD_OP_GET_NODE_LIST 0x82
#define SD_OP_GET_VM_LIST 0x83
@@ -172,4 +175,9 @@ static inline void print_node_list_entry(struct sheepdog_node_list_entry *e,
e->addr[14], e->addr[15], e->port);
}
+static inline int is_collie_op(uint8_t op)
+{
+ return op & SD_OP_COLLIE;
+}
+
#endif
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 5b77544..19ace97 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -15,6 +15,8 @@
#include <stdint.h>
#include "util.h"
+#define SD_PROTO_VER 0x01
+
#define SD_LISTEN_PORT 7000
#define SD_OP_CREATE_AND_WRITE_OBJ 0x01
@@ -50,6 +52,7 @@
#define SD_RES_SHUTDOWN 0x11 /* Sheepdog is shutting down */
#define SD_RES_NO_MEM 0x12 /* Cannot allocate memory */
#define SD_RES_FULL_VDI 0x13 /* we already have the maximum vdis */
+#define SD_RES_VER_MISMATCH 0x14 /* Protocol version mismatch */
/*
* Object ID rules
diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index cb5d5e3..3b59a61 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -843,6 +843,7 @@ static int vdi_lock(int argc, char **argv)
memset(&hdr, 0, sizeof(hdr));
+ hdr.proto_ver = SD_PROTO_VER; /* version is checked when locking */
hdr.opcode = opcode;
hdr.data_length = wlen;
hdr.flags = flags;
--
1.5.6.5
More information about the sheepdog
mailing list