From patchwork Fri Sep 13 11:35:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 2883531 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C29E8BFF05 for ; Fri, 13 Sep 2013 11:28:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0A7DD20257 for ; Fri, 13 Sep 2013 11:28:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BEBD42022A for ; Fri, 13 Sep 2013 11:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756476Ab3IML2s (ORCPT ); Fri, 13 Sep 2013 07:28:48 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:32983 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756466Ab3IML2o (ORCPT ); Fri, 13 Sep 2013 07:28:44 -0400 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r8DBSfTi013425 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 13 Sep 2013 11:28:41 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r8DBSe4c025389 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 13 Sep 2013 11:28:40 GMT Received: from abhmt101.oracle.com (abhmt101.oracle.com [141.146.116.53]) by userz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r8DBSd3c010102; Fri, 13 Sep 2013 11:28:40 GMT Received: from wish.sg.oracle.com (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 13 Sep 2013 04:28:39 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH] btrfs-progs: use btrfs error code for kernel errors Date: Fri, 13 Sep 2013 19:35:48 +0800 Message-Id: <1379072148-27612-1-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.1.164.g2d0029e In-Reply-To: <1376979054-2883-1-git-send-email-anand.jain@oracle.com> References: <1376979054-2883-1-git-send-email-anand.jain@oracle.com> X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Now with the below kernel patch, the excl operations like dev add/replace/resize and balance returns the btrfs error code defined in btrfs.h, this patch will help btrfs-progs (and thus user) to know the error string on the terminal (instead of /var/log/messages as previously kernel did). This patch depends on the btrfs kernel patch: btrfs: return btrfs error code for dev excl ops err Signed-off-by: Anand Jain --- cmds-balance.c | 15 +++++++++++++++ cmds-device.c | 7 ++++++- cmds-filesystem.c | 6 +++++- cmds-replace.c | 7 ++++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/cmds-balance.c b/cmds-balance.c index b7382ef..4407a13 100644 --- a/cmds-balance.c +++ b/cmds-balance.c @@ -316,6 +316,12 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args, if (ret == 0) goto out; e = errno; + if (ret > 0) { + fprintf(stderr, + "ERROR: Balance failed due to - %s\n", + btrfs_err_str(ret)); + goto out; + } } if (e == ECANCELED) { @@ -332,6 +338,11 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args, "syslog - try dmesg | tail\n"); ret = 19; } + } else if (ret > 0) { + fprintf(stderr, + "ERROR: Balance start failed - %s\n", + btrfs_err_str(ret)); + ret = 1; } else { printf("Done, had to relocate %llu out of %llu chunks\n", (unsigned long long)args->stat.completed, @@ -603,6 +614,10 @@ static int cmd_balance_resume(int argc, char **argv) "There may be more info in syslog - try dmesg | tail\n", path, strerror(e)); return 19; } + } else if (ret > 0) { + fprintf(stderr, + "ERROR: Balance resume failed - %s\n", + btrfs_err_str(ret)); } else { printf("Done, had to relocate %llu out of %llu chunks\n", (unsigned long long)args.stat.completed, diff --git a/cmds-device.c b/cmds-device.c index e45fb1f..17ee7dd 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -111,10 +111,15 @@ static int cmd_add_dev(int argc, char **argv) strncpy_null(ioctl_args.name, argv[i]); res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args); e = errno; - if(res<0){ + if (res < 0) { fprintf(stderr, "ERROR: error adding the device '%s' - %s\n", argv[i], strerror(e)); ret++; + } else if (res > 0) { + fprintf(stderr, + "ERROR: adding the device '%s' - %s\n", + argv[i], btrfs_err_str(res)); + ret = 1; } } diff --git a/cmds-filesystem.c b/cmds-filesystem.c index fa9d36b..b109416 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -618,10 +618,14 @@ static int cmd_resize(int argc, char **argv) res = ioctl(fd, BTRFS_IOC_RESIZE, &args); e = errno; close_file_or_dir(fd, dirstream); - if( res < 0 ){ + if (res < 0) { fprintf(stderr, "ERROR: unable to resize '%s' - %s\n", path, strerror(e)); return 1; + } else if (res > 0) { + fprintf(stderr, "ERROR: resize failed - %s\n", + btrfs_err_str(res)); + return 1; } return 0; } diff --git a/cmds-replace.c b/cmds-replace.c index d9b0940..a31d77e 100644 --- a/cmds-replace.c +++ b/cmds-replace.c @@ -297,12 +297,17 @@ static int cmd_start_replace(int argc, char **argv) start_args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_START; ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &start_args); if (do_not_background) { - if (ret) { + if (ret < 0) { fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_START) failed on \"%s\": %s, %s\n", path, strerror(errno), replace_dev_result2string(start_args.result)); goto leave_with_error; + } else if (ret > 0) { + fprintf(stderr, + "ERROR: replace start failed on %s - %s\n", + path, btrfs_err_str(ret)); + goto leave_with_error; } if (start_args.result !=