From patchwork Wed Jun 10 12:32:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597779 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A02D90 for ; Wed, 10 Jun 2020 12:33:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30B9E206F4 for ; Wed, 10 Jun 2020 12:33:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Y9V+fFDM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728991AbgFJMdW (ORCPT ); Wed, 10 Jun 2020 08:33:22 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12382 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729029AbgFJMdV (ORCPT ); Wed, 10 Jun 2020 08:33:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792401; x=1623328401; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OjdGgV/iUg9JxZsGLsOUpeBmloXD5kGKiFkSnh5FCc4=; b=Y9V+fFDM4qC7LMS4osyOMkXywWlhNfEmWWYypmfBZMSv9GjI4n7+GafO wSF02/4pKB8Q6UWthOrU67txCTEsWd5qwj94Bt1k0J2atsRSqEmuPG246 k34KS4XGKM+gtC1nyOpOZQL6tAz+yuP+3El9KW0WbrlgTo+taaE3oMuJ2 Oq+C723JJy/hPy9UV5mhYO5uGihVWoWCxxJRkwdX+51aQ3EdVhA74IWVC FFvlF5LOWKi6bzoJcYuzFuXI2v1h2zHsFtoZWlPmzV9iykKApD+pH3f1j Pjh5em0yZPDkqh5OjTcZDIl5ZuSGht4IYcitkUown2eGDLexAAfEn9FvJ Q==; IronPort-SDR: PeslH6MbR5XRkE9pN9fE2DQ/AXHgjGnY/nAwASJYtdYzBAN6sOY+pQ6YfWuyV1oHAu5Qkqb2+x QSeJcK+mPtSRoMThL5DyYXegBcBFgoHpNtWSS6sj9sfWGLlzSx1ojENTOGvv5G7NslgOoER2tB syBR2byWy2hK0ABmPp2QjGGSGtwm61YnHnWwLwVwtpGl90nPoVXXKI5AeI/PW73OkKs1H3ZyRi a1rGDor1ZMPjZ3n9e3MC+sJPXMxkVib6NBizTVrdlE02NyoXT4xmkC5LaHDcIDO3/IMQR5DE0d sPE= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632684" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:05 +0800 IronPort-SDR: gwxkbQDThKmd00SgvgOsuPBr/8WwrrwXLst5PwFYvlmFnLU8hn6Yoyfkdm2A/NAjov7Ehf0wQT hWL5gxQH+zQRjMUcHT9jppJFNGxbGzYB8= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:32 -0700 IronPort-SDR: Xp/O7BPACJrmB+8loD5lVqdovcOGxUmfaYthqtbvp2er8qOUSxhAqrUqu1p4UbVpj2yb6LacZJ RtcEyTrRYXpw== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:04 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 01/15] btrfs-progs: simplify minimal stripe number checking Date: Wed, 10 Jun 2020 21:32:44 +0900 Message-Id: <20200610123258.12382-2-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In btrfs_alloc_chunk_ctrl() we have a recurring pattern, first we assign num stripes, then we test if num_stripes is smaller than a hardcoded boundary and after that we set min_stripes to this magic value. Reverse the logic by first assigning min_stripes and then testing num_stripes against min_stripes. This will help further refactoring. Signed-off-by: Johannes Thumshirn --- volumes.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/volumes.c b/volumes.c index 7f84fbbaa742..089363f66473 100644 --- a/volumes.c +++ b/volumes.c @@ -1054,25 +1054,25 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } } if (type & BTRFS_BLOCK_GROUP_RAID1) { - num_stripes = min_t(u64, 2, + min_stripes = 2; + num_stripes = min_t(u64, min_stripes, btrfs_super_num_devices(info->super_copy)); - if (num_stripes < 2) + if (num_stripes < min_stripes) return -ENOSPC; - min_stripes = 2; } if (type & BTRFS_BLOCK_GROUP_RAID1C3) { - num_stripes = min_t(u64, 3, + min_stripes = 3; + num_stripes = min_t(u64, min_stripes, btrfs_super_num_devices(info->super_copy)); - if (num_stripes < 3) + if (num_stripes < min_stripes) return -ENOSPC; - min_stripes = 3; } if (type & BTRFS_BLOCK_GROUP_RAID1C4) { - num_stripes = min_t(u64, 4, + min_stripes = 4; + num_stripes = min_t(u64, min_stripes, btrfs_super_num_devices(info->super_copy)); - if (num_stripes < 4) + if (num_stripes < min_stripes) return -ENOSPC; - min_stripes = 4; } if (type & BTRFS_BLOCK_GROUP_DUP) { num_stripes = 2; @@ -1085,32 +1085,32 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, min_stripes = 2; } if (type & (BTRFS_BLOCK_GROUP_RAID10)) { + min_stripes = 4; num_stripes = btrfs_super_num_devices(info->super_copy); if (num_stripes > max_stripes) num_stripes = max_stripes; - if (num_stripes < 4) + if (num_stripes < min_stripes) return -ENOSPC; num_stripes &= ~(u32)1; sub_stripes = 2; - min_stripes = 4; } if (type & (BTRFS_BLOCK_GROUP_RAID5)) { + min_stripes = 2; num_stripes = btrfs_super_num_devices(info->super_copy); if (num_stripes > max_stripes) num_stripes = max_stripes; - if (num_stripes < 2) + if (num_stripes < min_stripes) return -ENOSPC; - min_stripes = 2; stripe_len = find_raid56_stripe_len(num_stripes - 1, btrfs_super_stripesize(info->super_copy)); } if (type & (BTRFS_BLOCK_GROUP_RAID6)) { + min_stripes = 3; num_stripes = btrfs_super_num_devices(info->super_copy); if (num_stripes > max_stripes) num_stripes = max_stripes; - if (num_stripes < 3) + if (num_stripes < min_stripes) return -ENOSPC; - min_stripes = 3; stripe_len = find_raid56_stripe_len(num_stripes - 2, btrfs_super_stripesize(info->super_copy)); } From patchwork Wed Jun 10 12:32:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597781 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 10369618 for ; Wed, 10 Jun 2020 12:33:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC0AB20734 for ; Wed, 10 Jun 2020 12:33:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="MmH+pGxI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729139AbgFJMd0 (ORCPT ); Wed, 10 Jun 2020 08:33:26 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12377 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729123AbgFJMdW (ORCPT ); Wed, 10 Jun 2020 08:33:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792401; x=1623328401; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EhNkqgJ46efGnAO7HtDNZHOEZXR0Z++zoyYswjc/ojo=; b=MmH+pGxI4v6l7O/CYwWtmOLz7dUOXgHyDwd8wWe5R71fEoMhvKwdZHzV CNyhtJBjcIjlneoqCMX9vghY7t4rS89znTffWVR4N/jMpGEzlbaqprObP K8k35MSRSpfPeUSBPkVbVK7lJylzcAMQd8f41ax0Z30yd/CFEMb6ZiaD2 49jAy5bjSGyDpvIY2bmc8vPoC1qHmgEUAtIBtO2nD31Ym1PMOcV9l9u0O tOq4OvKK3X5u8wXVOdIrRiP6p+kv6h3zvk3iWSIEJ67kq3fj/S/HSbtIS 9iaPpZqTqlxgJ3IiYnKXU6n9KegTGktcGjB/cthITuPBxJ3XTznrMKM65 A==; IronPort-SDR: mZD2SAlArANxUZ4lg4bfYd5VFy8OxtgGWGI62p25/r/6Th7RD5+avQb+s9r/3Jo43v4YMk2G+V VJeA46Uq9kOINc8bKkRhPv7N30fgLEAxk38159FMKI2k2euAryN4GPwYXTvPzlXSwmzQRKYTNr 8NF1jp+5uOL+Tbuwo6iuYbcYR020KqGF/OuADlwmM+28gN4vlwXMDFb4lONmt7Lt6TptAp9RO/ k8/Ppul0DNjk2MgTDuW7xG7k3v+pNH7CUGoNTIKWjOmx6Pxh/cuy6/wZbeBpoiOfydQBRFhuGY 7mk= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632687" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:06 +0800 IronPort-SDR: 8veiBgNbGOdFnJYlvc/qYINC2pZaXlUSoYYVIHup7kzazk7fyuAT6WAQpUsp2zyL9qdPvtzqh9 HmrdiZKKroRNYWuscBDs8TDUsGAAnrKBo= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:32 -0700 IronPort-SDR: ayNCbeJ9OfHyM056KApBvMhh5r7B0R1RBYROPCEJzPJucH6/1VFByfMWLT4WyJW8BgzRS2vF5p 7TkWYLm9dRVg== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:05 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 02/15] btrfs-progs: simplify assignment of number of RAID stripes Date: Wed, 10 Jun 2020 21:32:45 +0900 Message-Id: <20200610123258.12382-3-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Simplify the assignment of the used number of RAID stripes in chunk allocation. For RAID Levels 0, 5, 6 and 10 we first assigned it to the number of devices in the file-system and afterwards capped it to the upper bound of max_stripes. We can just use the max() macro for this. This will help in furhter refactorings. Signed-off-by: Johannes Thumshirn --- volumes.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/volumes.c b/volumes.c index 089363f66473..2a33dc09d7e7 100644 --- a/volumes.c +++ b/volumes.c @@ -1079,16 +1079,14 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, min_stripes = 2; } if (type & (BTRFS_BLOCK_GROUP_RAID0)) { - num_stripes = btrfs_super_num_devices(info->super_copy); - if (num_stripes > max_stripes) - num_stripes = max_stripes; + num_stripes = min_t(u64, max_stripes, + btrfs_super_num_devices(info->super_copy)); min_stripes = 2; } if (type & (BTRFS_BLOCK_GROUP_RAID10)) { min_stripes = 4; - num_stripes = btrfs_super_num_devices(info->super_copy); - if (num_stripes > max_stripes) - num_stripes = max_stripes; + num_stripes = min_t(u64, max_stripes, + btrfs_super_num_devices(info->super_copy)); if (num_stripes < min_stripes) return -ENOSPC; num_stripes &= ~(u32)1; @@ -1096,9 +1094,8 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } if (type & (BTRFS_BLOCK_GROUP_RAID5)) { min_stripes = 2; - num_stripes = btrfs_super_num_devices(info->super_copy); - if (num_stripes > max_stripes) - num_stripes = max_stripes; + num_stripes = min_t(u64, max_stripes, + btrfs_super_num_devices(info->super_copy)); if (num_stripes < min_stripes) return -ENOSPC; stripe_len = find_raid56_stripe_len(num_stripes - 1, @@ -1106,9 +1103,8 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } if (type & (BTRFS_BLOCK_GROUP_RAID6)) { min_stripes = 3; - num_stripes = btrfs_super_num_devices(info->super_copy); - if (num_stripes > max_stripes) - num_stripes = max_stripes; + num_stripes = min_t(u64, max_stripes, + btrfs_super_num_devices(info->super_copy)); if (num_stripes < min_stripes) return -ENOSPC; stripe_len = find_raid56_stripe_len(num_stripes - 2, From patchwork Wed Jun 10 12:32:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597783 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44F07618 for ; Wed, 10 Jun 2020 12:33:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 269E920734 for ; Wed, 10 Jun 2020 12:33:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nx4Qeab2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729160AbgFJMd1 (ORCPT ); Wed, 10 Jun 2020 08:33:27 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12382 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727927AbgFJMdX (ORCPT ); Wed, 10 Jun 2020 08:33:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792402; x=1623328402; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4rTThLZPL/2dTjEKuvaP6/qRdu3n3nG+IXm41NpwE8c=; b=nx4Qeab2y0hKsDvMWAbuaxh7b/pINoBU04G5RTIyLvJwrV7h5JXsSdaa 1Dvgk4VSSHrVSIuRXSUbcLOyH58oC3uQh8/z96OnaDq8M64xg3Tm+Cub1 1cohtKSms34Ns9nPrEWZReplMVKILH2yrYmdzzlD63LwY0J9ZFS0qwFNb YE+X0OdY0Zhe26GDqkb1l0faydyaelv6/Tc61JdzMfJl4wGIi1BNIjzMI SfZwdVGGlJ8HvhruFv4lCxEf7NHbfpByCnL7Cw99DcUFeCDqzOV/IHmz4 s/YVehvWrTm/pLJVmFvN5+oCwStkYrZ7PSHqgSWruEBM8hR+DI1tPGBta A==; IronPort-SDR: f0et1iv0PRf+R1pmQfN7udtzDUrhzSnbnHcHMfrqhx1WpHyg3O2BifZGI3/NyBHsJ/EG907/nz k6SbVP0zQqUGc/6piBfSNIYQpoE2njAwThg7vluGDBPP52QNJ0YpcTJ86YGwU1nCi6I6IDq1QG aGg6YfGU12HXEZBbgcruEvNHUbY166eXb6F7Um8yzHVXhaBuxELqUgCU+20pSvAJEs7uBedFCE eP2DvWNtS5Ts46YNrp5R9GL1AwIc1+Qj5m9vVwohbmeR/jpQo1K1eRz+8NJlU8z1m8RTC1iux7 eoY= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632694" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:06 +0800 IronPort-SDR: VAOyevNs6qzaMzEnumfaMeYQGdp3vtwKuLyUc1hOLe2q1FgLR85nRAv1p+F0InpSV3Ugp8FzMS RvSidKcPQlAp7enn3XJexhUIKjv3M5/8Y= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:33 -0700 IronPort-SDR: EbOYOJIlm7YBbnGL+DGYgLFu0it65bLaaSuHukT6f0SY/kHE3uaDqg1vysglEPSAz9/LUB3Jii WXWLXZJD9Oyg== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:06 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 03/15] btrfs-progs: introduce alloc_chunk_ctl structure Date: Wed, 10 Jun 2020 21:32:46 +0900 Message-Id: <20200610123258.12382-4-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Introduce an alloc_chunk_ctl structure, which holds parameters to control chunk allocation. Furthermore use this throughout btrfs_alloc_chunk(). Signed-off-by: Johannes Thumshirn --- volumes.c | 140 +++++++++++++++++++++++++++++------------------------- 1 file changed, 76 insertions(+), 64 deletions(-) diff --git a/volumes.c b/volumes.c index 2a33dc09d7e7..ea3e105859da 100644 --- a/volumes.c +++ b/volumes.c @@ -148,6 +148,16 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { }, }; +struct alloc_chunk_ctl { + enum btrfs_raid_types type; + int num_stripes; + int max_stripes; + int min_stripes; + int sub_stripes; + int stripe_len; + int total_devs; +}; + struct stripe { struct btrfs_device *dev; u64 physical; @@ -1016,14 +1026,10 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 avail = 0; u64 max_avail = 0; u64 percent_max; - int num_stripes = 1; - int max_stripes = 0; - int min_stripes = 1; - int sub_stripes = 1; + struct alloc_chunk_ctl ctl; int looped = 0; int ret; int index; - int stripe_len = BTRFS_STRIPE_LEN; struct btrfs_key key; u64 offset; @@ -1031,17 +1037,23 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, return -ENOSPC; } + ctl.num_stripes = 1; + ctl.max_stripes = 0; + ctl.min_stripes = 1; + ctl.sub_stripes = 1; + ctl.stripe_len = BTRFS_STRIPE_LEN; + if (type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { if (type & BTRFS_BLOCK_GROUP_SYSTEM) { calc_size = SZ_8M; max_chunk_size = calc_size * 2; min_stripe_size = SZ_1M; - max_stripes = BTRFS_MAX_DEVS_SYS_CHUNK; + ctl.max_stripes = BTRFS_MAX_DEVS_SYS_CHUNK; } else if (type & BTRFS_BLOCK_GROUP_DATA) { calc_size = SZ_1G; max_chunk_size = 10 * calc_size; min_stripe_size = SZ_64M; - max_stripes = BTRFS_MAX_DEVS(info); + ctl.max_stripes = BTRFS_MAX_DEVS(info); } else if (type & BTRFS_BLOCK_GROUP_METADATA) { /* for larger filesystems, use larger metadata chunks */ if (info->fs_devices->total_rw_bytes > 50ULL * SZ_1G) @@ -1050,64 +1062,64 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, max_chunk_size = SZ_256M; calc_size = max_chunk_size; min_stripe_size = SZ_32M; - max_stripes = BTRFS_MAX_DEVS(info); + ctl.max_stripes = BTRFS_MAX_DEVS(info); } } if (type & BTRFS_BLOCK_GROUP_RAID1) { - min_stripes = 2; - num_stripes = min_t(u64, min_stripes, + ctl.min_stripes = 2; + ctl.num_stripes = min_t(u64, ctl.min_stripes, btrfs_super_num_devices(info->super_copy)); - if (num_stripes < min_stripes) + if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; } if (type & BTRFS_BLOCK_GROUP_RAID1C3) { - min_stripes = 3; - num_stripes = min_t(u64, min_stripes, + ctl.min_stripes = 3; + ctl.num_stripes = min_t(u64, ctl.min_stripes, btrfs_super_num_devices(info->super_copy)); - if (num_stripes < min_stripes) + if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; } if (type & BTRFS_BLOCK_GROUP_RAID1C4) { - min_stripes = 4; - num_stripes = min_t(u64, min_stripes, + ctl.min_stripes = 4; + ctl.num_stripes = min_t(u64, ctl.min_stripes, btrfs_super_num_devices(info->super_copy)); - if (num_stripes < min_stripes) + if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; } if (type & BTRFS_BLOCK_GROUP_DUP) { - num_stripes = 2; - min_stripes = 2; + ctl.num_stripes = 2; + ctl.min_stripes = 2; } if (type & (BTRFS_BLOCK_GROUP_RAID0)) { - num_stripes = min_t(u64, max_stripes, + ctl.num_stripes = min_t(u64, ctl.max_stripes, btrfs_super_num_devices(info->super_copy)); - min_stripes = 2; + ctl.min_stripes = 2; } if (type & (BTRFS_BLOCK_GROUP_RAID10)) { - min_stripes = 4; - num_stripes = min_t(u64, max_stripes, + ctl.min_stripes = 4; + ctl.num_stripes = min_t(u64, ctl.max_stripes, btrfs_super_num_devices(info->super_copy)); - if (num_stripes < min_stripes) + if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; - num_stripes &= ~(u32)1; - sub_stripes = 2; + ctl.num_stripes &= ~(u32)1; + ctl.sub_stripes = 2; } if (type & (BTRFS_BLOCK_GROUP_RAID5)) { - min_stripes = 2; - num_stripes = min_t(u64, max_stripes, + ctl.min_stripes = 2; + ctl.num_stripes = min_t(u64, ctl.max_stripes, btrfs_super_num_devices(info->super_copy)); - if (num_stripes < min_stripes) + if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; - stripe_len = find_raid56_stripe_len(num_stripes - 1, + ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 1, btrfs_super_stripesize(info->super_copy)); } if (type & (BTRFS_BLOCK_GROUP_RAID6)) { - min_stripes = 3; - num_stripes = min_t(u64, max_stripes, + ctl.min_stripes = 3; + ctl.num_stripes = min_t(u64, ctl.max_stripes, btrfs_super_num_devices(info->super_copy)); - if (num_stripes < min_stripes) + if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; - stripe_len = find_raid56_stripe_len(num_stripes - 2, + ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 2, btrfs_super_stripesize(info->super_copy)); } @@ -1116,18 +1128,18 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, max_chunk_size = min(percent_max, max_chunk_size); again: - if (chunk_bytes_by_type(type, calc_size, num_stripes, sub_stripes) > - max_chunk_size) { + if (chunk_bytes_by_type(type, calc_size, ctl.num_stripes, + ctl.sub_stripes) > max_chunk_size) { calc_size = max_chunk_size; - calc_size /= num_stripes; - calc_size /= stripe_len; - calc_size *= stripe_len; + calc_size /= ctl.num_stripes; + calc_size /= ctl.stripe_len; + calc_size *= ctl.stripe_len; } /* we don't want tiny stripes */ calc_size = max_t(u64, calc_size, min_stripe_size); - calc_size /= stripe_len; - calc_size *= stripe_len; + calc_size /= ctl.stripe_len; + calc_size *= ctl.stripe_len; INIT_LIST_HEAD(&private_devs); cur = dev_list->next; index = 0; @@ -1138,7 +1150,7 @@ again: min_free = calc_size; /* build a private list of devices we will allocate from */ - while(index < num_stripes) { + while(index < ctl.num_stripes) { device = list_entry(cur, struct btrfs_device, dev_list); ret = btrfs_device_avail_bytes(trans, device, &avail); if (ret) @@ -1154,13 +1166,13 @@ again: if (cur == dev_list) break; } - if (index < num_stripes) { + if (index < ctl.num_stripes) { list_splice(&private_devs, dev_list); - if (index >= min_stripes) { - num_stripes = index; + if (index >= ctl.min_stripes) { + ctl.num_stripes = index; if (type & (BTRFS_BLOCK_GROUP_RAID10)) { - num_stripes /= sub_stripes; - num_stripes *= sub_stripes; + ctl.num_stripes /= ctl.sub_stripes; + ctl.num_stripes *= ctl.sub_stripes; } looped = 1; goto again; @@ -1179,11 +1191,11 @@ again: key.type = BTRFS_CHUNK_ITEM_KEY; key.offset = offset; - chunk = kmalloc(btrfs_chunk_item_size(num_stripes), GFP_NOFS); + chunk = kmalloc(btrfs_chunk_item_size(ctl.num_stripes), GFP_NOFS); if (!chunk) return -ENOMEM; - map = kmalloc(btrfs_map_lookup_size(num_stripes), GFP_NOFS); + map = kmalloc(btrfs_map_lookup_size(ctl.num_stripes), GFP_NOFS); if (!map) { kfree(chunk); return -ENOMEM; @@ -1191,9 +1203,9 @@ again: stripes = &chunk->stripe; *num_bytes = chunk_bytes_by_type(type, calc_size, - num_stripes, sub_stripes); + ctl.num_stripes, ctl.sub_stripes); index = 0; - while(index < num_stripes) { + while(index < ctl.num_stripes) { struct btrfs_stripe *stripe; BUG_ON(list_empty(&private_devs)); cur = private_devs.next; @@ -1201,7 +1213,7 @@ again: /* loop over this device again if we're doing a dup group */ if (!(type & BTRFS_BLOCK_GROUP_DUP) || - (index == num_stripes - 1)) + (index == ctl.num_stripes - 1)) list_move(&device->dev_list, dev_list); ret = btrfs_alloc_dev_extent(trans, device, key.offset, @@ -1227,23 +1239,23 @@ again: /* key was set above */ btrfs_set_stack_chunk_length(chunk, *num_bytes); btrfs_set_stack_chunk_owner(chunk, extent_root->root_key.objectid); - btrfs_set_stack_chunk_stripe_len(chunk, stripe_len); + btrfs_set_stack_chunk_stripe_len(chunk, ctl.stripe_len); btrfs_set_stack_chunk_type(chunk, type); - btrfs_set_stack_chunk_num_stripes(chunk, num_stripes); - btrfs_set_stack_chunk_io_align(chunk, stripe_len); - btrfs_set_stack_chunk_io_width(chunk, stripe_len); + btrfs_set_stack_chunk_num_stripes(chunk, ctl.num_stripes); + btrfs_set_stack_chunk_io_align(chunk, ctl.stripe_len); + btrfs_set_stack_chunk_io_width(chunk, ctl.stripe_len); btrfs_set_stack_chunk_sector_size(chunk, info->sectorsize); - btrfs_set_stack_chunk_sub_stripes(chunk, sub_stripes); + btrfs_set_stack_chunk_sub_stripes(chunk, ctl.sub_stripes); map->sector_size = info->sectorsize; - map->stripe_len = stripe_len; - map->io_align = stripe_len; - map->io_width = stripe_len; + map->stripe_len = ctl.stripe_len; + map->io_align = ctl.stripe_len; + map->io_width = ctl.stripe_len; map->type = type; - map->num_stripes = num_stripes; - map->sub_stripes = sub_stripes; + map->num_stripes = ctl.num_stripes; + map->sub_stripes = ctl.sub_stripes; ret = btrfs_insert_item(trans, chunk_root, &key, chunk, - btrfs_chunk_item_size(num_stripes)); + btrfs_chunk_item_size(ctl.num_stripes)); BUG_ON(ret); *start = key.offset;; @@ -1256,7 +1268,7 @@ again: if (type & BTRFS_BLOCK_GROUP_SYSTEM) { ret = btrfs_add_system_chunk(info, &key, - chunk, btrfs_chunk_item_size(num_stripes)); + chunk, btrfs_chunk_item_size(ctl.num_stripes)); if (ret < 0) goto out_chunk; } From patchwork Wed Jun 10 12:32:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597801 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8995C90 for ; Wed, 10 Jun 2020 12:33:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68B8020734 for ; Wed, 10 Jun 2020 12:33:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="YEkJuKPE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729191AbgFJMdh (ORCPT ); Wed, 10 Jun 2020 08:33:37 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12382 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729029AbgFJMd1 (ORCPT ); Wed, 10 Jun 2020 08:33:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792406; x=1623328406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Mc3RDYS7H1E2/ipsAUwmgH4rpoWOdtnog/4ZkZS5VKI=; b=YEkJuKPEHI9thOr/JQ0uEnBoAkrU4HVv+WBu1hxR6QXcGQTL2QhbCi9M CMONdFpXz1SXN+lZ+IiFcwWCVs5JJpBWSmyj2DbUfAsrxN/SKK0paQFl7 jVfuhsRxTx1PuQJT08lmO9b0uLPL+AEBYg+L3gZIIKb7s2bJWxiMmo8el 08vyHR0oWRhBRiNpnPapzY8VTNeCvgDXqrqIj52qx3fRkDkoaSUav8027 yA2QGlqnUsMQyBwMVyJzNdk+OCADYaG+ZZVXanV4cIEtb5S4okpWITF+k U+Ii6vSAogo1f9AhRzx/XtyzL9G4Ci67q38TjJaXqjYDOI/CpSdRYzP/S w==; IronPort-SDR: zxubRt6qLDeyxtcDgg7XLGgvGnyfdY9ANHY1ItGJd97zCKBdDk+hfOTUSVj++FiD+Xu9TypXvq rQIX2/KPX/UXbCRHLsD9JMIn15T4tqmZuxEB4EaJ3mctAmNAYA2vX7udB5Nq7ZzOC+F+KRWOE4 RwarfI85QTQajl/8aeNvHzJnw6VEIlTEiqs5UAsiVqUQEdGnq0cKvAQMwrjJJTnqLrOtaQshjZ yJjP4Iw2LoG+AawchW0Kk70UaVwwSN/Z/5n9KMH3S7vKksquwwZAqeekeM4jayAWIJxv7JLGNR Ijc= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632697" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:07 +0800 IronPort-SDR: ilr5aXJgqReXOwR/hm2y6JfMTtp01j90ZixzHMljIP9U+zyM0dFyI4UUNdSbIWP0/pcSidfjrl F3FVy7sq1YedSunBwiQf7kQd5/bAmipBE= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:34 -0700 IronPort-SDR: lsrjuN+CvB6WCBbmtH5qLrHlhtVJ2xGtHNL1PHXl3nw85V4AbiiI4cXkEQPfu+iYyj0/c8TKRj LUkJX+Y4ih5Q== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:07 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 04/15] btrfs-progs: cache number of devices for chunk allocation Date: Wed, 10 Jun 2020 21:32:47 +0900 Message-Id: <20200610123258.12382-5-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Cache the total number of devices usable for chunk allocation in alloc_chunk_ctl instread of reading it from the super-block over and over again. As it's a) unlikely to have more than 4 billion devices and the result of the max_t() gets truncated to int anyways, change the max_t calls to simple max(), while we're at it. Signed-off-by: Johannes Thumshirn --- volumes.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/volumes.c b/volumes.c index ea3e105859da..539c3d8648c6 100644 --- a/volumes.c +++ b/volumes.c @@ -1042,6 +1042,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ctl.min_stripes = 1; ctl.sub_stripes = 1; ctl.stripe_len = BTRFS_STRIPE_LEN; + ctl.total_devs = btrfs_super_num_devices(info->super_copy); if (type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { if (type & BTRFS_BLOCK_GROUP_SYSTEM) { @@ -1067,22 +1068,19 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } if (type & BTRFS_BLOCK_GROUP_RAID1) { ctl.min_stripes = 2; - ctl.num_stripes = min_t(u64, ctl.min_stripes, - btrfs_super_num_devices(info->super_copy)); + ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; } if (type & BTRFS_BLOCK_GROUP_RAID1C3) { ctl.min_stripes = 3; - ctl.num_stripes = min_t(u64, ctl.min_stripes, - btrfs_super_num_devices(info->super_copy)); + ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; } if (type & BTRFS_BLOCK_GROUP_RAID1C4) { ctl.min_stripes = 4; - ctl.num_stripes = min_t(u64, ctl.min_stripes, - btrfs_super_num_devices(info->super_copy)); + ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; } @@ -1091,14 +1089,12 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ctl.min_stripes = 2; } if (type & (BTRFS_BLOCK_GROUP_RAID0)) { - ctl.num_stripes = min_t(u64, ctl.max_stripes, - btrfs_super_num_devices(info->super_copy)); + ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); ctl.min_stripes = 2; } if (type & (BTRFS_BLOCK_GROUP_RAID10)) { ctl.min_stripes = 4; - ctl.num_stripes = min_t(u64, ctl.max_stripes, - btrfs_super_num_devices(info->super_copy)); + ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; ctl.num_stripes &= ~(u32)1; @@ -1106,8 +1102,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } if (type & (BTRFS_BLOCK_GROUP_RAID5)) { ctl.min_stripes = 2; - ctl.num_stripes = min_t(u64, ctl.max_stripes, - btrfs_super_num_devices(info->super_copy)); + ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 1, @@ -1115,8 +1110,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } if (type & (BTRFS_BLOCK_GROUP_RAID6)) { ctl.min_stripes = 3; - ctl.num_stripes = min_t(u64, ctl.max_stripes, - btrfs_super_num_devices(info->super_copy)); + ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 2, From patchwork Wed Jun 10 12:32:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597799 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52BF3618 for ; Wed, 10 Jun 2020 12:33:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3824820734 for ; Wed, 10 Jun 2020 12:33:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="a+TNompD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729193AbgFJMdi (ORCPT ); Wed, 10 Jun 2020 08:33:38 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12377 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729144AbgFJMdX (ORCPT ); Wed, 10 Jun 2020 08:33:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792402; x=1623328402; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6KYnZrg9iPjRo4w2i+VT65N1zKUg+5T2AWHqxxaE2aU=; b=a+TNompDMPUl3W7oEIhDNr7vhLuN1KRNrHguJtj1vmwpni5z/RR9eT3N J2FMqooCqNsVvbtgVUyzfLn3nQ/eqn+in3AakImQqaWqz0NYCsLoreOVV sxoFZPuxNgi72I6l8t/rKzLUH9mypmzsjHnK0WqXXgdnfutz+AeqniR/f xBzjSJpoyjVRxSrSQTVwFbXohOY1oCqNuYF0FH/KObLddCJYH8+2AwrqC DJd/OQnY+vqKNvLqpiNSn35kFMh+XEm1NjlgeOOhmCcp8OUeeDlQ8hvVv lid3R22RLo478k52BVLEdjJU5uBNQNqeoU4dH62Yw/xmOk1SKFTbUsFjG Q==; IronPort-SDR: Laqwg2hOd8tRTd41q2r3cUF846OqSdjtmyz45Ley6ajdpW/3lV0W42oPw7ORWPAjJ4gIaGOgM1 nwOvCUtfRi9WaiDvXk/0Em3jOb/KZqBlmxc/4TiPmEYQnMYxjo0OpPtewmQN/Czb5qM2Tl+fD1 NIxZyrSSo7TId4VA11k1DGIKKVbR9FJPx+i/voLiFTQyBwm7BICbmaYHDxy0LHoPEVF3fy99QX rRAN/5BMqQW4XJu/WzUd88WkIPdArG0325eJyvn6xUP5nQYnyoaaYMVePbOzg1KwEDP+WeTtIt RSU= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632698" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:08 +0800 IronPort-SDR: LqnG0rT9Gshx0PELFbTCVWi7PcdP6ucb39l8wcD10y0rPS552BVY0snYdv8qt23xkR66RhaQHJ jXLXdn0M8APB8C2YvfNhgaJQW+6w9VZxE= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:35 -0700 IronPort-SDR: 0/GoCiBD4xQzZBjqr5n7oIbKRPdr7G9OBvzLh+F473kfyc2vx4drgGWcm2sstJEGC5kBEaez3r LVFBKW0LWCnw== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:07 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 05/15] btrfs-progs: pass alloc_chunk_ctl to chunk_bytes_by_type Date: Wed, 10 Jun 2020 21:32:48 +0900 Message-Id: <20200610123258.12382-6-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Pass the whole alloc_chunk_ctl to chunk_bytes_by_type instead of its num_stripes and sub_stripes members. Signed-off-by: Johannes Thumshirn --- volumes.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/volumes.c b/volumes.c index 539c3d8648c6..04bc3d19a025 100644 --- a/volumes.c +++ b/volumes.c @@ -883,21 +883,21 @@ int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key, return 0; } -static u64 chunk_bytes_by_type(u64 type, u64 calc_size, int num_stripes, - int sub_stripes) +static u64 chunk_bytes_by_type(u64 type, u64 calc_size, + struct alloc_chunk_ctl *ctl) { if (type & (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_DUP)) return calc_size; else if (type & (BTRFS_BLOCK_GROUP_RAID1C3 | BTRFS_BLOCK_GROUP_RAID1C4)) return calc_size; else if (type & BTRFS_BLOCK_GROUP_RAID10) - return calc_size * (num_stripes / sub_stripes); + return calc_size * (ctl->num_stripes / ctl->sub_stripes); else if (type & BTRFS_BLOCK_GROUP_RAID5) - return calc_size * (num_stripes - 1); + return calc_size * (ctl->num_stripes - 1); else if (type & BTRFS_BLOCK_GROUP_RAID6) - return calc_size * (num_stripes - 2); + return calc_size * (ctl->num_stripes - 2); else - return calc_size * num_stripes; + return calc_size * ctl->num_stripes; } @@ -1122,8 +1122,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, max_chunk_size = min(percent_max, max_chunk_size); again: - if (chunk_bytes_by_type(type, calc_size, ctl.num_stripes, - ctl.sub_stripes) > max_chunk_size) { + if (chunk_bytes_by_type(type, calc_size, &ctl) > max_chunk_size) { calc_size = max_chunk_size; calc_size /= ctl.num_stripes; calc_size /= ctl.stripe_len; @@ -1196,8 +1195,7 @@ again: } stripes = &chunk->stripe; - *num_bytes = chunk_bytes_by_type(type, calc_size, - ctl.num_stripes, ctl.sub_stripes); + *num_bytes = chunk_bytes_by_type(type, calc_size, &ctl); index = 0; while(index < ctl.num_stripes) { struct btrfs_stripe *stripe; From patchwork Wed Jun 10 12:32:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597785 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F160A90 for ; Wed, 10 Jun 2020 12:33:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8C6C206F4 for ; Wed, 10 Jun 2020 12:33:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="NkFj5KZu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729163AbgFJMd2 (ORCPT ); Wed, 10 Jun 2020 08:33:28 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12387 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729132AbgFJMdX (ORCPT ); Wed, 10 Jun 2020 08:33:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792402; x=1623328402; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L8BYYhaHvR8L94NHP6LD6IUYo11rykcnRkK/lj/vwuY=; b=NkFj5KZuxCd2q7P2m2NxNa+W1UsX0X4eJcrNm2oVCOCKzX/XMtdiQ2n1 hmEMT7IXt1QqLPhUi05wuud4abB67QtYpG/D+gTVo1PfvLj7nZ82EKrPd XB/NmqcDa3bc0Js+TSfK33fNeSam5S2IY7iqtj2OlIh9KB1xuZX7tFhfR BN/KE08FkY7OTCokWDv7nlj9IpkqjG5bPCcm+tTjTHEJ8bXwjByC9mGUy 79ubGCT2VRBWw/IjHXzxh4i4cvNRd4dRnp0ip4W4sfe/N9nT87UkrTPWg cMYRT6RMPR2zcPZ9fhwH2OWyFLlQEoHhVJH6rz/eSHk9rRaJnIK03FV9A A==; IronPort-SDR: BLPwshydLYdUWlRR8ro4BK5qYQPWhkGziJJIZdlRIbk4wpqhNny4GPtwdnRpKe8JEOwEabhWtc 70JZwXCMHukv+m2e6UOGTUTo2yVFO8N1Wp+dti2b4TnfX/O3N/gAEFUXXGsY6EE9mqC5WsI5Eg x0hqcYkQM/YWXs27FWSgSORt9gIyz8jEBQ+G/RBzYSrofsBbuIIqbTAhafrLZRf1rQlN7kitNn M7pfS26/7qVq3WjUHmcf8NUKo0scd4kHj3nslNQhah/QFO7UZsfMnwkw81Hd9DSX/GEFj4+Bex gNw= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632700" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:09 +0800 IronPort-SDR: J6QPrcS/eJ2t6bP0b9AM/5WTuhz8c8NLGg7MuOEkB21Bu3Yjz1n5JOOgF1SIktY5ra3Mj98ohU 4g7hrzpyvhLvgC05j1iKS8389QzOP7V1s= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:36 -0700 IronPort-SDR: tWRTpkOLqqYAQUqiqSrhp78rD1kECHyt/Eip1yt3ee0qaHJJDX6QDV2Eva6Me/0+Qz1TjwYk7Y I52BqAd8hIWg== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:08 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 06/15] btrfs-progs: introduce raid profile table for chunk allocation Date: Wed, 10 Jun 2020 21:32:49 +0900 Message-Id: <20200610123258.12382-7-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Introduce a table holding the paramenters for chunk allocation per RAID profile. Also convert all assignments of hardcoded numbers to table lookups in this process. Further changes will reduce code duplication even more. Signed-off-by: Johannes Thumshirn --- volumes.c | 95 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/volumes.c b/volumes.c index 04bc3d19a025..fc14283db2bb 100644 --- a/volumes.c +++ b/volumes.c @@ -1005,6 +1005,68 @@ error: - 2 * sizeof(struct btrfs_chunk)) \ / sizeof(struct btrfs_stripe) + 1) +static const struct btrfs_raid_profile { + int num_stripes; + int max_stripes; + int min_stripes; + int sub_stripes; +} btrfs_raid_profile_table[BTRFS_NR_RAID_TYPES] = { + [BTRFS_RAID_RAID10] = { + .num_stripes = 0, + .max_stripes = 0, + .min_stripes = 4, + .sub_stripes = 2, + }, + [BTRFS_RAID_RAID1] = { + .num_stripes = 0, + .max_stripes = 0, + .min_stripes = 2, + .sub_stripes = 1, + }, + [BTRFS_RAID_RAID1C3] = { + .num_stripes = 0, + .max_stripes = 0, + .min_stripes = 3, + .sub_stripes = 1, + }, + [BTRFS_RAID_RAID1C4] = { + .num_stripes = 0, + .max_stripes = 0, + .min_stripes = 4, + .sub_stripes = 1, + }, + [BTRFS_RAID_DUP] = { + .num_stripes = 2, + .max_stripes = 0, + .min_stripes = 2, + .sub_stripes = 1, + }, + [BTRFS_RAID_RAID0] = { + .num_stripes = 0, + .max_stripes = 0, + .min_stripes = 2, + .sub_stripes = 1, + }, + [BTRFS_RAID_SINGLE] = { + .num_stripes = 1, + .max_stripes = 0, + .min_stripes = 1, + .sub_stripes = 1, + }, + [BTRFS_RAID_RAID5] = { + .num_stripes = 0, + .max_stripes = 0, + .min_stripes = 2, + .sub_stripes = 1, + }, + [BTRFS_RAID_RAID6] = { + .num_stripes = 0, + .max_stripes = 0, + .min_stripes = 3, + .sub_stripes = 1, + }, +}; + int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, struct btrfs_fs_info *info, u64 *start, u64 *num_bytes, u64 type) @@ -1037,6 +1099,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, return -ENOSPC; } + ctl.type = btrfs_bg_flags_to_raid_index(type); ctl.num_stripes = 1; ctl.max_stripes = 0; ctl.min_stripes = 1; @@ -1066,50 +1129,50 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ctl.max_stripes = BTRFS_MAX_DEVS(info); } } - if (type & BTRFS_BLOCK_GROUP_RAID1) { - ctl.min_stripes = 2; + if (ctl.type == BTRFS_RAID_RAID1) { + ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; } - if (type & BTRFS_BLOCK_GROUP_RAID1C3) { - ctl.min_stripes = 3; + if (ctl.type == BTRFS_RAID_RAID1C3) { + ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; } - if (type & BTRFS_BLOCK_GROUP_RAID1C4) { - ctl.min_stripes = 4; + if (ctl.type == BTRFS_RAID_RAID1C4) { + ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; } - if (type & BTRFS_BLOCK_GROUP_DUP) { + if (ctl.type == BTRFS_RAID_DUP) { ctl.num_stripes = 2; - ctl.min_stripes = 2; + ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; } - if (type & (BTRFS_BLOCK_GROUP_RAID0)) { + if (ctl.type == BTRFS_RAID_RAID0) { ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); - ctl.min_stripes = 2; + ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; } - if (type & (BTRFS_BLOCK_GROUP_RAID10)) { - ctl.min_stripes = 4; + if (ctl.type == BTRFS_RAID_RAID10) { + ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; ctl.num_stripes &= ~(u32)1; ctl.sub_stripes = 2; } - if (type & (BTRFS_BLOCK_GROUP_RAID5)) { - ctl.min_stripes = 2; + if (ctl.type == BTRFS_RAID_RAID5) { + ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 1, btrfs_super_stripesize(info->super_copy)); } - if (type & (BTRFS_BLOCK_GROUP_RAID6)) { - ctl.min_stripes = 3; + if (ctl.type == BTRFS_RAID_RAID6) { + ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; From patchwork Wed Jun 10 12:32:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597795 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9167C14B7 for ; Wed, 10 Jun 2020 12:33:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E3CC206F4 for ; Wed, 10 Jun 2020 12:33:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="evwtSpgJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729077AbgFJMdc (ORCPT ); Wed, 10 Jun 2020 08:33:32 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12377 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729123AbgFJMd1 (ORCPT ); Wed, 10 Jun 2020 08:33:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792406; x=1623328406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qzzRJdE+MntvzoAexva4Z2kK9WR740g/z7oKcJNOyrc=; b=evwtSpgJh3c7pLhF1pda3Oq0nz8cdqvrLW1NaKPOsKoZ5IdS/VuL2Kaz AWLdEJIOGkrqts8ubh40/mC8MSNGZ52oNE8p5wUGGQOgqDwiLovN0Ul71 Z/oSUdE33cSBL3j9kEWwJIflJnFzMx+OpKpvtXeW0+JS+LWd0x7hGWtzr E0YEZYxZtKuEIsNi8sBEmB9Rof+f5ITs5PFRGK50MkUEm0CwE/OX7kDqB bhkl4KbNh1dujOzzho9j3RIaFSBIyaK/2P2SKfOOUfd94H8RudthZIxvw loUQnN1Uc4llm+/ZeFqIwMMorD/cJye6EP1lvG9SKTH2lkVRehoHfilz3 g==; IronPort-SDR: uWF4OlQFe0DKQTGshn9122eoZvzaQo1nUdFg5zaA+xyZFAj54jCieMVmWtMlerZ3ZANFH3QPsr HWs9WGdvddi00Eu83LZfrQIW9foziYkKvLRqCr5aJQLBtk/sov2zUi14WYTvDKwVvIFhMfa4tz djZb3015IVZuxOqwvgoBn8QfMCjeATttfYmaUVFRqB3D4I4RRgf0SEhqtf0bN7speq6XapxWyW fxZwrLilkD3+GTmt0qCP5wVVucJLVubkPzKG9oTHdeMFyV+OiV9tktfhqzx/Brt4GM76O74GJA Mog= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632702" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:10 +0800 IronPort-SDR: XStrOIub+Z2hmHtR4C8TiwcAwPS4ori3WWbEqJMIuVdy1kjaCrXtwWp8jsGUPGZq+V68uOAfML TjvZU4UF4J8A7tOszfncnjCfbSIj9+TPw= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:36 -0700 IronPort-SDR: 21O1i4L+j2WcdjZYbSEeFgg1UPRtwZBV7wpJ6ouJeAIpvzheyuKe6R2CbHJf4oWxZLvMl50+e9 PVT9c+1NMSpQ== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:09 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 07/15] btrfs-progs: consolidate assignment of minimal stripe number Date: Wed, 10 Jun 2020 21:32:50 +0900 Message-Id: <20200610123258.12382-8-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we have a table holding the min_stripes value we can consolidate all setting of alloc_chunk_ctl::min_stripes to a signle table lookup. Signed-off-by: Johannes Thumshirn --- volumes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/volumes.c b/volumes.c index fc14283db2bb..9076f055f6bd 100644 --- a/volumes.c +++ b/volumes.c @@ -1102,7 +1102,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ctl.type = btrfs_bg_flags_to_raid_index(type); ctl.num_stripes = 1; ctl.max_stripes = 0; - ctl.min_stripes = 1; + ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.sub_stripes = 1; ctl.stripe_len = BTRFS_STRIPE_LEN; ctl.total_devs = btrfs_super_num_devices(info->super_copy); @@ -1149,7 +1149,6 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } if (ctl.type == BTRFS_RAID_DUP) { ctl.num_stripes = 2; - ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; } if (ctl.type == BTRFS_RAID_RAID0) { ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); From patchwork Wed Jun 10 12:32:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597791 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7FCA2618 for ; Wed, 10 Jun 2020 12:33:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5DAF920734 for ; Wed, 10 Jun 2020 12:33:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="R75EmNR/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729185AbgFJMde (ORCPT ); Wed, 10 Jun 2020 08:33:34 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12382 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729162AbgFJMd2 (ORCPT ); Wed, 10 Jun 2020 08:33:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792408; x=1623328408; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1FcJZjdTxkREy1X3S1iMZVT1/faVLCWruKgGFYb/ZC0=; b=R75EmNR/3wOGZ3kIhf2BZBZArb08wSkMWLED+a9SqbWTHVUCHMLh+zMc mJK5gQAV/CNbr7PdUT3rwgq77P5KV7WVd1FzNV3jjlhp6cLd2gbNwdt31 1WM170NdFYzNuczLkW+1qK0Jg1QNtQucrZo8k6KDr4zpeRedHWvRj96T9 glEfBdETj5sSPeGCv1MaAOR1EAhSsz7ay/aw4BCw4HDYsviVYewkYgMQy C5PrI8GXv+uPZWb+W7aHZ2IYOyOHItIYNSRqvhLHi0mwhJQTCGgq7/A/D p6ap8v84dG4pR9icpx5XnTmZLD5DCRoReyAaZDFfX/BZgYUxdrvAmsQuj g==; IronPort-SDR: lmP7C+4yCTg+p+mQ6gbPbQLGQ4Il1vWnI0kSwdQ24vmxyvIOTxoR4KZYqIxREPBIKDhwUEvVnI xoeuHx5ZMFSYKt7Gblcuw4dXWWc20Zjt/Ge02BU0c1EmL7bbVGM2LOufxH7S2LLz7vIj+iXZCS 5ikLV8aALMCv/ARczvfhirweh95MiDLSxyaPiIL9n+hDcJs5uSi5owqFiTpAENkjmeaPfe6rhK LGQTymBh9ZFZE9SI2hyxtAIv6JHB/0UZxO96G46QNjbfWIL/DlFkijpxuz3NhCLO0txMGegnvP a8g= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632704" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:10 +0800 IronPort-SDR: 0J+8dcHfm14vs+vKLGQqKmRX/zqvP+8vN+R/IcTplJdLzVEl6G/R34yqUhwGkttOIDW8FnqWa1 OeXQPiGYj79cLAOHbYqQyC86rI9Q+3uts= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:37 -0700 IronPort-SDR: /JsKXHT7rUjMF/iLqa/ptNDUInm1cghCnBjoXrMvgHx7y8iOdvgzf7k1C20gMrwMJP9wtpxukA 2cXi+vBlvx/Q== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:10 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 08/15] btrfs-progs: consolidate assignment of sub_stripes Date: Wed, 10 Jun 2020 21:32:51 +0900 Message-Id: <20200610123258.12382-9-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we have a table holding the sub_stripes value we can consolidate all setting of alloc_chunk_ctl::sub_stripes to a signle table lookup. Signed-off-by: Johannes Thumshirn --- volumes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/volumes.c b/volumes.c index 9076f055f6bd..32d3dfe0decd 100644 --- a/volumes.c +++ b/volumes.c @@ -1103,7 +1103,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ctl.num_stripes = 1; ctl.max_stripes = 0; ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; - ctl.sub_stripes = 1; + ctl.sub_stripes = btrfs_raid_profile_table[ctl.type].sub_stripes; ctl.stripe_len = BTRFS_STRIPE_LEN; ctl.total_devs = btrfs_super_num_devices(info->super_copy); @@ -1160,7 +1160,6 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; ctl.num_stripes &= ~(u32)1; - ctl.sub_stripes = 2; } if (ctl.type == BTRFS_RAID_RAID5) { ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; From patchwork Wed Jun 10 12:32:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597797 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7BF97618 for ; Wed, 10 Jun 2020 12:33:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62C6320734 for ; Wed, 10 Jun 2020 12:33:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="ClT8Bpeq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729189AbgFJMdg (ORCPT ); Wed, 10 Jun 2020 08:33:36 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12387 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729167AbgFJMda (ORCPT ); Wed, 10 Jun 2020 08:33:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792409; x=1623328409; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+wYOK9PdQ86NW6Tz668h2RFa7WrtjJbcYjd1zVmH5e4=; b=ClT8BpeqKVKl/wIK/ryqFok4id9I2pIUrT4k5oLpIThxMujlnRZlBQs1 aA9hmC5hPqohXVEVn5CoxOnxxFBsfB7ADzUoge9+SWQFrXlC6y6zKPrHn uZ7t3/EGY5aqKcJc4dlX44kr47celfPMTY+40HmdadhDbB+qJKTMtN9V4 q9GUY192TBHQ52acajmkOOgW+ijJFVy/+fGJe23E2k+cRt4jMUyzuYtwL xkI1IoRxkbJ6guT2SzA3B1sN9aC12JWgvgIZeTxJQGBiXVN4Aawg41r9I JIaXxIJ2GACq4ES9FJwLzenSTI6l0Gcvf23p1KCdPJ0foZz4sWCJ9nUgn A==; IronPort-SDR: rzAOltaFBZgxZhZ3qLYFbKUoJsbrBi39cewUR7dY5ItWSYepo9yLITeRVemmPt/VW0+owCkM0V JupYKeLnFJTJ+oPWQ2mBw3B3XisDN8ZR79KZ169IpWflccvVGEdWOfbqpqirntof65CHv+mGaV 2gS2enah24jZ1ULGFK9ooaT1oEswgpQM+Q/0Crwgz1Q5V9UYkoU4Xy6Wse0jvXRqdMII8wf1bG Vx6MXxIMkcd6Dxbo5rxxHDv+FERuPqYrG3oZEr5QhIUYlA7vkPszaI1OLZ46pT0pZxZJ8cdAqk xvM= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632705" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:11 +0800 IronPort-SDR: HO3BKIaBpmwE0SM/SNbCFuzgF2Ov4FJ9TkRi9pbYfwfD1BNrd5vGeQTbgJQS5jm4XkXbZH4sJb G2O2pdcpdJF2/2KScPHNEL1M8uQgkNMoU= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:38 -0700 IronPort-SDR: bd0YcKy+Y1lYOtmxB2nbnN+3QTCQBoCuynLt8gQhJrJlKXV4YifkSHu7H4LKQVtBYfsnOPAd95 jIFiq36H1lsQ== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:11 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 09/15] btrfs-progs: consolidate setting of RAID1 stripes Date: Wed, 10 Jun 2020 21:32:52 +0900 Message-Id: <20200610123258.12382-10-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org All 3 different RAID1 profiles use the same calculation mehod for the number of used stripes. Now that we do table lookups fo rmost of the allocation control parameters, we can consolidate all 3 RAID1 profiles into a single branch for the calculation. Signed-off-by: Johannes Thumshirn --- volumes.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/volumes.c b/volumes.c index 32d3dfe0decd..24e6d151c313 100644 --- a/volumes.c +++ b/volumes.c @@ -1129,20 +1129,9 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ctl.max_stripes = BTRFS_MAX_DEVS(info); } } - if (ctl.type == BTRFS_RAID_RAID1) { - ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; - ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); - if (ctl.num_stripes < ctl.min_stripes) - return -ENOSPC; - } - if (ctl.type == BTRFS_RAID_RAID1C3) { - ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; - ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); - if (ctl.num_stripes < ctl.min_stripes) - return -ENOSPC; - } - if (ctl.type == BTRFS_RAID_RAID1C4) { - ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; + if (ctl.type == BTRFS_RAID_RAID1 || + ctl.type == BTRFS_RAID_RAID1C3 || + ctl.type == BTRFS_RAID_RAID1C4) { ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; From patchwork Wed Jun 10 12:32:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597787 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F4EE90 for ; Wed, 10 Jun 2020 12:33:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CC6D20734 for ; Wed, 10 Jun 2020 12:33:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="BUJswjB9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729178AbgFJMdb (ORCPT ); Wed, 10 Jun 2020 08:33:31 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12387 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729157AbgFJMd1 (ORCPT ); Wed, 10 Jun 2020 08:33:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792407; x=1623328407; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X9E6tK44PGKIni2Q6yn3QbbsKzgzvGhWgKp3QaiFbMk=; b=BUJswjB9H/M38tCqHcLIUDUZk4PpHwAPL0vCeUDdRQ7f/oNaf4B2MzJO BpMT6pATVVX5UIhYF+FzzcVnR/nRWjEMK+Gm4oRprQ6fyIbRlfvDRt6i1 ym0TOL/BRjcbgeucIXU5NmzrsOz5K8Ie+r4C+K6/x2FRrUGkq7OjMcat1 7egqmOPJcH0v6/s81TDrZZT946UV1CR3T0ypSBEFKtU1UDv38oqoXn4LW wQLr5ojj9AGFxDH2AHXi2a0/roJV72EOWn2pswhmhWoxnzrizQituzDWg thFAs2SyE/aHissa2Qvs+p+TNefVwP46LV8L6cG03Mso/WhQ2FPa7LK0w g==; IronPort-SDR: I5e3+wMF7OCuYP8pNedjo67rA5Qx9ZluIB33dQm22hmvIH78nsu9K7C32E6U56D/pl+VSCfBfP 55skP+1b1d7Xfi/B8y+0JcadOBEH22qxRKDkhUica04h6L6Xm7hdXhcKTKonQ9+f/NKR2FalVf nwvpgpSIBIkeMEBYTl/rtbQC005PyGrYw1RZHSbSTnCLhPeS7RazbnChXPkmPsn0pWvf8BxfSV yXX6Q1koiYmZau7crxP/th/zAAXV3zjfjIu53RZaNqVjVVnlWNKi6YCliYM0oad6MDxDm9q5aj xvU= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632707" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:12 +0800 IronPort-SDR: RQYvr3YgX/35mAIx2hU7x7vR3dKVETfqF5O2Xnn14GjGBi/TdAEtn2agkpePsSD7LI0K5sZ28Z xItpmb2poAhytjqbKF/GOE082xz0ganRo= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:39 -0700 IronPort-SDR: V9oL1899rhMWZ42nAlKmVWuG+bR38ipg8fiB8BH28nVxfgV5Qa1TVoYxgCWIWeOd2o8X54wQ+j deVQ8/MOysqw== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:11 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 10/15] btrfs-progs: do table lookup for simple RAID profiles' num_stripes Date: Wed, 10 Jun 2020 21:32:53 +0900 Message-Id: <20200610123258.12382-11-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org For the two simple "RAID" profiles single and dup, we can simply fallback to a table lookup to get num_stripes. Signed-off-by: Johannes Thumshirn --- volumes.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/volumes.c b/volumes.c index 24e6d151c313..80b4b373f012 100644 --- a/volumes.c +++ b/volumes.c @@ -1100,7 +1100,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } ctl.type = btrfs_bg_flags_to_raid_index(type); - ctl.num_stripes = 1; + ctl.num_stripes = btrfs_raid_profile_table[ctl.type].num_stripes; ctl.max_stripes = 0; ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.sub_stripes = btrfs_raid_profile_table[ctl.type].sub_stripes; @@ -1136,9 +1136,6 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; } - if (ctl.type == BTRFS_RAID_DUP) { - ctl.num_stripes = 2; - } if (ctl.type == BTRFS_RAID_RAID0) { ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; From patchwork Wed Jun 10 12:32:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597789 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2595C618 for ; Wed, 10 Jun 2020 12:33:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0856A206F4 for ; Wed, 10 Jun 2020 12:33:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="ggemvFnN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729182AbgFJMdd (ORCPT ); Wed, 10 Jun 2020 08:33:33 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12377 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729132AbgFJMd3 (ORCPT ); Wed, 10 Jun 2020 08:33:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792408; x=1623328408; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oMfoutGETTP0olztKA64IXtyFkR9BV6V/NZVlxq+TJw=; b=ggemvFnNM++pavZHt46LpKnVZCzo2HT43Ep6HRZmWeY0U0h+cbu8yti7 PZzZlOtqIZTup7H/cQNAFgkvRWVV64vCGMZPFV4R8r9xbqe94gKIzIrIz pbQjmAlp431yKSxsvEvaBpV9ljB2bolZ0BhwIIo4ZyYA/zbGPm9O/cwl/ MB3aEGGLAul7mabAG6RoUK4mzbg1IBERB2aWkasq6KV7S+IwanW5stdXn cbty0zLO8hy7pzueGnUcNX9iQw/R9DwfSoDKoBX13nmfO+Id4cZNwxzqJ dEklVIpp+io5kMZ5dJiyIyHnHcauTGx0PeBu7401dirJn0OeuPj4v+8AJ A==; IronPort-SDR: X0T7O/xREKT7rk831JGLqqxKPjGaHlpggEpoK2nzMaQTdexPEILmsCizRWO0RBv66zP4xpxtj2 eC9FbBodMU0M0B2TTD6m+Vaj7XSgSPWprbH5OTgMNy7SdkFW1z0ODS7zWN8kf53b3biRGn7TlB bpmeSXwCnVRxNZL3m8FqlXqjlWN2SfYebcBXPQVPuHkBm4dCReLnikdIOT44RznIZA+L30ql3U tbDPactKVTN34yLYiwRkZQYjgvWIsoNGPzecgJ9KGyP6MnFFSW8QwXMpQ+6PgvTjwe2pEv+Me2 YCQ= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632709" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:13 +0800 IronPort-SDR: SMv6d/trapU147e4PXveToQTpOlVS6O6Gbc0eFlWQC/HHnAAdPZbDoissDIZm1SSsFnuD/M83W x35RNhuXlpzD6YJfcphs9rSamiFZTFZNc= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:40 -0700 IronPort-SDR: hzT8yQZfP3dobmkE53s8/dkyt5pYh3sx0X+fEK/fFbH1snxAHmw6cNV6vJ06Po7aWpZws6kNo8 gO2Sg/7619FQ== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:12 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 11/15] btrfs-progs: consolidate num_stripes sanity check Date: Wed, 10 Jun 2020 21:32:54 +0900 Message-Id: <20200610123258.12382-12-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org For all RAID profiles in btrfs_alloc_chunk() we're doing a sanity check if the number of stripes is smaller than the minimal number of stripes needed for this profile. Consolidate this per-profile check to a single check after assigning the number of stripes to further reduce code. Signed-off-by: Johannes Thumshirn --- volumes.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/volumes.c b/volumes.c index 80b4b373f012..80144a763b72 100644 --- a/volumes.c +++ b/volumes.c @@ -1133,36 +1133,27 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ctl.type == BTRFS_RAID_RAID1C3 || ctl.type == BTRFS_RAID_RAID1C4) { ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); - if (ctl.num_stripes < ctl.min_stripes) - return -ENOSPC; } if (ctl.type == BTRFS_RAID_RAID0) { ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; } if (ctl.type == BTRFS_RAID_RAID10) { - ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); - if (ctl.num_stripes < ctl.min_stripes) - return -ENOSPC; ctl.num_stripes &= ~(u32)1; } if (ctl.type == BTRFS_RAID_RAID5) { - ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); - if (ctl.num_stripes < ctl.min_stripes) - return -ENOSPC; ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 1, btrfs_super_stripesize(info->super_copy)); } if (ctl.type == BTRFS_RAID_RAID6) { - ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); - if (ctl.num_stripes < ctl.min_stripes) - return -ENOSPC; ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 2, btrfs_super_stripesize(info->super_copy)); } + if (ctl.num_stripes < ctl.min_stripes) + return -ENOSPC; /* we don't want a chunk larger than 10% of the FS */ percent_max = div_factor(btrfs_super_total_bytes(info->super_copy), 1); From patchwork Wed Jun 10 12:32:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597807 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83E76618 for ; Wed, 10 Jun 2020 12:33:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BC6420734 for ; Wed, 10 Jun 2020 12:33:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="jj48q9xw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729195AbgFJMdj (ORCPT ); Wed, 10 Jun 2020 08:33:39 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12382 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729168AbgFJMda (ORCPT ); Wed, 10 Jun 2020 08:33:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792409; x=1623328409; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hSbU88BxRVzAR6Lx9GsMNeT0Ej/jclkKY5xRxSd8v0Q=; b=jj48q9xwNEkGm4rFcNAJ5BqI0cI1Q/AQXigHoDwRyLsZcOgLIlWg9pfr gNhA+womChzUTpAFhU6AwMUGrOIR1U0IuSjz0Gwsh0b9ty3zMAiaY0BIK eFIS6JoA2TlR0ZhP/ND2b8Sew1+bLMhsuu+H8DFeyLvboDvzOyDcQlxlV UVl48tKXNb6/V4Fv4kZmsBunG9PeY6rGilOleEKDwMQ8pXkAUc/h3zDt/ 4zBIll/jp73x39AqIfZNHUxn3Ew64IWPKYHREwPQ0+FHeSbDGVGxy7esw TdvUFETBUMRLnp3wyocHZ5Wok5wQV0KKVcHyet8jCtUiRwgedOds2VtXa Q==; IronPort-SDR: CaPg0IfP3IggowjlnadT7QaLUTscdsaUfsth3IYJ39by3FRIFnkfmlfPS/EYegNjYYiFS0hw6d Ysk4JElF9QYxZspIcyzB9f2/J1x02otD0Abohpx/BF47q3EEej2cKMWGWeYLt0MaxjzRHJ2DZU Lhb6bVN5LHEKiFqDJQSmOyElwB8fIscbtYTjTRj1xV/VgDYVNQkf8MbO7IRnVhr60G/h+hNx6m Ixr5itZ0g7Y/jB65bq4ZaqQ62sb0+d3rEJ9clqiFA1T/zrtxc8SRQSWMexgrwzzU7edQW66py6 opM= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632711" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:14 +0800 IronPort-SDR: 2Hhz4QqM3sRXOkJYn7ZCinjapLXNRynH54WdO56it/tRx014qe8WLqoNmvFXC7eUpVkZQBBpMx 7yKStunlz/W+82T6FGvA41PBIpysW8rTg= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:40 -0700 IronPort-SDR: ZAeCQ6IQFtWsUryKfJdfll4n4v+R+eN2DNpiC074nbErL+uGyxLosDw7qA/JePEWewDF77+nBY P6nHWZtoDElw== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:13 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 12/15] btrfs-progs: compactify num_stripe setting in btrfs_alloc_chunk Date: Wed, 10 Jun 2020 21:32:55 +0900 Message-Id: <20200610123258.12382-13-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that most of the RAID profile dependent chunk allocation parameters have been converted to table lookus and moved out of the if-statement maze, all that remains is the actual calculation of the number of stripes. Compact the 5 if statements into a single switch statemnt to make the code a bit more compact and more intuitive to follow. Signed-off-by: Johannes Thumshirn --- volumes.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/volumes.c b/volumes.c index 80144a763b72..57d0db5463ef 100644 --- a/volumes.c +++ b/volumes.c @@ -1129,28 +1129,31 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ctl.max_stripes = BTRFS_MAX_DEVS(info); } } - if (ctl.type == BTRFS_RAID_RAID1 || - ctl.type == BTRFS_RAID_RAID1C3 || - ctl.type == BTRFS_RAID_RAID1C4) { + switch (ctl.type) { + case BTRFS_RAID_RAID1: + case BTRFS_RAID_RAID1C3: + case BTRFS_RAID_RAID1C4: ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); - } - if (ctl.type == BTRFS_RAID_RAID0) { + break; + case BTRFS_RAID_RAID0: ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); - ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; - } - if (ctl.type == BTRFS_RAID_RAID10) { + break; + case BTRFS_RAID_RAID10: ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); ctl.num_stripes &= ~(u32)1; - } - if (ctl.type == BTRFS_RAID_RAID5) { + break; + case BTRFS_RAID_RAID5: ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 1, btrfs_super_stripesize(info->super_copy)); - } - if (ctl.type == BTRFS_RAID_RAID6) { + break; + case BTRFS_RAID_RAID6: ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 2, btrfs_super_stripesize(info->super_copy)); + break; + default: + break; } if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; From patchwork Wed Jun 10 12:32:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597793 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60CE590 for ; Wed, 10 Jun 2020 12:33:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4767720734 for ; Wed, 10 Jun 2020 12:33:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="NTtOUFxE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729187AbgFJMdf (ORCPT ); Wed, 10 Jun 2020 08:33:35 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12377 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729170AbgFJMda (ORCPT ); Wed, 10 Jun 2020 08:33:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792410; x=1623328410; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=47UTAKtRn8tdX1PlPox61BbXGfDryG3zyq36HRS9mDo=; b=NTtOUFxEyvjOVJQ034pKGswePyhTTJ1YYcXZqqa+75ThzeDtBcf95aiD yJLs8EXx53EY9GPYkOXmux3qbojw2/YeJvLOy3jRgNK0OUzTuUbKV7pnj wE6EBA5g5z5nNGupbMLi1jNL25tnzAr94nOCsjKLEcKnH15dUBPDr/Iux m/rXJcKW8EQHTmPuhU1D1BAOkk3Cop3fqLrzw7PYEnVaKsujTz6OUA78E uJ+tb1760t5683Un+YXw0P3XjYyVA4QQxrwsm7bQbrzNOGnX1P7BIcdYW ORAehXTrqM7aonc0uhWLuWKT6D4pPALTDpr//KmW9RQo/s3QpOnxBB3se Q==; IronPort-SDR: rSv5vbuiSObE1XqSI4QGmbPfwPnsfeUYsU8y72buOAhjnVl4jTf4LN/p5fCBjmTaNEDi8Bwzsy JCb1iWIoTtlo8rhvJy5DccKspm45WgwKQPNrjmddbYGOnSiG1trLLW58MZ7J4alpIenymsM6rv tKeF98hp3tCzJxdTAE4SarnAZ2a0bM1RY/IFNaSuum2ilc/0XzyzJjeQmm3LkB/JWC5fl+r2ZF NwxyAEaBj9lfnfdVOjYfJ182Cfzh0FSmqhwI0QLvU9SKf+iYv8+ffrL+rI5dasQYDszcIKSoaH zOE= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632713" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:14 +0800 IronPort-SDR: 9Bio1VDlhtR3tXP+pPmR7ohXi45EStB69rQfJzhaaKZnYHUeNoTqMkfrEcIrases0yYSHQuTFd A7CKdJTT52KAP0t4BXzxPryqWW4pv6Yig= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:41 -0700 IronPort-SDR: AESf7B3qjLzsktX1dMUCimJOvDKVrWOyR2dxeobAUY/J/SuTDgeWMD37HT306Ybgnq/iatSG0m l3fGGqmVqlsA== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:14 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 13/15] btrfs-progs: introduce init_alloc_chunk_ctl Date: Wed, 10 Jun 2020 21:32:56 +0900 Message-Id: <20200610123258.12382-14-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out setting of alloc_chuk_ctl fileds in a separate function init_alloc_chunk_ctl. Signed-off-by: Johannes Thumshirn --- volumes.c | 70 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/volumes.c b/volumes.c index 57d0db5463ef..aacff6e0656b 100644 --- a/volumes.c +++ b/volumes.c @@ -1067,6 +1067,44 @@ static const struct btrfs_raid_profile { }, }; +static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, + struct alloc_chunk_ctl *ctl) +{ + int type = ctl->type; + + ctl->num_stripes = btrfs_raid_profile_table[type].num_stripes; + ctl->min_stripes = btrfs_raid_profile_table[type].min_stripes; + ctl->sub_stripes = btrfs_raid_profile_table[type].sub_stripes; + ctl->stripe_len = BTRFS_STRIPE_LEN; + + switch (type) { + case BTRFS_RAID_RAID1: + case BTRFS_RAID_RAID1C3: + case BTRFS_RAID_RAID1C4: + ctl->num_stripes = min(ctl->min_stripes, ctl->total_devs); + break; + case BTRFS_RAID_RAID0: + ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs); + break; + case BTRFS_RAID_RAID10: + ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs); + ctl->num_stripes &= ~(u32)1; + break; + case BTRFS_RAID_RAID5: + ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs); + ctl->stripe_len = find_raid56_stripe_len(ctl->num_stripes - 1, + btrfs_super_stripesize(info->super_copy)); + break; + case BTRFS_RAID_RAID6: + ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs); + ctl->stripe_len = find_raid56_stripe_len(ctl->num_stripes - 2, + btrfs_super_stripesize(info->super_copy)); + break; + default: + break; + } +} + int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, struct btrfs_fs_info *info, u64 *start, u64 *num_bytes, u64 type) @@ -1100,11 +1138,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } ctl.type = btrfs_bg_flags_to_raid_index(type); - ctl.num_stripes = btrfs_raid_profile_table[ctl.type].num_stripes; ctl.max_stripes = 0; - ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes; - ctl.sub_stripes = btrfs_raid_profile_table[ctl.type].sub_stripes; - ctl.stripe_len = BTRFS_STRIPE_LEN; ctl.total_devs = btrfs_super_num_devices(info->super_copy); if (type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { @@ -1129,32 +1163,8 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ctl.max_stripes = BTRFS_MAX_DEVS(info); } } - switch (ctl.type) { - case BTRFS_RAID_RAID1: - case BTRFS_RAID_RAID1C3: - case BTRFS_RAID_RAID1C4: - ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs); - break; - case BTRFS_RAID_RAID0: - ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); - break; - case BTRFS_RAID_RAID10: - ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); - ctl.num_stripes &= ~(u32)1; - break; - case BTRFS_RAID_RAID5: - ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); - ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 1, - btrfs_super_stripesize(info->super_copy)); - break; - case BTRFS_RAID_RAID6: - ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs); - ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 2, - btrfs_super_stripesize(info->super_copy)); - break; - default: - break; - } + + init_alloc_chunk_ctl(info, &ctl); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; From patchwork Wed Jun 10 12:32:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597805 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CF7C618 for ; Wed, 10 Jun 2020 12:33:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8201C20734 for ; Wed, 10 Jun 2020 12:33:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="dUpXwU8Z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729199AbgFJMdk (ORCPT ); Wed, 10 Jun 2020 08:33:40 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12377 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729174AbgFJMdb (ORCPT ); Wed, 10 Jun 2020 08:33:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792410; x=1623328410; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XUoazRuMF0oKCxTYEC1yElCPHbLq/WobG1xmOBAUBBg=; b=dUpXwU8Z2xldkgVOHN2C0oMcy9k3zp2Ol5JU7Pdkc/MzNmnze1uNbuxA g3P5LkxQJ6f3s7Kkbyfo5teoL5JQ4mDWKJmB01oMSx1aCbBN4s4WONaaN G8dIzXyIMBxzQw+M0RohQ+Duit1Jk/Sy9F/ZsxJ8GiY9+JvKDMbUuGDHN /4SarupW6bg91D7GNOT/14uANB7I/5VKcUA1WMh80w+o/x3j7FBhGZ1OG SGfbVKLWBOFWMMz8JBA0Xi7bWrDrT7RrRzsrDrLWTI5ACpNBN5YfLrWo2 o2gE88efRv8TIuiY8rBNvMPJHwWkHEuu86J0toNZPgT4mzC/Ve65yWbhw w==; IronPort-SDR: T4DvCzm9mjCRGOnmiQ0gB6gUqgtq3EuFN+gHz721GMJ52FdW0bXFzF1eOQev0LO9pcU0i4JJtg S7jPSzNtKFdrLKCujHYCM+0ou1PizBTGSWCGf5JdHFguIXgUgwoIKn4jY7ycvD0i95F+YP1ciX gwNiJQHbA2B+wvBAFdJ2FJdpCAjXpkxDJsHM0gsgHilEnXvh8qRI8Zoqcj/tTI+ROsoYmBrTpI 7CrBAbVyGxvXSYNpnSicRfs7wqHXJtrcWG0T2yvnR1BSbVvWi2KkkVytXQGdlfXO5G5fqQQtR5 FpM= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632715" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:15 +0800 IronPort-SDR: JOoWqAVlWxzvmG8sd/xk9KMOM4KOB2yOlNj74+3bBNEzRtH2VnQZ4Rl+PBg/s8flN1GeQ8QcB+ eFloJ+9WgJXMDUBgaIQ1xxqi/6SDQMcTM= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:42 -0700 IronPort-SDR: shEmx+lrmPHWaLh0s1A18kjLeCyf9qWopJaM4J3kX5feLni5dVI5QEPiDMKiDD1EcmRxwGN2Tw pKoBambZKC1w== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:15 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 14/15] btrfs-progs: don't pretend RAID56 has a different stripe length Date: Wed, 10 Jun 2020 21:32:57 +0900 Message-Id: <20200610123258.12382-15-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Since it's addition in 2009 BTRFS RAID5/6 uses a constant stripe length and we're lacking the meta-data to define a per stripe length, so it's unlikely to change in the near future for RAID5/6. So let's not pretend something we don't do and remove the RAID5/6 stripe length special casing. Signed-off-by: Johannes Thumshirn --- volumes.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/volumes.c b/volumes.c index aacff6e0656b..ec31acd57aa7 100644 --- a/volumes.c +++ b/volumes.c @@ -900,13 +900,6 @@ static u64 chunk_bytes_by_type(u64 type, u64 calc_size, return calc_size * ctl->num_stripes; } - -static u32 find_raid56_stripe_len(u32 data_devices, u32 dev_stripe_target) -{ - /* TODO, add a way to store the preferred stripe size */ - return BTRFS_STRIPE_LEN; -} - /* * btrfs_device_avail_bytes - count bytes available for alloc_chunk * @@ -1092,13 +1085,9 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, break; case BTRFS_RAID_RAID5: ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs); - ctl->stripe_len = find_raid56_stripe_len(ctl->num_stripes - 1, - btrfs_super_stripesize(info->super_copy)); break; case BTRFS_RAID_RAID6: ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs); - ctl->stripe_len = find_raid56_stripe_len(ctl->num_stripes - 2, - btrfs_super_stripesize(info->super_copy)); break; default: break; From patchwork Wed Jun 10 12:32:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11597803 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF25790 for ; Wed, 10 Jun 2020 12:33:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C3BC20734 for ; Wed, 10 Jun 2020 12:33:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="VZll1u8l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729197AbgFJMdk (ORCPT ); Wed, 10 Jun 2020 08:33:40 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:12387 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729157AbgFJMdc (ORCPT ); Wed, 10 Jun 2020 08:33:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1591792411; x=1623328411; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fX+wAGF/flCqZTft6Sun+GAf9y+9j55/jeOZA8h5m80=; b=VZll1u8l/PIAyi65nBol9ByC2GMtWfPZzDViDcJUczzQy4Mr78VsPMUl kvZmETs1UP7ZwoxzmsD2imqTcYTiWY1B/6+bFO5j9nkO3u4T0hpnM9F7C sDSvL4bUZ5X92SPcP75JZWrxKrS79a1XNH7YAIUijdNlPRH14c6E0pHDa DYFvCE1zBxLR0dc37TATZ3yUHwByQMYicS889sZCNhP/TrQZtBS027oze XIKe3FnmPLA+8hUT2uw0uMnGUEWE+niD6XCeSvnkrSPK9D5+pf2g1i4gR pJ5Z2Y2jjbwYMWtjFklY6Ko4YKRXrSmFpgFdQ+EPFWffmKsyXQegpdAJv A==; IronPort-SDR: DjyHi/AJJ0qdM+8NkPEgwL1Wa0L/3FGmG9Ik3yF7JVqEoVy7+tqzPCFgqmVsyD6fd3jRrH1U/G EfgSrpwu48b5UmROWXnbSJalF2baAlIa3MwRHnN7YazcyibbRU0qKrhOQTsZl78edD/CrWIVBn OcYYRRDR74G4Oqe/n1oDoE08IhGBrhDZOmAeNzKF5cXk3o28Z/xU2q6idlKt2ZxKQnvdtpNazm QLPZ1LYEma7bD2sn59uM8LxBIqSr4MKnz0KXL6NGYFMTI6HwefKrVXrxCvmiRj5yQ48KuJzv4E cKc= X-IronPort-AV: E=Sophos;i="5.73,496,1583164800"; d="scan'208";a="139632716" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jun 2020 20:33:16 +0800 IronPort-SDR: 8yV5AVAJmLh9cqPowWxnoPj0MSCDRR4O/qNNFe1xI6lme/4xPYsreZijHFUd/4v2UwIRuu1lwv BhSUFZ94x/yZC52iv6r8G2LyjmjYBrlFM= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 05:22:43 -0700 IronPort-SDR: 52YHrzPfgsVIRqb3mHNwWis8Cq+4ODR2hiJDlfasJnrFbmVlLm8JrqtjUHeqgEknpcoDop3NAm GszWp4+MGCKw== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jun 2020 05:33:15 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 15/15] btrfs-progs: consolidate num_stripes setting for striping RAID levels Date: Wed, 10 Jun 2020 21:32:58 +0900 Message-Id: <20200610123258.12382-16-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com> References: <20200610123258.12382-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org All striping RAID Levels use the same method to set the number of RAID stripes, so consolidate it. Signed-off-by: Johannes Thumshirn --- volumes.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/volumes.c b/volumes.c index ec31acd57aa7..7c57d6cb376e 100644 --- a/volumes.c +++ b/volumes.c @@ -1077,17 +1077,12 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, ctl->num_stripes = min(ctl->min_stripes, ctl->total_devs); break; case BTRFS_RAID_RAID0: - ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs); - break; case BTRFS_RAID_RAID10: - ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs); - ctl->num_stripes &= ~(u32)1; - break; case BTRFS_RAID_RAID5: - ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs); - break; case BTRFS_RAID_RAID6: ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs); + if (type == BTRFS_RAID_RAID10) + ctl->num_stripes &= ~(u32)1; break; default: break;