[sheepdog] [PATCH v3 2/2] collie: make `collie vdi list` not read vdi_inuse bitmap

levin li levin108 at gmail.com
Fri Aug 24 09:11:38 CEST 2012


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


Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 collie/common.c    |   32 ++++++++++++++++----------------
 include/sheep.h    |    5 +++++
 sheep/sheep_priv.h |    5 -----
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/collie/common.c b/collie/common.c
index 364e36c..ce8dcf7 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -126,16 +126,16 @@ int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data, unsigned int dat
 
 int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
 {
-	int ret, fd;
+	int ret, fd, count;
+	struct vdi_copy *vc;
 	unsigned long nr;
 	static struct sheepdog_inode i;
 	struct sd_req req;
-	static DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
-	unsigned int wlen = 0, rlen = sizeof(vdi_inuse) * 2;
-	char *buf;
+	struct sd_rsp *rsp = (struct sd_rsp *)&req;
+	unsigned int wlen = 0, rlen = SD_DATA_OBJ_SIZE; /* FIXME */
 
-	buf = zalloc(rlen);
-	if (!buf) {
+	vc = zalloc(rlen);
+	if (!vc) {
 		fprintf(stderr, "Failed to allocate memory\n");
 		return -1;
 	}
@@ -143,30 +143,28 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
 	fd = connect_to(sdhost, sdport);
 	if (fd < 0) {
 		fprintf(stderr, "Failed to connect to %s:%d\n", sdhost, sdport);
-		return fd;
+		ret = -1;
+		goto out;
 	}
 
-	sd_init_req(&req, SD_OP_READ_VDIS);
+	sd_init_req(&req, SD_OP_GET_VDI_COPIES);
 	req.data_length = rlen;
 	req.epoch = sd_epoch;
 
-	ret = exec_req(fd, &req, buf, &wlen, &rlen);
+	ret = exec_req(fd, &req, (char *)vc, &wlen, &rlen);
 	if (ret < 0) {
 		fprintf(stderr, "Failed to read VDIs from %s:%d\n",
 			sdhost, sdport);
 		close(fd);
-		return ret;
+		goto out;
 	}
 	close(fd);
 
-	memcpy(&vdi_inuse, buf, sizeof(vdi_inuse));
-	for (nr = 0; nr < SD_NR_VDIS; nr++) {
+	count = rsp->data_length / sizeof(*vc);
+	for (nr = 0; nr < count; nr++) {
 		uint64_t oid;
 
-		if (!test_bit(nr, vdi_inuse))
-			continue;
-
-		oid = vid_to_vdi_oid(nr);
+		oid = vid_to_vdi_oid(vc[nr].vid);
 
 		memset(&i, 0, sizeof(i));
 		ret = sd_read_object(oid, &i, SD_INODE_HEADER_SIZE, 0);
@@ -196,6 +194,8 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
 		func(i.vdi_id, i.name, i.tag, i.snap_id, 0, &i, data);
 	}
 
+out:
+	free(vc);
 	return 0;
 }
 
diff --git a/include/sheep.h b/include/sheep.h
index 719d18f..fbbab85 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -36,6 +36,11 @@ struct vnode_info {
 	int refcnt;
 };
 
+struct vdi_copy {
+	uint32_t vid;
+	uint32_t nr_copies;
+};
+
 #define TRACE_GRAPH_ENTRY  0x01
 #define TRACE_GRAPH_RETURN 0x02
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 84c4164..9c086e0 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -137,11 +137,6 @@ struct vdi_iocb {
 	int nr_copies;
 };
 
-struct vdi_copy {
-	uint32_t vid;
-	uint32_t nr_copies;
-};
-
 struct store_driver {
 	struct list_head list;
 	const char *name;
-- 
1.7.1




More information about the sheepdog mailing list