[PATCH 6/6] sheepdog: handle an inconsistent state of metadata

Hitoshi Mitake <[email protected]> Tue, 6 Sep 2016 16:37:29 +0900
Newsgroups org.kernel.vger.stgt
Message-ID <[email protected]>
This commit lets the sheepdog driver to handle the case of no VDI
found during inode reloading. It can happen because sheepdog does not
provide metadata transaction.

Cc: Teruaki Ishizaki <[email protected]>
Cc: Takashi Menjo <[email protected]>
Tested-by: Takashi Menjo <[email protected]>
Signed-off-by: Hitoshi Mitake <[email protected]>
---
 usr/bs_sheepdog.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/usr/bs_sheepdog.c b/usr/bs_sheepdog.c
index 12bcfd9..fc91ad1 100644
--- a/usr/bs_sheepdog.c
+++ b/usr/bs_sheepdog.c
@@ -750,6 +750,7 @@ static int read_write_object(struct sheepdog_access_info *ai, char *buf,
 	unsigned int wlen, rlen;
 	int ret;
 
+retry:
 	memset(&hdr, 0, sizeof(hdr));
 
 	hdr.proto_ver = SD_PROTO_VER;
@@ -791,6 +792,17 @@ static int read_write_object(struct sheepdog_access_info *ai, char *buf,
 	case SD_RES_READONLY:
 		*need_reload = 1;
 		return 0;
+	case SD_RES_NO_OBJ:
+		if (!write && oid & (UINT64_C(1) << 63))
+			/*
+			 * sheepdog doesn't provide a mechanism of metadata
+			 * transaction, so tgt can see an inconsistent state
+			 * like this (old working VDI became snapshot already
+			 * but an inode object of new working VDI isn't
+			 * created yet).
+			 */
+			goto retry;
+		return -1;
 	default:
 		eprintf("%s (oid: %" PRIx64 ", old_oid: %" PRIx64 ")\n",
 			sd_strerror(rsp->result), oid, old_oid);
-- 
2.7.4