[sheepdog] [PATCH] sheep: avoid using large stack area

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Wed Sep 5 10:42:11 CEST 2012


This also silences valgrind warnings.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/plain_store.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index dc0e2d8..89dd844 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -167,24 +167,29 @@ static int init_vdi_copy_number(uint64_t oid)
 {
 	char path[PATH_MAX];
 	int fd, flags = get_open_flags(oid, false), ret;
-	struct sheepdog_inode inode;
+	struct sheepdog_inode *inode = xzalloc(sizeof(*inode));
 
 	snprintf(path, sizeof(path), "%s%016" PRIx64, obj_path, oid);
 
 	fd = open(path, flags);
 	if (fd < 0) {
 		eprintf("failed to open %s, %m\n", path);
-		return SD_RES_EIO;
+		ret = SD_RES_EIO;
+		goto out;
 	}
 
-	ret = xpread(fd, (void *)&inode, SD_INODE_HEADER_SIZE, 0);
+	ret = xpread(fd, inode, SD_INODE_HEADER_SIZE, 0);
 	if (ret != SD_INODE_HEADER_SIZE) {
 		eprintf("failed to read inode header, path=%s, %m\n", path);
-		return SD_RES_EIO;
+		ret = SD_RES_EIO;
+		goto out;
 	}
 
-	add_vdi_copy_number(oid_to_vid(oid), inode.nr_copies);
+	add_vdi_copy_number(oid_to_vid(oid), inode->nr_copies);
 
+	ret = SD_RES_SUCCESS;
+out:
+	free(inode);
 	return SD_RES_SUCCESS;
 }
 
-- 
1.7.2.5




More information about the sheepdog mailing list