From patchwork Mon Feb 15 17:34:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 8317361 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 12EAD9F6E4 for ; Mon, 15 Feb 2016 17:35:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1D43B2039C for ; Mon, 15 Feb 2016 17:35:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D016202E5 for ; Mon, 15 Feb 2016 17:35:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753289AbcBORes (ORCPT ); Mon, 15 Feb 2016 12:34:48 -0500 Received: from mx2.suse.de ([195.135.220.15]:34934 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752584AbcBOReh (ORCPT ); Mon, 15 Feb 2016 12:34:37 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3801CABD3; Mon, 15 Feb 2016 17:34:36 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 4119DDA9DC; Mon, 15 Feb 2016 18:34:33 +0100 (CET) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba , anand.jain@oracle.com Subject: [PATCH 11/15] btrfs: pass number of devices to btrfs_check_raid_min_devices Date: Mon, 15 Feb 2016 18:34:33 +0100 Message-Id: <83c7c8cf473c48f6dd8eaccb2d80fcc84cf8919e.1455556900.git.dsterba@suse.com> X-Mailer: git-send-email 2.7.1 In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 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 Before this patch, btrfs_check_raid_min_devices would do an off-by-one check of the constraints and not the miminmum check, as its name suggests. This is not a problem if the only caller is device remove, but would be confusing for others. Add an argument with the exact number and let the caller(s) decide if this needs any adjustments, like when device replace is running. Signed-off-by: David Sterba Reviewed-by: Anand Jain Tested-by: Anand Jain --- fs/btrfs/volumes.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 4fa4a836a072..ae94e06f3e61 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1705,20 +1705,17 @@ static int btrfs_rm_dev_item(struct btrfs_root *root, return ret; } -static int btrfs_check_raid_min_devices(struct btrfs_fs_info *fs_info) +/* + * Verify that @num_devices satisfies the RAID profile constraints in the whole + * filesystem. It's up to the caller to adjust that number regarding eg. device + * replace. + */ +static int btrfs_check_raid_min_devices(struct btrfs_fs_info *fs_info, + u64 num_devices) { u64 all_avail; - u64 num_devices; unsigned seq; - num_devices = fs_info->fs_devices->num_devices; - btrfs_dev_replace_lock(&fs_info->dev_replace); - if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) { - WARN_ON(num_devices < 1); - num_devices--; - } - btrfs_dev_replace_unlock(&fs_info->dev_replace); - do { seq = read_seqbegin(&fs_info->profiles_lock); @@ -1727,21 +1724,21 @@ static int btrfs_check_raid_min_devices(struct btrfs_fs_info *fs_info) fs_info->avail_metadata_alloc_bits; } while (read_seqretry(&fs_info->profiles_lock, seq)); - if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) { + if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices < 4) { return BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET; } - if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && num_devices <= 2) { + if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && num_devices < 2) { return BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET; } if ((all_avail & BTRFS_BLOCK_GROUP_RAID5) && - fs_info->fs_devices->rw_devices <= 2) { + fs_info->fs_devices->rw_devices < 2) { return BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET; } if ((all_avail & BTRFS_BLOCK_GROUP_RAID6) && - fs_info->fs_devices->rw_devices <= 3) { + fs_info->fs_devices->rw_devices < 3) { return BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET; } @@ -1760,7 +1757,15 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid) mutex_lock(&uuid_mutex); - ret = btrfs_check_raid_min_devices(root->fs_info); + num_devices = root->fs_info->fs_devices->num_devices; + btrfs_dev_replace_lock(&root->fs_info->dev_replace); + if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) { + WARN_ON(num_devices < 1); + num_devices--; + } + btrfs_dev_replace_unlock(&root->fs_info->dev_replace); + + ret = btrfs_check_raid_min_devices(root->fs_info, num_devices - 1); if (ret) goto out;