From patchwork Tue Aug 25 14:50:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7071431 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 70B629F344 for ; Tue, 25 Aug 2015 14:51:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 75CC5208BA for ; Tue, 25 Aug 2015 14:51:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F745208B2 for ; Tue, 25 Aug 2015 14:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754893AbbHYOvs (ORCPT ); Tue, 25 Aug 2015 10:51:48 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:23066 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932409AbbHYOvr (ORCPT ); Tue, 25 Aug 2015 10:51:47 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100002330" Received: from bogon (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 25 Aug 2015 22:54:54 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t7PEpcf4004382 for ; Tue, 25 Aug 2015 22:51:38 +0800 Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Tue, 25 Aug 2015 22:51:44 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH] btrfs-progs: unified error handle for print_replace_status Date: Tue, 25 Aug 2015 22:50:08 +0800 Message-ID: <8ecb18af6cff4e7f413bfeee8d66aa61dc1aa151.1440514191.git.zhaolei@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.1 MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- cmds-replace.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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);