[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-btrfs
Subject: [PATCH 1/2] btrfs-progs: scan: cleanup, return errno when we have one
From: Anand Jain <anand.jain () oracle ! com>
Date: 2019-03-29 5:49:53
Message-ID: 1553838594-26013-1-git-send-email-anand.jain () oracle ! com
[Download RAW message or body]
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic