All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs-progs: Improve the errno string about open_path_or_dev_mnt()
@ 2014-04-28  8:37 Qu Wenruo
  2014-04-28  8:37 ` [PATCH 2/2] btrfs-progs: Replace the overkill assert with normal error message Qu Wenruo
  0 siblings, 1 reply; 2+ messages in thread
From: Qu Wenruo @ 2014-04-28  8:37 UTC (permalink / raw)
  To: linux-btrfs

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>
---
 cmds-device.c  |  8 +++++++-
 cmds-replace.c |  9 +++++++--
 cmds-scrub.c   | 25 +++++++++++++++++++++----
 3 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/cmds-device.c b/cmds-device.c
index a9b4a38..f2e08ba 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -353,7 +353,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;
 	}
 
diff --git a/cmds-replace.c b/cmds-replace.c
index 01ab77c..645dc98 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -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;
 	}
 
diff --git a/cmds-scrub.c b/cmds-scrub.c
index 4338a0b..616d797 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -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;
 	}
 
-- 
1.9.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] btrfs-progs: Replace the overkill assert with normal error message.
  2014-04-28  8:37 [PATCH 1/2] btrfs-progs: Improve the errno string about open_path_or_dev_mnt() Qu Wenruo
@ 2014-04-28  8:37 ` Qu Wenruo
  0 siblings, 0 replies; 2+ messages in thread
From: Qu Wenruo @ 2014-04-28  8:37 UTC (permalink / raw)
  To: linux-btrfs

When 'btrfs replace status' encounters an unknown dev replace status, it
will cause an assert, which is somewhat overkilled and can be replaced
with a normal error message.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-replace.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/cmds-replace.c b/cmds-replace.c
index 645dc98..9eb981b 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -449,7 +449,10 @@ static int print_replace_status(int fd, const char *path, int once)
 			break;
 		default:
 			prevent_loop = 1;
-			assert(0);
+			fprintf(stderr,
+				"Unknown btrfs dev replace status:%llu",
+				status->replace_state);
+			ret = -EINVAL;
 			break;
 		}
 
@@ -459,9 +462,9 @@ static int print_replace_status(int fd, const char *path, int once)
 				(unsigned long long)status->num_write_errors,
 				(unsigned long long)
 				 status->num_uncorrectable_read_errors);
-		if (once || prevent_loop) {
+		if (once || prevent_loop || ret) {
 			printf("\n");
-			return 0;
+			return ret;
 		}
 
 		fflush(stdout);
-- 
1.9.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-04-28  8:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-28  8:37 [PATCH 1/2] btrfs-progs: Improve the errno string about open_path_or_dev_mnt() Qu Wenruo
2014-04-28  8:37 ` [PATCH 2/2] btrfs-progs: Replace the overkill assert with normal error message Qu Wenruo

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.