From patchwork Wed Oct 11 02:18:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 9998459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6029760230 for ; Wed, 11 Oct 2017 02:19:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C76D288B0 for ; Wed, 11 Oct 2017 02:19:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41AB8288BB; Wed, 11 Oct 2017 02:19:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6B79288B0 for ; Wed, 11 Oct 2017 02:19:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756641AbdJKCTA (ORCPT ); Tue, 10 Oct 2017 22:19:00 -0400 Received: from mgwym01.jp.fujitsu.com ([211.128.242.40]:30886 "EHLO mgwym01.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752751AbdJKCS7 (ORCPT ); Tue, 10 Oct 2017 22:18:59 -0400 Received: from yt-mxoi1.gw.nic.fujitsu.com (unknown [192.168.229.67]) by mgwym01.jp.fujitsu.com with smtp id 632a_f0af_792a8095_daff_4727_bd44_9b681738825e; Wed, 11 Oct 2017 11:18:54 +0900 Received: from g01jpfmpwkw03.exch.g01.fujitsu.local (g01jpfmpwkw03.exch.g01.fujitsu.local [10.0.193.57]) by yt-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id E8EFAAC00D0 for ; Wed, 11 Oct 2017 11:18:53 +0900 (JST) Received: from G01JPEXCHKW18.g01.fujitsu.local (G01JPEXCHKW18.g01.fujitsu.local [10.0.194.57]) by g01jpfmpwkw03.exch.g01.fujitsu.local (Postfix) with ESMTP id 163E3BD64EF for ; Wed, 11 Oct 2017 11:18:53 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: b0aa0accbf9b43128337c7d734d0b12a Subject: [PATCH v2 3/3] btrfs-progs: device: add remove missing-all From: "Misono, Tomohiro" To: linux-btrfs References: Message-ID: Date: Wed, 11 Oct 2017 11:18:50 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add 'btrfs remove missing-all' to remove all the missing devices at once for improving usability. Example: sudo mkfs.btrfs -f -d raid1 /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 sudo wipefs -a /dev/sdb1 /dev/sdb3 sudo mount -o degraded /dev/sdb2 /mnt sudo btrfs filesystem show /mnt sudo btrfs device remove missing-all /mnt sudo btrfs filesystem show /mnt Signed-off-by: Tomohiro Misono --- Documentation/btrfs-device.asciidoc | 1 + cmds-device.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Documentation/btrfs-device.asciidoc b/Documentation/btrfs-device.asciidoc index dd60415..f08d64d 100644 --- a/Documentation/btrfs-device.asciidoc +++ b/Documentation/btrfs-device.asciidoc @@ -79,6 +79,7 @@ lowest device id. If device is mounted as degraded mode (-o degraded), special term "missing" can be used for . In that case, the first device that is described by the filesystem metadata, but not preseted at the mount time will be removed. +Also, "missing-all" can be used to remove all the missing devices. *delete* | [|...] :: Alias of remove kept for backward compatibility diff --git a/cmds-device.c b/cmds-device.c index d28ed0f..507ad04 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -164,6 +164,8 @@ static int _cmd_device_remove(int argc, char **argv, struct btrfs_ioctl_vol_args arg; struct btrfs_ioctl_vol_args_v2 argv2 = {0}; int is_devid = 0; + int is_missing_all = 0; + int num_missing = 0; int res; if (string_is_numerical(argv[i])) { @@ -173,12 +175,16 @@ static int _cmd_device_remove(int argc, char **argv, } else if (is_block_device(argv[i]) == 1 || strcmp(argv[i], "missing") == 0) { strncpy_null(argv2.name, argv[i]); + } else if (strcmp(argv[i], "missing-all") == 0) { + is_missing_all = 1; + strncpy_null(argv2.name, "missing"); } else { error("not a block device: %s", argv[i]); ret++; continue; } +again: /* * Positive values are from BTRFS_ERROR_DEV_*, * otherwise it's a generic error, one of errnos @@ -202,6 +208,21 @@ static int _cmd_device_remove(int argc, char **argv, res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); } + if (is_missing_all) { + if (!res) { + num_missing++; + goto again; + } + + if (num_missing > 0 && + (res == BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET || + res == BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET || + res == BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET || + res == BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET || + res == BTRFS_ERROR_DEV_MISSING_NOT_FOUND)) + continue; + } + if (res) { const char *msg; @@ -228,7 +249,8 @@ static int _cmd_device_remove(int argc, char **argv, "", \ "If 'missing' is specified for , the first device that is", \ "described by the filesystem metadata, but not presented at the", \ - "mount time will be removed." + "mount time will be removed. Use 'missing-all' to remove all the", \ + "missing devices." static const char * const cmd_device_remove_usage[] = { "btrfs device remove | [|...] ",