[sheepdog] [PATCH RFC 4/5] sheep: replace open() with retry_open()

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Fri Jul 12 03:54:25 CEST 2013


This patch replaces some important calling of open() with
retry_open().

Current retry_open() simply retries open() twice. This policy must be
improved in the future.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 sheep/md.c           |    2 +-
 sheep/object_cache.c |    8 ++++----
 sheep/plain_store.c  |    6 +++---
 sheep/store.c        |    2 +-
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/sheep/md.c b/sheep/md.c
index 5ee3339..cfd2adb 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -497,7 +497,7 @@ static int md_move_object(uint64_t oid, char *old, char *new)
 	int fd, ret = -1;
 	size_t sz = get_objsize(oid);
 
-	fd = open(old, O_RDONLY);
+	fd = retry_open(old, O_RDONLY);
 	if (fd < 0) {
 		sd_eprintf("failed to open %s", old);
 		goto out;
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 06054c3..729dea0 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -338,7 +338,7 @@ static int read_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 		flags |= O_DIRECT;
 	}
 
-	fd = open(p, flags, sd_def_fmode);
+	fd = retry_open(p, flags);
 	if (fd < 0) {
 		sd_eprintf("%m");
 		ret = SD_RES_EIO;
@@ -374,7 +374,7 @@ static int write_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 		flags |= O_DIRECT;
 	}
 
-	fd = open(p, flags, sd_def_fmode);
+	fd = retry_open(p, flags);
 	if (fd < 0) {
 		sd_eprintf("%m");
 		ret = SD_RES_EIO;
@@ -741,7 +741,7 @@ static int object_cache_lookup(struct object_cache *oc, uint32_t idx,
 		return lookup_path(path);
 
 	flags |= O_CREAT | O_TRUNC;
-	fd = open(path, flags, sd_def_fmode);
+	fd = retry_open(path, flags);
 	if (fd < 0) {
 		sd_dprintf("%s, %m", path);
 		ret = SD_RES_EIO;
@@ -770,7 +770,7 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 
 	snprintf(tmp_path, sizeof(tmp_path), "%s/%06"PRIx32"/%08"PRIx32".tmp",
 		object_cache_dir, oc->vid, idx);
-	fd = open(tmp_path, flags, sd_def_fmode);
+	fd = retry_open(tmp_path, flags);
 	if (fd < 0) {
 		if (errno == EEXIST) {
 			sd_dprintf("%08"PRIx32" already created", idx);
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 4854be8..f397fec 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -116,7 +116,7 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 
 	get_obj_path(oid, path);
 
-	fd = open(path, flags, sd_def_fmode);
+	fd = retry_open(path, flags);
 	if (fd < 0)
 		return err_to_sderr(path, oid, errno);
 
@@ -235,7 +235,7 @@ static int default_read_from_path(uint64_t oid, char *path,
 	    ret = SD_RES_SUCCESS;
 	ssize_t size;
 
-	fd = open(path, flags);
+	fd = retry_open(path, flags);
 
 	if (fd < 0)
 		return err_to_sderr(path, oid, errno);
@@ -308,7 +308,7 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 		sync();
 	}
 
-	fd = open(tmp_path, flags, sd_def_fmode);
+	fd = retry_open(tmp_path, flags);
 	if (fd < 0) {
 		if (errno == EEXIST) {
 			/*
diff --git a/sheep/store.c b/sheep/store.c
index d07a100..1f03f69 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -49,7 +49,7 @@ static int do_epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len,
 	struct stat epoch_stat;
 
 	snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
-	fd = open(path, O_RDONLY);
+	fd = retry_open(path, O_RDONLY);
 	if (fd < 0) {
 		sd_eprintf("failed to open epoch %"PRIu32" log, %m", epoch);
 		goto err;
-- 
1.7.10.4




More information about the sheepdog mailing list