From patchwork Mon Feb 15 17:34:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 8317411 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 2D27EC02AA for ; Mon, 15 Feb 2016 17:37:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4E7D8202E5 for ; Mon, 15 Feb 2016 17:37:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B5592039C for ; Mon, 15 Feb 2016 17:37:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753420AbcBOReq (ORCPT ); Mon, 15 Feb 2016 12:34:46 -0500 Received: from mx2.suse.de ([195.135.220.15]:34948 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752970AbcBOReo (ORCPT ); Mon, 15 Feb 2016 12:34:44 -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 C7954ABD3; Mon, 15 Feb 2016 17:34:42 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id D0C59DA9DC; Mon, 15 Feb 2016 18:34:39 +0100 (CET) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba , anand.jain@oracle.com Subject: [PATCH 13/15] btrfs: use existing device constraints table btrfs_raid_array Date: Mon, 15 Feb 2016 18:34:39 +0100 Message-Id: <1294a3215cb0e28a81c33ed1b8921aae95043619.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 We should avoid duplicating the device constraints, let's use the btrfs_raid_array in btrfs_check_raid_min_devices. Signed-off-by: David Sterba Reviewed-by: Anand Jain --- fs/btrfs/volumes.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index a67249582a6f..8fee24f92574 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1730,6 +1730,7 @@ static int btrfs_check_raid_min_devices(struct btrfs_fs_info *fs_info, { u64 all_avail; unsigned seq; + int i; do { seq = read_seqbegin(&fs_info->profiles_lock); @@ -1739,22 +1740,16 @@ 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) { - return BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET; - } - - if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && num_devices < 2) { - return BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET; - } + for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) { + if (!(all_avail & btrfs_raid_group[i])) + continue; - if ((all_avail & BTRFS_BLOCK_GROUP_RAID5) && - fs_info->fs_devices->rw_devices < 2) { - return BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET; - } + if (num_devices < btrfs_raid_array[i].devs_min) { + int ret = btrfs_raid_mindev_error[i]; - if ((all_avail & BTRFS_BLOCK_GROUP_RAID6) && - fs_info->fs_devices->rw_devices < 3) { - return BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET; + if (ret) + return ret; + } } return 0;