[Sheepdog] [PATCH v2] collie: fix vdi_object() read size

Liu Yuan namei.unix at gmail.com
Thu Nov 24 06:59:27 CET 2011


From: Liu Yuan <tailai.ly at taobao.com>

This fixes the bug for command 'collie vdi object image -i x'

Since now we don't support short read, for data object, we have
to pass the exact size, or sheep daemon will error out.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 collie/vdi.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/collie/vdi.c b/collie/vdi.c
index d9f8bdb..13b08f8 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -246,20 +246,20 @@ static void get_data_oid(char *sheep, uint64_t oid, struct sd_obj_rsp *rsp,
 	}
 }
 
-static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data)
+static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigned size)
 {
 	char name[128];
 	int i, fd, ret;
 	char *buf;
 
-	buf = zalloc(sizeof(struct sheepdog_inode));
+	buf = zalloc(sizeof(size));
 	if (!buf) {
 		fprintf(stderr, "out of memory\n");
 		return;
 	}
 
 	for (i = 0; i < nr_nodes; i++) {
-		unsigned wlen = 0, rlen = sizeof(struct sheepdog_inode);
+		unsigned wlen = 0, rlen = size;
 		struct sd_obj_req hdr;
 		struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
 
@@ -752,7 +752,7 @@ static int vdi_object(int argc, char **argv)
 	if (idx == ~0) {
 		printf("Looking for the inode object 0x%" PRIx32 " with %d nodes\n\n",
 		       vid, nr_nodes);
-		parse_objs(vid_to_vdi_oid(vid), do_print_obj, NULL);
+		parse_objs(vid_to_vdi_oid(vid), do_print_obj, NULL, SD_INODE_SIZE);
 	} else {
 		struct get_data_oid_info old_info;
 
@@ -764,7 +764,7 @@ static int vdi_object(int argc, char **argv)
 			exit(EXIT_FAILURE);
 		}
 
-		parse_objs(vid_to_vdi_oid(vid), get_data_oid, &old_info);
+		parse_objs(vid_to_vdi_oid(vid), get_data_oid, &old_info, SD_DATA_OBJ_SIZE);
 
 		if (old_info.success) {
 			if (old_info.data_oid) {
@@ -772,7 +772,7 @@ static int vdi_object(int argc, char **argv)
 				       " (the inode vid 0x%" PRIx32 " idx %u) with %d nodes\n\n",
 				       old_info.data_oid, vid, idx, nr_nodes);
 
-				parse_objs(old_info.data_oid, do_print_obj, NULL);
+				parse_objs(old_info.data_oid, do_print_obj, NULL, SD_DATA_OBJ_SIZE);
 			} else
 				printf("The inode object 0x%" PRIx32 " idx %u is not allocated\n",
 				       vid, idx);
-- 
1.7.8.rc3




More information about the sheepdog mailing list