util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] loopdev: Properly translate errors from ul_path_read_*()
@ 2022-01-20 12:16 Jan Kara
  2022-01-20 12:16 ` [PATCH 2/2] loopdev: Do not treat errors when detecting overlap as fatal Jan Kara
  2022-01-25 16:31 ` [PATCH 1/2] loopdev: Properly translate errors from ul_path_read_*() Karel Zak
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Kara @ 2022-01-20 12:16 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, Jan Kara

A few callsites do not translate error from ul_path_read_*() and just
treat it as error code leading to confusing EPERM errors.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 lib/loopdev.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/loopdev.c b/lib/loopdev.c
index b5da1516e37f..27ab06c66848 100644
--- a/lib/loopdev.c
+++ b/lib/loopdev.c
@@ -739,7 +739,8 @@ int loopcxt_get_offset(struct loopdev_cxt *lc, uint64_t *offset)
 	int rc = -EINVAL;
 
 	if (sysfs)
-		rc = ul_path_read_u64(sysfs, offset, "loop/offset");
+		if (ul_path_read_u64(sysfs, offset, "loop/offset") == 0)
+			rc = 0;
 
 	if (rc && loopcxt_ioctl_enabled(lc)) {
 		struct loop_info64 *lo = loopcxt_get_info(lc);
@@ -767,7 +768,8 @@ int loopcxt_get_blocksize(struct loopdev_cxt *lc, uint64_t *blocksize)
 	int rc = -EINVAL;
 
 	if (sysfs)
-		rc = ul_path_read_u64(sysfs, blocksize, "queue/logical_block_size");
+		if (ul_path_read_u64(sysfs, blocksize, "queue/logical_block_size") == 0)
+			rc = 0;
 
 	/* Fallback based on BLKSSZGET ioctl */
 	if (rc) {
@@ -799,7 +801,8 @@ int loopcxt_get_sizelimit(struct loopdev_cxt *lc, uint64_t *size)
 	int rc = -EINVAL;
 
 	if (sysfs)
-		rc = ul_path_read_u64(sysfs, size, "loop/sizelimit");
+		if (ul_path_read_u64(sysfs, size, "loop/sizelimit") == 0)
+			rc = 0;
 
 	if (rc && loopcxt_ioctl_enabled(lc)) {
 		struct loop_info64 *lo = loopcxt_get_info(lc);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] loopdev: Do not treat errors when detecting overlap as fatal
  2022-01-20 12:16 [PATCH 1/2] loopdev: Properly translate errors from ul_path_read_*() Jan Kara
@ 2022-01-20 12:16 ` Jan Kara
  2022-01-25 16:31 ` [PATCH 1/2] loopdev: Properly translate errors from ul_path_read_*() Karel Zak
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2022-01-20 12:16 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, Jan Kara

When looking for overlapping loop device we can fail getting some loop
device properties when we race with device autoclear. Just squelsh these
errors and try next loop device.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 lib/loopdev.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/loopdev.c b/lib/loopdev.c
index 27ab06c66848..d49738fde122 100644
--- a/lib/loopdev.c
+++ b/lib/loopdev.c
@@ -1777,10 +1777,13 @@ int loopcxt_find_overlap(struct loopdev_cxt *lc, const char *filename,
 
 		rc = loopcxt_is_used(lc, hasst ? &st : NULL,
 				     filename, offset, sizelimit, 0);
-		if (!rc)
-			continue;	/* unused */
-		if (rc < 0)
-			break;		/* error */
+		/*
+		 * Either the loopdev is unused or we've got an error which can
+		 * happen when we are racing with device autoclear. Just ignore
+		 * this loopdev...
+		 */
+		if (rc <= 0)
+			continue;
 
 		DBG(CXT, ul_debugobj(lc, "found %s backed by %s",
 			loopcxt_get_device(lc), filename));
@@ -1789,13 +1792,13 @@ int loopcxt_find_overlap(struct loopdev_cxt *lc, const char *filename,
 		if (rc) {
 			DBG(CXT, ul_debugobj(lc, "failed to get offset for device %s",
 				loopcxt_get_device(lc)));
-			break;
+			continue;
 		}
 		rc = loopcxt_get_sizelimit(lc, &lc_sizelimit);
 		if (rc) {
 			DBG(CXT, ul_debugobj(lc, "failed to get sizelimit for device %s",
 				loopcxt_get_device(lc)));
-			break;
+			continue;
 		}
 
 		/* full match */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] loopdev: Properly translate errors from ul_path_read_*()
  2022-01-20 12:16 [PATCH 1/2] loopdev: Properly translate errors from ul_path_read_*() Jan Kara
  2022-01-20 12:16 ` [PATCH 2/2] loopdev: Do not treat errors when detecting overlap as fatal Jan Kara
@ 2022-01-25 16:31 ` Karel Zak
  1 sibling, 0 replies; 3+ messages in thread
From: Karel Zak @ 2022-01-25 16:31 UTC (permalink / raw)
  To: Jan Kara; +Cc: util-linux

On Thu, Jan 20, 2022 at 01:16:38PM +0100, Jan Kara wrote:
>  lib/loopdev.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)

 Applied (both patches), thanks!

  Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-25 16:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20 12:16 [PATCH 1/2] loopdev: Properly translate errors from ul_path_read_*() Jan Kara
2022-01-20 12:16 ` [PATCH 2/2] loopdev: Do not treat errors when detecting overlap as fatal Jan Kara
2022-01-25 16:31 ` [PATCH 1/2] loopdev: Properly translate errors from ul_path_read_*() Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).