linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/2] btrfs-progs: scan: cleanup, return errno when we have one
Date: Fri, 29 Mar 2019 13:49:53 +0800	[thread overview]
Message-ID: <1553838594-26013-1-git-send-email-anand.jain@oracle.com> (raw)

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


             reply	other threads:[~2019-03-29  5:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-29  5:49 Anand Jain [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1553838594-26013-1-git-send-email-anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).