Blame SOURCES/lvm2-2_02_183-bcache-sync-io-fixes.patch

12cbd3
 lib/device/bcache.c | 69 ++++++++++++++++++++++++++++++++++++-----------------
12cbd3
 1 file changed, 47 insertions(+), 22 deletions(-)
12cbd3
12cbd3
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
12cbd3
index 1cb1b2f..6886b74 100644
12cbd3
--- a/lib/device/bcache.c
12cbd3
+++ b/lib/device/bcache.c
12cbd3
@@ -320,7 +320,7 @@ struct io_engine *create_async_io_engine(void)
12cbd3
 	e->aio_context = 0;
12cbd3
 	r = io_setup(MAX_IO, &e->aio_context);
12cbd3
 	if (r < 0) {
12cbd3
-		log_warn("io_setup failed");
12cbd3
+		log_debug("io_setup failed %d", r);
12cbd3
 		dm_free(e);
12cbd3
 		return NULL;
12cbd3
 	}
12cbd3
@@ -363,8 +363,11 @@ static void _sync_destroy(struct io_engine *ioe)
12cbd3
 static bool _sync_issue(struct io_engine *ioe, enum dir d, int fd,
12cbd3
                         sector_t sb, sector_t se, void *data, void *context)
12cbd3
 {
12cbd3
-        int r;
12cbd3
-        uint64_t len = (se - sb) * 512, where;
12cbd3
+	int rv;
12cbd3
+	off_t off;
12cbd3
+	uint64_t where;
12cbd3
+	uint64_t pos = 0;
12cbd3
+	uint64_t len = (se - sb) * 512;
12cbd3
 	struct sync_engine *e = _to_sync(ioe);
12cbd3
 	struct sync_io *io = malloc(sizeof(*io));
12cbd3
 	if (!io) {
12cbd3
@@ -373,11 +376,17 @@ static bool _sync_issue(struct io_engine *ioe, enum dir d, int fd,
12cbd3
 	}
12cbd3
 
12cbd3
 	where = sb * 512;
12cbd3
-	r = lseek(fd, where, SEEK_SET);
12cbd3
-	if (r < 0) {
12cbd3
-        	log_warn("unable to seek to position %llu", (unsigned long long) where);
12cbd3
-        	free(io);
12cbd3
-        	return false;
12cbd3
+
12cbd3
+	off = lseek(fd, where, SEEK_SET);
12cbd3
+	if (off == (off_t) -1) {
12cbd3
+		log_warn("Device seek error %d for offset %llu", errno, (unsigned long long)where);
12cbd3
+		free(io);
12cbd3
+		return false;
12cbd3
+	}
12cbd3
+	if (off != (off_t) where) {
12cbd3
+		log_warn("Device seek failed for offset %llu", (unsigned long long)where);
12cbd3
+		free(io);
12cbd3
+		return false;
12cbd3
 	}
12cbd3
 
12cbd3
 	/*
12cbd3
@@ -422,28 +431,44 @@ static bool _sync_issue(struct io_engine *ioe, enum dir d, int fd,
12cbd3
 		len = nbytes;
12cbd3
 	}
12cbd3
 
12cbd3
-	while (len) {
12cbd3
-        	do {
12cbd3
-                	if (d == DIR_READ)
12cbd3
-                                r = read(fd, data, len);
12cbd3
-                        else
12cbd3
-                                r = write(fd, data, len);
12cbd3
+	while (pos < len) {
12cbd3
+		if (d == DIR_READ)
12cbd3
+			rv = read(fd, (char *)data + pos, len - pos);
12cbd3
+		else
12cbd3
+			rv = write(fd, (char *)data + pos, len - pos);
12cbd3
 
12cbd3
-        	} while ((r < 0) && ((r == EINTR) || (r == EAGAIN)));
12cbd3
+		if (rv == -1 && errno == EINTR)
12cbd3
+			continue;
12cbd3
+		if (rv == -1 && errno == EAGAIN)
12cbd3
+			continue;
12cbd3
+
12cbd3
+		if (!rv)
12cbd3
+			break;
12cbd3
 
12cbd3
-        	if (r < 0) {
12cbd3
-                	log_warn("io failed %d", r);
12cbd3
+		if (rv < 0) {
12cbd3
+			if (d == DIR_READ)
12cbd3
+				log_debug("Device read error %d offset %llu len %llu", errno,
12cbd3
+					  (unsigned long long)(where + pos),
12cbd3
+					  (unsigned long long)(len - pos));
12cbd3
+			else
12cbd3
+				log_debug("Device write error %d offset %llu len %llu", errno,
12cbd3
+					  (unsigned long long)(where + pos),
12cbd3
+					  (unsigned long long)(len - pos));
12cbd3
                 	free(io);
12cbd3
                 	return false;
12cbd3
-        	}
12cbd3
-
12cbd3
-                len -= r;
12cbd3
+		}
12cbd3
+		pos += rv;
12cbd3
 	}
12cbd3
 
12cbd3
-	if (len) {
12cbd3
-        	log_warn("short io %u bytes remaining", (unsigned) len);
12cbd3
+	if (pos < len) {
12cbd3
+		if (d == DIR_READ)
12cbd3
+			log_warn("Device read short %u bytes remaining", (unsigned)(len - pos));
12cbd3
+		else
12cbd3
+			log_warn("Device write short %u bytes remaining", (unsigned)(len - pos));
12cbd3
+		/*
12cbd3
         	free(io);
12cbd3
         	return false;
12cbd3
+		*/
12cbd3
 	}
12cbd3
 
12cbd3