* [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
* [PATCH 2/2] btrfs-progs: scan: pass blkid_get_cache error code
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 ` Anand Jain
2019-05-15 14:29 ` David Sterba
2019-05-15 14:26 ` [PATCH 1/2] btrfs-progs: scan: cleanup, return errno when we have one David Sterba
1 sibling, 1 reply; 6+ messages in thread
From: Anand Jain @ 2019-03-29 5:49 UTC (permalink / raw)
To: linux-btrfs
blkid_get_cache() returns error code which is -errno. So we can use them
directly.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
Ref:
blkid_get_cache() code:
https://github.com/karelzak/util-linux/blob/master/libblkid/src/cache.c#L93
https://github.com/karelzak/util-linux/blob/master/libblkid/src/blkidP.h#L307
utils.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/utils.c b/utils.c
index 9e26c884cc6c..c6cdc8f01dc1 100644
--- a/utils.c
+++ b/utils.c
@@ -1994,9 +1994,11 @@ int btrfs_scan_devices(void)
if (btrfs_scan_done)
return 0;
- if (blkid_get_cache(&cache, NULL) < 0) {
- error("blkid cache get failed");
- return 1;
+ ret = blkid_get_cache(&cache, NULL);
+ if (ret < 0) {
+ errno = -ret;
+ error("blkid cache get failed: %m");
+ return ret;
}
blkid_probe_all(cache);
iter = blkid_dev_iterate_begin(cache);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: scan: cleanup, return errno when we have one
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:26 ` David Sterba
2019-05-28 12:47 ` Anand Jain
1 sibling, 1 reply; 6+ messages in thread
From: David Sterba @ 2019-05-15 14:26 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs
On Fri, Mar 29, 2019 at 01:49:53PM +0800, Anand Jain wrote:
> @@ -386,7 +386,9 @@ static int cmd_device_scan(int argc, char **argv)
> }
>
> out:
> - return !!ret;
> + if (ret < 0)
> + return -ret;
> + return ret;
No, cmd_device_scan as the command handler returns the error code that's
intepreted by shell. Most commands do just 0 and 1, in documented case
there are other values, but we can't return errno here.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: scan: pass blkid_get_cache error code
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
0 siblings, 1 reply; 6+ messages in thread
From: David Sterba @ 2019-05-15 14:29 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs
On Fri, Mar 29, 2019 at 01:49:54PM +0800, Anand Jain wrote:
> blkid_get_cache() returns error code which is -errno. So we can use them
> directly.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> Ref:
> blkid_get_cache() code:
> https://github.com/karelzak/util-linux/blob/master/libblkid/src/cache.c#L93
> https://github.com/karelzak/util-linux/blob/master/libblkid/src/blkidP.h#L307
This is internal header of blkid and incidentally the error numbers
match errnos, but I don't think we should rely on that. Does blkid have
a function that translates the code to string, similar to strerror?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: scan: cleanup, return errno when we have one
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
0 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2019-05-28 12:47 UTC (permalink / raw)
To: dsterba, linux-btrfs
On 15/5/19 10:26 PM, David Sterba wrote:
> On Fri, Mar 29, 2019 at 01:49:53PM +0800, Anand Jain wrote:
>> @@ -386,7 +386,9 @@ static int cmd_device_scan(int argc, char **argv)
>> }
>>
>> out:
>> - return !!ret;
>> + if (ret < 0)
>> + return -ret;
>> + return ret;
>
> No, cmd_device_scan as the command handler returns the error code that's
> intepreted by shell. Most commands do just 0 and 1, in documented case
> there are other values, but we can't return errno here.
>
Ok. errno is better error informative though. Interpreted by shell seems
to be a roadblock.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: scan: pass blkid_get_cache error code
2019-05-15 14:29 ` David Sterba
@ 2019-05-28 12:48 ` Anand Jain
0 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2019-05-28 12:48 UTC (permalink / raw)
To: dsterba, linux-btrfs
On 15/5/19 10:29 PM, David Sterba wrote:
> On Fri, Mar 29, 2019 at 01:49:54PM +0800, Anand Jain wrote:
>> blkid_get_cache() returns error code which is -errno. So we can use them
>> directly.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>> Ref:
>> blkid_get_cache() code:
>> https://github.com/karelzak/util-linux/blob/master/libblkid/src/cache.c#L93
>> https://github.com/karelzak/util-linux/blob/master/libblkid/src/blkidP.h#L307
>
> This is internal header of blkid and incidentally the error numbers
> match errnos, but I don't think we should rely on that. Does blkid have
> a function that translates the code to string, similar to strerror?
>
Uh. No there isn't BLKID_ERR.. to string conversion.
^ permalink raw reply [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.