[sheepdog] [PATCH v2 1/2] sheep: don't send vdi_inuse in get_vdis

levin li levin108 at gmail.com
Fri Aug 24 07:36:46 CEST 2012


From: levin li <xingke.lwp at taobao.com>

Since we already send vdi copy list in get_vdis(), there's no
need to send the vdi_inuse bitmap any more, without it we can
send less data as the length of vdi copy list is variable and
it contains the vid just as vdi_inuse does.

Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 include/internal_proto.h |    1 +
 sheep/group.c            |   37 ++++++++++++++++---------------------
 sheep/ops.c              |   15 +++++++++++++++
 sheep/sheep_priv.h       |    1 +
 sheep/vdi.c              |    2 +-
 5 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/include/internal_proto.h b/include/internal_proto.h
index 83d98f1..4fe98e5 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -63,6 +63,7 @@
 #define SD_OP_ENABLE_RECOVER 0xA8
 #define SD_OP_DISABLE_RECOVER 0xA9
 #define SD_OP_INFO_RECOVER 0xAA
+#define SD_OP_GET_VDI_LIST 0xAB
 
 /* internal flags for hdr.flags, must be above 0x80 */
 #define SD_FLAG_CMD_RECOVERY 0x0080
diff --git a/sheep/group.c b/sheep/group.c
index bcbd152..5e56d1b 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -618,21 +618,12 @@ static int get_vdis_from(struct sd_node *node)
 {
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-	struct vdi_copy *vc;
-	static DECLARE_BITMAP(tmp_vdi_inuse, SD_NR_VDIS);
+	struct vdi_copy *vc = NULL;
 	int fd, i, ret = SD_RES_SUCCESS;
-	unsigned int rlen = SD_NR_VDIS * 3, wlen;
+	unsigned int rlen = SD_NR_VDIS, wlen;
 	char host[128];
-	char *buf = NULL;
 	int count;
 
-	buf = zalloc(rlen);
-	if (!buf) {
-		vprintf(SDOG_ERR, "unable to allocate memory\n");
-		ret = SD_RES_NO_MEM;
-		goto out;
-	}
-
 	if (is_myself(node->nid.addr, node->nid.port))
 		goto out;
 
@@ -652,7 +643,14 @@ static int get_vdis_from(struct sd_node *node)
 	hdr.data_length = rlen;
 	wlen = 0;
 
-	ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
+	vc = zalloc(rlen);
+	if (!vc) {
+		vprintf(SDOG_ERR, "unable to allocate memory\n");
+		ret = SD_RES_NO_MEM;
+		goto out;
+	}
+
+	ret = exec_req(fd, &hdr, (char *)vc, &wlen, &rlen);
 	close(fd);
 
 	if (ret || rsp->result != SD_RES_SUCCESS) {
@@ -661,16 +659,13 @@ static int get_vdis_from(struct sd_node *node)
 		goto out;
 	}
 
-	memcpy(tmp_vdi_inuse, buf, sizeof(tmp_vdi_inuse));
-	for (i = 0; i < ARRAY_SIZE(sys->vdi_inuse); i++)
-		sys->vdi_inuse[i] |= tmp_vdi_inuse[i];
-
-	count = (rsp->data_length - sizeof(tmp_vdi_inuse)) / sizeof(*vc);
-	vc = (struct vdi_copy *)(buf + sizeof(tmp_vdi_inuse));
-	for (i = 0; i < count; i++, vc++)
-		add_vdi_copy_number(vc->vid, vc->nr_copies);
+	count = rsp->data_length / sizeof(*vc);
+	for (i = 0; i < count; i++) {
+		set_bit(vc[i].vid, sys->vdi_inuse);
+		add_vdi_copy_number(vc[i].vid, vc[i].nr_copies);
+	}
 out:
-	free(buf);
+	free(vc);
 	return ret;
 }
 
diff --git a/sheep/ops.c b/sheep/ops.c
index aaa4ed6..ea62f39 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -370,6 +370,14 @@ static int local_read_vdis(const struct sd_req *req, struct sd_rsp *rsp,
 	return read_vdis(data, req->data_length, &rsp->data_length);
 }
 
+static int local_get_vdi_list(const struct sd_req *req, struct sd_rsp *rsp,
+			   void *data)
+{
+	rsp->data_length = fill_vdi_copy_list(data);
+
+	return SD_RES_SUCCESS;
+}
+
 static int local_stat_sheep(struct request *req)
 {
 	struct sd_node_rsp *node_rsp = (struct sd_node_rsp *)&req->rp;
@@ -953,6 +961,13 @@ static struct sd_op_template sd_ops[] = {
 		.process_main = local_read_vdis,
 	},
 
+	[SD_OP_GET_VDI_LIST] = {
+		.name = "GET_VDI_LIST",
+		.type = SD_OP_TYPE_LOCAL,
+		.force = 1,
+		.process_main = local_get_vdi_list,
+	},
+
 	[SD_OP_GET_NODE_LIST] = {
 		.name = "GET_NODE_LIST",
 		.type = SD_OP_TYPE_LOCAL,
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 4a2ca8a..84c4164 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -205,6 +205,7 @@ int create_listen_port(int port, void *data);
 int init_store(const char *dir, int enable_write_cache);
 int init_base_path(const char *dir);
 
+int fill_vdi_copy_list(void *data);
 int get_vdi_copy_number(uint32_t vid);
 int get_obj_copy_number(uint64_t oid);
 int get_max_copy_number(void);
diff --git a/sheep/vdi.c b/sheep/vdi.c
index aa5134b..b18f40c 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -139,7 +139,7 @@ int add_vdi_copy_number(uint32_t vid, int nr_copies)
 	return SD_RES_SUCCESS;
 }
 
-static int fill_vdi_copy_list(void *data)
+int fill_vdi_copy_list(void *data)
 {
 	int nr = 0;
 	struct rb_node *n;
-- 
1.7.1




More information about the sheepdog mailing list