[sheepdog] [PATCH 1/2] sheep: don't send vdi_inuse in get_vdis
levin li
levin108 at gmail.com
Fri Aug 24 04:56:35 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>
---
sheep/group.c | 37 ++++++++++++++++---------------------
sheep/ops.c | 4 +++-
sheep/sheep_priv.h | 3 +--
sheep/vdi.c | 15 +--------------
4 files changed, 21 insertions(+), 38 deletions(-)
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..84ebdcb 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -367,7 +367,9 @@ static int local_get_store_list(struct request *req)
static int local_read_vdis(const struct sd_req *req, struct sd_rsp *rsp,
void *data)
{
- return read_vdis(data, req->data_length, &rsp->data_length);
+ rsp->data_length = fill_vdi_copy_list(data);
+
+ return SD_RES_SUCCESS;
}
static int local_stat_sheep(struct request *req)
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 4a2ca8a..00d3d19 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);
@@ -219,8 +220,6 @@ int del_vdi(struct request *req, char *data, int data_len, uint32_t *vid,
int lookup_vdi(char *name, char *tag, uint32_t *vid, uint32_t snapid,
unsigned int *nr_copies, uint64_t *ctime);
-int read_vdis(char *data, int len, unsigned int *rsp_len);
-
int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len, uint32_t vid,
uint32_t *attrid, uint64_t ctime, int write,
int excl, int delete);
diff --git a/sheep/vdi.c b/sheep/vdi.c
index aa5134b..aa7a541 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;
@@ -511,19 +511,6 @@ out:
return ret;
}
-int read_vdis(char *data, int len, unsigned int *rsp_len)
-{
- int length;
-
- 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;
-
- return SD_RES_SUCCESS;
-}
-
struct deletion_work {
uint32_t done;
--
1.7.1
More information about the sheepdog
mailing list