loopdev: Properly translate errors from ul_path_read_*()
Subsystems (2)
PATCH 1/2 loopdev: Properly translate errors from ul_path_read_*()
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 <[email protected]>
--- lib/loopdev.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
lib/loopdev.c +6 -3
@@ -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);
Signature · 1 line
2.31.1
PATCH 2/2 loopdev: Do not treat errors when detecting overlap as fatal
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 <[email protected]>
--- lib/loopdev.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
lib/loopdev.c +9 -6
@@ -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 */
Signature · 1 line
2.31.1
Karel Zak
maintainerQuoted 2 lines · Jan Kara
lib/loopdev.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Applied (both patches), thanks!
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com