All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs-progs: scan: cleanup, return errno when we have one
@ 2019-03-29  5:49 Anand Jain
  2019-03-29  5:49 ` [PATCH 2/2] btrfs-progs: scan: pass blkid_get_cache error code Anand Jain
  2019-05-15 14:26 ` [PATCH 1/2] btrfs-progs: scan: cleanup, return errno when we have one David Sterba
  0 siblings, 2 replies; 6+ messages in thread
From: Anand Jain @ 2019-03-29  5:49 UTC (permalink / raw)
  To: linux-btrfs

Functions called in cmd_device_scan() and its return codes as below:

btrfs_forget_devices() returns -errno pass down from ioctl or -errno of
open().
btrfs_register_one_device() returns -errno pass down from the kernel
ioctl or -errno from open().
btrfs_scan_devices() (after the patch) returns error code from libblk who's
return error code matches to -errno or 0.
btrfs_register_all_devices() returns number of devices that failed to
regester (as of now) which no one uses. However if
btrfs_register_all_devices() returns error, we error_on() and return 0.

So we can safely return the error code instead of return !!ret;

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-device.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/cmds-device.c b/cmds-device.c
index e3e30b6d5ded..bb3dc78149f8 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -359,13 +359,13 @@ static int cmd_device_scan(int argc, char **argv)
 
 		if (is_block_device(argv[i]) != 1) {
 			error("not a block device: %s", argv[i]);
-			ret = 1;
+			ret = EINVAL;
 			goto out;
 		}
 		path = canonicalize_path(argv[i]);
 		if (!path) {
 			error("could not canonicalize path '%s': %m", argv[i]);
-			ret = 1;
+			ret = EINVAL;
 			goto out;
 		}
 		if (forget) {
@@ -376,8 +376,8 @@ static int cmd_device_scan(int argc, char **argv)
 			}
 		} else {
 			printf("Scanning for btrfs filesystems on '%s'\n", path);
-			if (btrfs_register_one_device(path) != 0) {
-				ret = 1;
+			ret = btrfs_register_one_device(path);
+			if (ret < 0) {
 				free(path);
 				goto out;
 			}
@@ -386,7 +386,9 @@ static int cmd_device_scan(int argc, char **argv)
 	}
 
 out:
-	return !!ret;
+	if (ret < 0)
+		return -ret;
+	return ret;
 }
 
 static const char * const cmd_device_ready_usage[] = {
-- 
1.8.3.1


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

end of thread, other threads:[~2019-05-28 12:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-29  5:49 [PATCH 1/2] btrfs-progs: scan: cleanup, return errno when we have one Anand Jain
2019-03-29  5:49 ` [PATCH 2/2] btrfs-progs: scan: pass blkid_get_cache error code Anand Jain
2019-05-15 14:29   ` David Sterba
2019-05-28 12:48     ` Anand Jain
2019-05-15 14:26 ` [PATCH 1/2] btrfs-progs: scan: cleanup, return errno when we have one David Sterba
2019-05-28 12:47   ` Anand Jain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.