[sheepdog] [PATCH] store/plain: use link to recover local objects

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Fri Sep 14 10:40:40 CEST 2012


It is not safe to rename stale objects to the working directory.  When
reading objects for recovery, default_read reads the working directory
first, and then, searches stale objects.  However, if the objects are
renamed from the stale directory to the working directory on the node
at the same time, the recovery read request fails to find the object.

To fix this race condition, this patch uses link/2 to keep stale
objects.  This fixes test failure of tests/028.

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

diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index e07e934..de38a1f 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -331,8 +331,8 @@ int default_link(uint64_t oid, struct siocb *iocb, uint32_t tgt_epoch)
 	get_obj_path(oid, path);
 	get_stale_obj_path(oid, tgt_epoch, stale_path);
 
-	if (rename(stale_path, path) < 0) {
-		eprintf("failed to rename from %s to %s, %m\n", stale_path,
+	if (link(stale_path, path) < 0) {
+		eprintf("failed to link from %s to %s, %m\n", stale_path,
 			path);
 		return SD_RES_EIO;
 	}
-- 
1.7.2.5




More information about the sheepdog mailing list