[Sheepdog] [PATCH 2/4] simple store: fix preallocation object size

Liu Yuan namei.unix at gmail.com
Sat Mar 10 17:53:23 CET 2012


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

We should allocate different sizes for vdi and data object, instead
of fixed size for both.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/simple_store.c |    5 +++--
 sheep/store.c        |    1 +
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/sheep/simple_store.c b/sheep/simple_store.c
index e1cfeca..7cdad31 100644
--- a/sheep/simple_store.c
+++ b/sheep/simple_store.c
@@ -84,6 +84,7 @@ static int store_write_last_sector(uint64_t oid, struct siocb *iocb)
 	const int size = SECTOR_SIZE;
 	char *buf = NULL;
 	int ret;
+	uint32_t length = iocb->length;
 
 	buf = valloc(size);
 	if (!buf) {
@@ -94,7 +95,7 @@ static int store_write_last_sector(uint64_t oid, struct siocb *iocb)
 
 	iocb->buf = buf;
 	iocb->length = size;
-	iocb->offset = SD_DATA_OBJ_SIZE - size;
+	iocb->offset = length - size;
 	ret = simple_store_write(oid, iocb);
 	free(buf);
 
@@ -139,7 +140,7 @@ static int simple_store_open(uint64_t oid, struct siocb *iocb, int create)
 		/*
 		 * Preallocate the whole object to get a better filesystem layout.
 		 */
-		ret = fallocate(iocb->fd, 0, 0, SD_DATA_OBJ_SIZE);
+		ret = fallocate(iocb->fd, 0, 0, iocb->length);
 		if (ret < 0) {
 			if (errno != ENOSYS && errno != EOPNOTSUPP) {
 				ret = SD_RES_EIO;
diff --git a/sheep/store.c b/sheep/store.c
index 0a1932d..e2fd0ee 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -648,6 +648,7 @@ int store_create_and_write_obj(const struct sd_req *req, struct sd_rsp *rsp, voi
 	memset(&iocb, 0, sizeof(iocb));
 	iocb.epoch = epoch;
 	iocb.flags = hdr->flags;
+	iocb.length = hdr->data_length;
 	ret = sd_store->open(hdr->oid, &iocb, 1);
 	if (ret != SD_RES_SUCCESS)
 		return ret;
-- 
1.7.8.2




More information about the sheepdog mailing list