diff options
author | Zhao Lei <zhaolei@cn.fujitsu.com> | 2015-08-25 22:50:08 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2015-08-31 19:25:13 +0200 |
commit | 96fbc6a146ba2b7356112d99ede54cf362797990 (patch) | |
tree | f965308fcef43effa1ec22aca1edc61e1a4b1cd8 /cmds-replace.c | |
parent | 2d46558b30f5e130085212de7e3a22e2780e8d2a (diff) |
btrfs-progs: unified error handling in print_replace_status
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>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-replace.c')
-rw-r--r-- | cmds-replace.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/cmds-replace.c b/cmds-replace.c index 47a8e1c0..c777f1c9 100644 --- a/cmds-replace.c +++ b/cmds-replace.c @@ -417,7 +417,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, @@ -425,6 +424,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) { @@ -469,12 +470,10 @@ 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; + "ERROR: ioctl(DEV_REPLACE_STATUS) on \"%s\" got unknown status: %llu\n", + path, status->replace_state); + return -EINVAL; } if (!skip_stats) @@ -483,9 +482,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); |