btrfs-progs: Improve the errno string about open_path_or_dev_mnt()
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Mon, 28 Apr 2014 08:37:29 +0000 (16:37 +0800)
committerDavid Sterba <dsterba@suse.cz>
Fri, 22 Aug 2014 12:39:30 +0000 (14:39 +0200)
open_path_or_dev_mnt() is used to on *mounted* btrfs device or mount
point, when a unmounted btrfs device is passed, errno is set to EINVAL to
info the caller.
If ignore the errno and just print "ERROR: can't access '%s'", end users
will get confused.

This patch will add check for open_path_or_dev_mnt() caller and print
more meaningful error message when a unmounted btrfs device path is
given.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-device.c
cmds-replace.c
cmds-scrub.c

index c8586a0..29da661 100644 (file)
@@ -352,7 +352,13 @@ static int cmd_dev_stats(int argc, char **argv)
        fdmnt = open_path_or_dev_mnt(dev_path, &dirstream);
 
        if (fdmnt < 0) {
-               fprintf(stderr, "ERROR: can't access '%s'\n", dev_path);
+               if (errno == EINVAL)
+                       fprintf(stderr,
+                               "ERROR: '%s' is not a mounted btrfs device\n",
+                               dev_path);
+               else
+                       fprintf(stderr, "ERROR: can't access '%s': %s\n",
+                               dev_path, strerror(errno));
                return 1;
        }
 
index 01ab77c..645dc98 100644 (file)
@@ -172,8 +172,13 @@ static int cmd_start_replace(int argc, char **argv)
        fdmnt = open_path_or_dev_mnt(path, &dirstream);
 
        if (fdmnt < 0) {
-               fprintf(stderr, "ERROR: can't access \"%s\": %s\n",
-                       path, strerror(errno));
+               if (errno == EINVAL)
+                       fprintf(stderr,
+                               "ERROR: '%s' is not a mounted btrfs device\n",
+                               path);
+               else
+                       fprintf(stderr, "ERROR: can't access '%s': %s\n",
+                               path, strerror(errno));
                goto leave_with_error;
        }
 
index 3510f57..5265a2b 100644 (file)
@@ -1172,7 +1172,13 @@ static int scrub_start(int argc, char **argv, int resume)
        fdmnt = open_path_or_dev_mnt(path, &dirstream);
 
        if (fdmnt < 0) {
-               ERR(!do_quiet, "ERROR: can't access '%s'\n", path);
+               if (errno == EINVAL)
+                       ERR(!do_quiet,
+                           "ERROR: '%s' is not a mounted btrfs device\n",
+                           path);
+               else
+                       ERR(!do_quiet, "ERROR: can't access '%s': %s\n",
+                           path, strerror(errno));
                return 1;
        }
 
@@ -1560,8 +1566,13 @@ static int cmd_scrub_cancel(int argc, char **argv)
 
        fdmnt = open_path_or_dev_mnt(path, &dirstream);
        if (fdmnt < 0) {
-               fprintf(stderr, "ERROR: could not open %s: %s\n",
-                       path, strerror(errno));
+               if (errno == EINVAL)
+                       fprintf(stderr,
+                               "ERROR: '%s' is not a mounted btrfs device\n",
+                               path);
+               else
+                       fprintf(stderr, "ERROR: can't access '%s': %s\n",
+                               path, strerror(errno));
                ret = 1;
                goto out;
        }
@@ -1658,7 +1669,13 @@ static int cmd_scrub_status(int argc, char **argv)
        fdmnt = open_path_or_dev_mnt(path, &dirstream);
 
        if (fdmnt < 0) {
-               fprintf(stderr, "ERROR: can't access '%s'\n", path);
+               if (errno == EINVAL)
+                       fprintf(stderr,
+                               "ERROR: '%s' is not a mounted btrfs device\n",
+                               path);
+               else
+                       fprintf(stderr, "ERROR: can't access '%s': %s\n",
+                               path, strerror(errno));
                return 1;
        }