[Sheepdog] [PATCH] shepherd: improve vdi listing performance

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Mon May 10 12:48:35 CEST 2010


This patch does the following things:
 - reuse the socket discriptor during listing vdis
 - read only the part of the vdi objects

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 shepherd/shepherd.c |   18 +++++++-----------
 1 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index 51401e3..fa51ebe 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -292,10 +292,10 @@ static int parse_vdi(vdi_parser_func_t func, void *data)
 
 	rlen = sizeof(vdi_inuse);
 	ret = exec_req(fd, &req, vdi_inuse, &wlen, &rlen);
-	close(fd);
-
-	if (ret < 0)
+	if (ret < 0) {
+		close(fd);
 		return ret;
+	}
 
 	for (nr = 0; nr < SD_NR_VDIS; nr++) {
 		struct sd_obj_req hdr;
@@ -305,13 +305,8 @@ static int parse_vdi(vdi_parser_func_t func, void *data)
 			continue;
 
 		wlen = 0;
-		rlen = sizeof(i);
-
-		fd = connect_to("localhost", sdport);
-		if (fd < 0) {
-			printf("failed to connect, %m\n");
-			return -1;
-		}
+		/* don't need to read the entire object */
+		rlen = sizeof(i) - sizeof(i.data_vdi_id);
 
 		memset(&hdr, 0, sizeof(hdr));
 		hdr.opcode = SD_OP_READ_OBJ;
@@ -319,7 +314,6 @@ static int parse_vdi(vdi_parser_func_t func, void *data)
 		hdr.data_length = rlen;
 
 		ret = exec_req(fd, (struct sd_req *)&hdr, &i, &wlen, &rlen);
-		close(fd);
 
 		if (!ret && rsp->result == SD_RES_SUCCESS) {
 			if (i.name[0] == '\0') /* deleted */
@@ -329,6 +323,8 @@ static int parse_vdi(vdi_parser_func_t func, void *data)
 			printf("error %lu, %d\n", nr, ret);
 	}
 
+	close(fd);
+
 	return 0;
 }
 
-- 
1.5.6.5




More information about the sheepdog mailing list