dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame 0036-loopdev-Properly-translate-errors-from-ul_path_read_.patch

Karel Zak 0f3035
From 432b5024cc40647ea0a541c70c31d00719b52652 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:38 +0100
Karel Zak 0f3035
Subject: loopdev: Properly translate errors from ul_path_read_*()
Karel Zak 0f3035
Karel Zak 0f3035
A few callsites do not translate error from ul_path_read_*() and just
Karel Zak 0f3035
treat it as error code leading to confusing EPERM errors.
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 | 9 ++++++---
Karel Zak 0f3035
 1 file changed, 6 insertions(+), 3 deletions(-)
Karel Zak 0f3035
Karel Zak 0f3035
diff --git a/lib/loopdev.c b/lib/loopdev.c
Karel Zak 0f3035
index d9ea1d4a2..db3aab29f 100644
Karel Zak 0f3035
--- a/lib/loopdev.c
Karel Zak 0f3035
+++ b/lib/loopdev.c
Karel Zak 0f3035
@@ -739,7 +739,8 @@ int loopcxt_get_offset(struct loopdev_cxt *lc, uint64_t *offset)
Karel Zak 0f3035
 	int rc = -EINVAL;
Karel Zak 0f3035
 
Karel Zak 0f3035
 	if (sysfs)
Karel Zak 0f3035
-		rc = ul_path_read_u64(sysfs, offset, "loop/offset");
Karel Zak 0f3035
+		if (ul_path_read_u64(sysfs, offset, "loop/offset") == 0)
Karel Zak 0f3035
+			rc = 0;
Karel Zak 0f3035
 
Karel Zak 0f3035
 	if (rc && loopcxt_ioctl_enabled(lc)) {
Karel Zak 0f3035
 		struct loop_info64 *lo = loopcxt_get_info(lc);
Karel Zak 0f3035
@@ -767,7 +768,8 @@ int loopcxt_get_blocksize(struct loopdev_cxt *lc, uint64_t *blocksize)
Karel Zak 0f3035
 	int rc = -EINVAL;
Karel Zak 0f3035
 
Karel Zak 0f3035
 	if (sysfs)
Karel Zak 0f3035
-		rc = ul_path_read_u64(sysfs, blocksize, "queue/logical_block_size");
Karel Zak 0f3035
+		if (ul_path_read_u64(sysfs, blocksize, "queue/logical_block_size") == 0)
Karel Zak 0f3035
+			rc = 0;
Karel Zak 0f3035
 
Karel Zak 0f3035
 	/* Fallback based on BLKSSZGET ioctl */
Karel Zak 0f3035
 	if (rc) {
Karel Zak 0f3035
@@ -799,7 +801,8 @@ int loopcxt_get_sizelimit(struct loopdev_cxt *lc, uint64_t *size)
Karel Zak 0f3035
 	int rc = -EINVAL;
Karel Zak 0f3035
 
Karel Zak 0f3035
 	if (sysfs)
Karel Zak 0f3035
-		rc = ul_path_read_u64(sysfs, size, "loop/sizelimit");
Karel Zak 0f3035
+		if (ul_path_read_u64(sysfs, size, "loop/sizelimit") == 0)
Karel Zak 0f3035
+			rc = 0;
Karel Zak 0f3035
 
Karel Zak 0f3035
 	if (rc && loopcxt_ioctl_enabled(lc)) {
Karel Zak 0f3035
 		struct loop_info64 *lo = loopcxt_get_info(lc);
Karel Zak 0f3035
-- 
Karel Zak 0f3035
2.37.1
Karel Zak 0f3035