util-linux/0036-loopdev-Properly-translate-errors-from-ul_path_read_.patch
2022-08-10 15:16:21 +02:00

52 lines
1.6 KiB
Diff

From 432b5024cc40647ea0a541c70c31d00719b52652 Mon Sep 17 00:00:00 2001
From: Jan Kara <jack@suse.cz>
Date: Thu, 20 Jan 2022 13:16:38 +0100
Subject: 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.
Addresses: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=2117203
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 d9ea1d4a2..db3aab29f 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.37.1