[2/2] btrfs-progs: scan: pass blkid_get_cache error code
diff mbox series

Message ID 1553838594-26013-2-git-send-email-anand.jain@oracle.com
State New
Headers show
Series
  • [1/2] btrfs-progs: scan: cleanup, return errno when we have one
Related show

Commit Message

Anand Jain March 29, 2019, 5:49 a.m. UTC
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(-)

Comments

David Sterba May 15, 2019, 2:29 p.m. UTC | #1
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?
Anand Jain May 28, 2019, 12:48 p.m. UTC | #2
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.

Patch
diff mbox series

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);