[sheepdog] [PATCH v2 1/6] sheep: prepare and cleanup err_to_stderr() for MD recovery

Liu Yuan namei.unix at gmail.com
Wed Mar 27 06:10:56 CET 2013


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

MD recovery relies on the err_to_stderr to catch EIO and do its own EIO handling
tricks.

We don't handle EIO for object cache and journal file gracefully and use
err_to_stderr() to translate errno is non-sense for now because MD recovery
don't care about other path except backend stores.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/journal_file.c |    3 ++-
 sheep/object_cache.c |    3 ++-
 sheep/plain_store.c  |   28 +++++++++++++++-------------
 sheep/sheep_priv.h   |    1 -
 4 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/sheep/journal_file.c b/sheep/journal_file.c
index 7d7773f..d37b4d1 100644
--- a/sheep/journal_file.c
+++ b/sheep/journal_file.c
@@ -360,7 +360,8 @@ int journal_file_write(uint64_t oid, const char *buf, size_t size,
 	written = xpwrite(jfile.fd, wbuffer, wsize, woff);
 	if (written != wsize) {
 		sd_eprintf("failed, written %zd, len %zu", written, wsize);
-		ret = err_to_sderr(oid, errno);
+		/* FIXME: teach journal file handle EIO gracefully */
+		ret = SD_RES_EIO;
 		goto out;
 	}
 out:
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index e80fd99..93ecfe7 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -757,7 +757,8 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 			goto out_close;
 		}
 		sd_dprintf("failed to link %s to %s: %m", tmp_path, path);
-		ret = err_to_sderr(idx_to_oid(oc->vid, idx), errno);
+		/* FIXME: teach object cache handle EIO gracefully */
+		ret = SD_RES_EIO;
 		goto out_close;
 	}
 	ret = SD_RES_SUCCESS;
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 87ebd35..f9741bb 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -13,6 +13,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <libgen.h>
 
 #include "sheep_priv.h"
 #include "config.h"
@@ -66,14 +67,15 @@ bool default_exist(uint64_t oid)
 	return true;
 }
 
-int err_to_sderr(uint64_t oid, int err)
+static int err_to_sderr(char *path, uint64_t oid, int err)
 {
 	struct stat s;
+	char *dir = dirname(path);
 
 	switch (err) {
 	case ENOENT:
-		if (stat(get_object_path(oid), &s) < 0) {
-			sd_eprintf("corrupted");
+		if (stat(dir, &s) < 0) {
+			sd_eprintf("%s corrupted", dir);
 			return SD_RES_EIO;
 		}
 		sd_dprintf("object %016" PRIx64 " not found locally", oid);
@@ -114,14 +116,14 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 
 	fd = open(path, flags, def_fmode);
 	if (fd < 0)
-		return err_to_sderr(oid, errno);
+		return err_to_sderr(path, oid, errno);
 
 	size = xpwrite(fd, iocb->buf, iocb->length, iocb->offset);
 	if (size != iocb->length) {
 		sd_eprintf("failed to write object %"PRIx64", path=%s, offset=%"
 			PRId64", size=%"PRId32", result=%zd, %m", oid, path,
 			iocb->offset, iocb->length, size);
-		ret = err_to_sderr(oid, errno);
+		ret = err_to_sderr(path, oid, errno);
 		goto out;
 	}
 out:
@@ -225,7 +227,7 @@ int default_init(void)
 	return for_each_object_in_wd(init_objlist_and_vdi_bitmap, true, NULL);
 }
 
-static int default_read_from_path(uint64_t oid, const char *path,
+static int default_read_from_path(uint64_t oid, char *path,
 				  const struct siocb *iocb)
 {
 	int flags = get_open_flags(oid, false, iocb->flags), fd,
@@ -235,14 +237,14 @@ static int default_read_from_path(uint64_t oid, const char *path,
 	fd = open(path, flags);
 
 	if (fd < 0)
-		return err_to_sderr(oid, errno);
+		return err_to_sderr(path, oid, errno);
 
 	size = xpread(fd, iocb->buf, iocb->length, iocb->offset);
 	if (size != iocb->length) {
 		sd_eprintf("failed to read object %"PRIx64", path=%s, offset=%"
 			PRId64", size=%"PRId32", result=%zd, %m", oid, path,
 			iocb->offset, iocb->length, size);
-		ret = err_to_sderr(oid, errno);
+		ret = err_to_sderr(path, oid, errno);
 	}
 
 	close(fd);
@@ -322,13 +324,13 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 		}
 
 		sd_eprintf("failed to open %s: %m", tmp_path);
-		return err_to_sderr(oid, errno);
+		return err_to_sderr(path, oid, errno);
 	}
 
 	if (iocb->offset != 0 || iocb->length != get_objsize(oid)) {
 		ret = prealloc(fd, get_objsize(oid));
 		if (ret < 0) {
-			ret = err_to_sderr(oid, errno);
+			ret = err_to_sderr(path, oid, errno);
 			goto out;
 		}
 	}
@@ -336,14 +338,14 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 	ret = xpwrite(fd, iocb->buf, len, iocb->offset);
 	if (ret != len) {
 		sd_eprintf("failed to write object. %m");
-		ret = err_to_sderr(oid, errno);
+		ret = err_to_sderr(path, oid, errno);
 		goto out;
 	}
 
 	ret = rename(tmp_path, path);
 	if (ret < 0) {
 		sd_eprintf("failed to rename %s to %s: %m", tmp_path, path);
-		ret = err_to_sderr(oid, errno);
+		ret = err_to_sderr(path, oid, errno);
 		goto out;
 	}
 	sd_dprintf("%"PRIx64, oid);
@@ -368,7 +370,7 @@ int default_link(uint64_t oid, uint32_t tgt_epoch)
 	if (link(stale_path, path) < 0) {
 		sd_eprintf("failed to link from %s to %s, %m", stale_path,
 			   path);
-		return err_to_sderr(oid, errno);
+		return err_to_sderr(path, oid, errno);
 	}
 
 	return SD_RES_SUCCESS;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 35cea77..21aec29 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -184,7 +184,6 @@ int default_remove_object(uint64_t oid);
 int default_purge_obj(void);
 int for_each_object_in_wd(int (*func)(uint64_t, char *, void *), bool, void *);
 int for_each_obj_path(int (*func)(char *path));
-int err_to_sderr(uint64_t oid, int err);
 
 extern struct list_head store_drivers;
 #define add_store_driver(driver)				\
-- 
1.7.9.5




More information about the sheepdog mailing list