Blame 0037-loopdev-Do-not-treat-errors-when-detecting-overlap-a.patch

Karel Zak 0f3035
From ea556ef1d9e26802842577597e3736528f54ee0f Mon Sep 17 00:00:00 2001
Karel Zak 0f3035
From: Jan Kara <jack@suse.cz>
Karel Zak 0f3035
Date: Thu, 20 Jan 2022 13:16:39 +0100
Karel Zak 0f3035
Subject: loopdev: Do not treat errors when detecting overlap as fatal
Karel Zak 0f3035
Karel Zak 0f3035
When looking for overlapping loop device we can fail getting some loop
Karel Zak 0f3035
device properties when we race with device autoclear. Just squelsh these
Karel Zak 0f3035
errors and try next loop device.
Karel Zak 0f3035
Karel Zak 0f3035
Addresses: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=2117203
Karel Zak 0f3035
Signed-off-by: Jan Kara <jack@suse.cz>
Karel Zak 0f3035
---
Karel Zak 0f3035
 lib/loopdev.c | 15 +++++++++------
Karel Zak 0f3035
 1 file changed, 9 insertions(+), 6 deletions(-)
Karel Zak 0f3035
Karel Zak 0f3035
diff --git a/lib/loopdev.c b/lib/loopdev.c
Karel Zak 0f3035
index db3aab29f..511f8a0d6 100644
Karel Zak 0f3035
--- a/lib/loopdev.c
Karel Zak 0f3035
+++ b/lib/loopdev.c
Karel Zak 0f3035
@@ -1773,10 +1773,13 @@ int loopcxt_find_overlap(struct loopdev_cxt *lc, const char *filename,
Karel Zak 0f3035
 
Karel Zak 0f3035
 		rc = loopcxt_is_used(lc, hasst ? &st : NULL,
Karel Zak 0f3035
 				     filename, offset, sizelimit, 0);
Karel Zak 0f3035
-		if (!rc)
Karel Zak 0f3035
-			continue;	/* unused */
Karel Zak 0f3035
-		if (rc < 0)
Karel Zak 0f3035
-			break;		/* error */
Karel Zak 0f3035
+		/*
Karel Zak 0f3035
+		 * Either the loopdev is unused or we've got an error which can
Karel Zak 0f3035
+		 * happen when we are racing with device autoclear. Just ignore
Karel Zak 0f3035
+		 * this loopdev...
Karel Zak 0f3035
+		 */
Karel Zak 0f3035
+		if (rc <= 0)
Karel Zak 0f3035
+			continue;
Karel Zak 0f3035
 
Karel Zak 0f3035
 		DBG(CXT, ul_debugobj(lc, "found %s backed by %s",
Karel Zak 0f3035
 			loopcxt_get_device(lc), filename));
Karel Zak 0f3035
@@ -1785,13 +1788,13 @@ int loopcxt_find_overlap(struct loopdev_cxt *lc, const char *filename,
Karel Zak 0f3035
 		if (rc) {
Karel Zak 0f3035
 			DBG(CXT, ul_debugobj(lc, "failed to get offset for device %s",
Karel Zak 0f3035
 				loopcxt_get_device(lc)));
Karel Zak 0f3035
-			break;
Karel Zak 0f3035
+			continue;
Karel Zak 0f3035
 		}
Karel Zak 0f3035
 		rc = loopcxt_get_sizelimit(lc, &lc_sizelimit);
Karel Zak 0f3035
 		if (rc) {
Karel Zak 0f3035
 			DBG(CXT, ul_debugobj(lc, "failed to get sizelimit for device %s",
Karel Zak 0f3035
 				loopcxt_get_device(lc)));
Karel Zak 0f3035
-			break;
Karel Zak 0f3035
+			continue;
Karel Zak 0f3035
 		}
Karel Zak 0f3035
 
Karel Zak 0f3035
 		/* full match */
Karel Zak 0f3035
-- 
Karel Zak 0f3035
2.37.1
Karel Zak 0f3035