[Sheepdog] [PATCH 3/3] object cache: fix create_cache_object()

Liu Yuan namei.unix at gmail.com
Wed May 2 05:22:05 CEST 2012


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

We should unlock fd before err-out.

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

diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 0d00bb1..0b3c911 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -356,17 +356,16 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx, void *buff
 		goto out_close;
 	}
 	ret = xpwrite(fd, buffer, buf_size, 0);
-	if (ret != buf_size) {
+	if (flock(fd, LOCK_UN) < 0) {
 		ret = SD_RES_EIO;
-		eprintf("failed, vid %"PRIx32", idx %"PRIx32"\n", oc->vid, idx);
+		eprintf("%m\n");
 		goto out_close;
 	}
-	if (flock(fd, LOCK_UN) < 0) {
+	if (ret != buf_size) {
 		ret = SD_RES_EIO;
-		eprintf("%m\n");
+		eprintf("failed, vid %"PRIx32", idx %"PRIx32"\n", oc->vid, idx);
 		goto out_close;
 	}
-
 	ret = SD_RES_SUCCESS;
 	dprintf("%08"PRIx32" size %zu\n", idx, buf_size);
 out_close:
-- 
1.7.8.2




More information about the sheepdog mailing list