From: levin li <xingke....@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....@taobao.com>
---
 include/internal_proto.h |    1 +
 sheep/group.c            |   40 ++++++++++++++++++----------------------
 sheep/ops.c              |   15 +++++++++++++++
 sheep/sheep_priv.h       |    1 +
 sheep/vdi.c              |   10 ++++------
 5 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/include/internal_proto.h b/include/internal_proto.h
index 83d98f1..3d70ba9 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_COPIES 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..ea5b9e6 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, 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;
 
@@ -647,12 +638,20 @@ static int get_vdis_from(struct sd_node *node)
 
        vprintf(SDOG_ERR, "%s:%d\n", host, node->nid.port);
 
-       sd_init_req(&hdr, SD_OP_READ_VDIS);
+       rlen = SD_DATA_OBJ_SIZE; /* FIXME */
+       sd_init_req(&hdr, SD_OP_GET_VDI_COPIES);
        hdr.epoch = sys->epoch;
        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 +660,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..0215312 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_copies(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_COPIES] = {
+               .name = "GET_VDI_COPIES",
+               .type = SD_OP_TYPE_LOCAL,
+               .force = 1,
+               .process_main = local_get_vdi_copies,
+       },
+
        [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..7a97c7b 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;
@@ -513,13 +513,11 @@ out:
 
 int read_vdis(char *data, int len, unsigned int *rsp_len)
 {
-       int length;
+       if (len != sizeof(sys->vdi_inuse))
+               return SD_RES_INVALID_PARMS;
 
        memcpy(data, sys->vdi_inuse, sizeof(sys->vdi_inuse));
-       /* put vdi copy list at the end of vdi bitmap */
-       length = fill_vdi_copy_list(data + sizeof(sys->vdi_inuse));
-
-       *rsp_len = sizeof(sys->vdi_inuse) + length;
+       *rsp_len = sizeof(sys->vdi_inuse);
 
        return SD_RES_SUCCESS;
 }
-- 
1.7.1

-- 
sheepdog mailing list
sheepdog@lists.wpkg.org
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to