diff mbox

btrfs-progs: unified error handle for print_replace_status

Message ID 8ecb18af6cff4e7f413bfeee8d66aa61dc1aa151.1440514191.git.zhaolei@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Zhaolei Aug. 25, 2015, 2:50 p.m. UTC
Current code of print_replace_status() mixed stdout and stderr in
error case, output a error string to stderr without "\n", then
output "\n" to stdout to end the line.

This patch fixed above problem by using unified error handle way for 3
type of errors in print_replace_status().

Also include some small logic cleanup.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
 cmds-replace.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Comments

David Sterba Aug. 25, 2015, 5:11 p.m. UTC | #1
On Tue, Aug 25, 2015 at 10:50:08PM +0800, Zhao Lei wrote:
> Current code of print_replace_status() mixed stdout and stderr in
> error case, output a error string to stderr without "\n", then
> output "\n" to stdout to end the line.
> 
> This patch fixed above problem by using unified error handle way for 3
> type of errors in print_replace_status().
> 
> Also include some small logic cleanup.
> 
> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>

Applied, thanks. I've slighly reworded the error message.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-replace.c b/cmds-replace.c
index ce91787..134addf 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -405,7 +405,6 @@  static int print_replace_status(int fd, const char *path, int once)
 			return ret;
 		}
 
-		status = &args.status;
 		if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR) {
 			fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_STATUS) on \"%s\" returns error: %s\n",
 				path,
@@ -413,6 +412,8 @@  static int print_replace_status(int fd, const char *path, int once)
 			return -1;
 		}
 
+		status = &args.status;
+
 		skip_stats = 0;
 		num_chars = 0;
 		switch (status->replace_state) {
@@ -457,12 +458,9 @@  static int print_replace_status(int fd, const char *path, int once)
 			printf("Never started");
 			break;
 		default:
-			prevent_loop = 1;
-			fprintf(stderr,
-				"Unknown btrfs dev replace status:%llu",
-				status->replace_state);
-			ret = -EINVAL;
-			break;
+			fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_STATUS) on \"%s\" got unknown status: %llu\n",
+				path, status->replace_state);
+			return -EINVAL;
 		}
 
 		if (!skip_stats)
@@ -471,9 +469,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 || ret) {
+		if (once || prevent_loop) {
 			printf("\n");
-			return ret;
+			break;
 		}
 
 		fflush(stdout);