From patchwork Fri Aug 14 10:36:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 7014241 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 01F87C05AC for ; Fri, 14 Aug 2015 10:37:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 073832076A for ; Fri, 14 Aug 2015 10:37:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A795A2073C for ; Fri, 14 Aug 2015 10:37:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754920AbbHNKhM (ORCPT ); Fri, 14 Aug 2015 06:37:12 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:35416 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754833AbbHNKhK (ORCPT ); Fri, 14 Aug 2015 06:37:10 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t7EAb6vt030185 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 14 Aug 2015 10:37:07 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t7EAb6P3028949 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 14 Aug 2015 10:37:06 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t7EAb6oH014367; Fri, 14 Aug 2015 10:37:06 GMT Received: from arch2.sg.oracle.com (/10.186.101.122) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 14 Aug 2015 03:37:05 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: clm@fb.com, dsterba@suse.cz Subject: [PATCH 2/2] btrfs-progs: device delete to accept devid Date: Fri, 14 Aug 2015 18:36:51 +0800 Message-Id: <1439548611-29730-3-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1439548611-29730-1-git-send-email-anand.jain@oracle.com> References: <1439548388-29686-1-git-send-email-anand.jain@oracle.com> <1439548611-29730-1-git-send-email-anand.jain@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] 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.9 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 This patch introduces new option for the command btrfs device delete [..] In a user reported issue on a 3-disk-RAID1, one disk failed with its SB unreadable. Now with this patch user will have a choice to delete the device using devid. The other method we could do, is to match the input device_path to the available device_paths with in the kernel. But that won't work in all the cases, like what if user provided mapper path when the path within the kernel is a non-mapper path. This patch depends on the below kernel patch for the new feature to work, however it will fail-back to the old interface for the kernel without the patch Btrfs: device delete by devid Signed-off-by: Anand Jain --- Documentation/btrfs-device.asciidoc | 2 +- cmds-device.c | 45 ++++++++++++++++++++++++++++--------- ioctl.h | 8 +++++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/Documentation/btrfs-device.asciidoc b/Documentation/btrfs-device.asciidoc index 2827598..61ede6e 100644 --- a/Documentation/btrfs-device.asciidoc +++ b/Documentation/btrfs-device.asciidoc @@ -74,7 +74,7 @@ do not perform discard by default -f|--force:::: force overwrite of existing filesystem on the given disk(s) -*remove* [...] :: +*remove* | [|...] :: Remove device(s) from a filesystem identified by . *delete* [...] :: diff --git a/cmds-device.c b/cmds-device.c index 0e60500..eb4358d 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -164,16 +164,34 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr) struct btrfs_ioctl_vol_args arg; int res; - if (!is_block_device(argv[i])) { + struct btrfs_ioctl_vol_args_v3 argv3 = {0}; + int its_num = false; + + if (is_numerical(argv[i])) { + argv3.devid = arg_strtou64(argv[i]); + its_num = true; + } else if (is_block_device(argv[i])) { + strncpy_null(argv3.name, argv[i]); + } else { fprintf(stderr, - "ERROR: %s is not a block device\n", argv[i]); + "ERROR: %s is not a block device or devid\n", argv[i]); ret++; continue; } - memset(&arg, 0, sizeof(arg)); - strncpy_null(arg.name, argv[i]); - res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); + res = ioctl(fdmnt, BTRFS_IOC_RM_DEV_V2, &argv3); e = errno; + if (res && e == ENOTTY) { + if (its_num) { + fprintf(stderr, + "Error: Kernel does not support delete by devid\n"); + ret = 1; + continue; + } + memset(&arg, 0, sizeof(arg)); + strncpy_null(arg.name, argv[i]); + res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); + e = errno; + } if (res) { const char *msg; @@ -181,9 +199,16 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr) msg = btrfs_err_str(res); else msg = strerror(e); - fprintf(stderr, - "ERROR: error removing the device '%s' - %s\n", - argv[i], msg); + + if (its_num) + fprintf(stderr, + "ERROR: error removing the devid '%llu' - %s\n", + argv3.devid, msg); + else + fprintf(stderr, + "ERROR: error removing the device '%s' - %s\n", + argv[i], msg); + ret++; } } @@ -193,7 +218,7 @@ static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr) } static const char * const cmd_rm_dev_usage[] = { - "btrfs device remove [...] ", + "btrfs device remove | [|...] ", "Remove a device from a filesystem", NULL }; @@ -204,7 +229,7 @@ static int cmd_rm_dev(int argc, char **argv) } static const char * const cmd_del_dev_usage[] = { - "btrfs device delete [...] ", + "btrfs device delete | [|...] ", "Remove a device from a filesystem", NULL }; diff --git a/ioctl.h b/ioctl.h index dff015a..6870931 100644 --- a/ioctl.h +++ b/ioctl.h @@ -40,6 +40,12 @@ struct btrfs_ioctl_vol_args { char name[BTRFS_PATH_NAME_MAX + 1]; }; +struct btrfs_ioctl_vol_args_v3 { + __s64 fd; + char name[BTRFS_PATH_NAME_MAX + 1]; + __u64 devid; +}; + #define BTRFS_DEVICE_PATH_NAME_MAX 1024 #define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0) @@ -683,6 +689,8 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code) struct btrfs_ioctl_feature_flags[2]) #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \ struct btrfs_ioctl_feature_flags[3]) +#define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \ + struct btrfs_ioctl_vol_args_v3) #ifdef __cplusplus } #endif