From patchwork Wed Apr 6 01:43:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12803070 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1882C433F5 for ; Wed, 6 Apr 2022 10:03:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235568AbiDFKFc (ORCPT ); Wed, 6 Apr 2022 06:05:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231833AbiDFKEk (ORCPT ); Wed, 6 Apr 2022 06:04:40 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A6FE2DD3A5 for ; Tue, 5 Apr 2022 18:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1649209429; x=1680745429; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q1w6wnSgfWk7aRR5DChrrbID1bDVYX1evttk/zngMFc=; b=HzH/Mhwi4MoUgBIcAcBG++AKZUgtDZdLESwEsdnjXmD4tcgEmfY2Brsd 0Y0f8/ULZsAjpVTaB/hiD7p2PRTWjhS1l8iKZ3ZkY3mS53c7Fk19PEIF3 V7eJ4rKZZOsV75qnkKmfaF78i2O4hL2uXxhM2t29/Joq/XCKUUnJLdtoW yVPZ966mKY2bT4blkGGyimB5zkdzkGRLvCwHqpl6mA8bFWLt9yRBLQqa8 sAukxSAotrAiOi+fRjFunJSQFhf5GXqbzuNiELfYlrYkThySWLwAlPJKU 9CSUhBYToYzDHV0JrbdxKN2BRuXtP8nw8udtkto4JdiSFagnA0bAChJKF Q==; X-IronPort-AV: E=Sophos;i="5.90,238,1643644800"; d="scan'208";a="309153502" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 06 Apr 2022 09:43:47 +0800 IronPort-SDR: Qcx+HmMU/Vfw16+iK4NdO7gt6xUeWYmnj9G/J1HyHY7EHXs0wUA2M6XhJQjUoReU2mGmOSddse 5K/Ndyrm3T7EAIXNAgl34dzbILNEN/1TcskwdVQWfOVCDfXvCeqH1oyAoJEORmQVp8jIrd3W6m MAIAY+hDGeRyZNfs5s18Qi7hY+3OiIWx7ERYBlWEy6wEORmHfsIweuzhH3zob/616EXTkCE4gT K6BaKA7RF9DGySOiSSrjY7ajIxyqVPHTYqUw/2KDvDV9+1xYonwhARBeKbbnPuZqZwyTDFvQwz zBnkyVUuf5zvJZYb0+l8qFGq Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 05 Apr 2022 18:14:30 -0700 IronPort-SDR: x6K0rF8u15lwowP0kSB+G4IS4zvNqrnoUFIUYnQBlg0GrJA/nh0Lf7oPDe86BUactF/GV7tUVc TpnKVTiYhdMuZ64HOF/WbiUMgEJ3ZJK87D86Ol9xeECha3SMdW09tFqSMJbCXcWfRZTrdacQDo GhAKfgjdbITgKSNzSKkTg5c0zBzZEMHCFoWdk4Q4Od/QtVPIENIbEgmBVsh0y027UU00cyTvL4 A22lJWAzY/OHFRnXuS8P7brQj0sOD8BbrD57LpBdjAEVgOMOmYk2KVPUbr81VRfQgR4IVfH3aj MUI= WDCIronportException: Internal Received: from 5cg2012qdx.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.10]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Apr 2022 18:43:48 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 1/4] btrfs-progs: zoned: export sb_zone_number() and related constants Date: Wed, 6 Apr 2022 10:43:10 +0900 Message-Id: <20220406014313.993961-2-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406014313.993961-1-naohiro.aota@wdc.com> References: <20220406014313.993961-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Move sb_zone_number() and related constants from zoned.c to the corresponding header for later use. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 33 --------------------------------- kernel-shared/zoned.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 2a11a1d723aa..396b74f0d906 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -33,20 +33,6 @@ /* Pseudo write pointer value for conventional zone */ #define WP_CONVENTIONAL ((u64)-2) -/* - * Location of the first zone of superblock logging zone pairs. - * - * - primary superblock: 0B (zone 0) - * - first copy: 512G (zone starting at that offset) - * - second copy: 4T (zone starting at that offset) - */ -#define BTRFS_SB_LOG_PRIMARY_OFFSET (0ULL) -#define BTRFS_SB_LOG_FIRST_OFFSET (512ULL * SZ_1G) -#define BTRFS_SB_LOG_SECOND_OFFSET (4096ULL * SZ_1G) - -#define BTRFS_SB_LOG_FIRST_SHIFT const_ilog2(BTRFS_SB_LOG_FIRST_OFFSET) -#define BTRFS_SB_LOG_SECOND_SHIFT const_ilog2(BTRFS_SB_LOG_SECOND_OFFSET) - #define EMULATED_ZONE_SIZE SZ_256M static int btrfs_get_dev_zone_info(struct btrfs_device *device); @@ -220,25 +206,6 @@ static int sb_write_pointer(int fd, struct blk_zone *zones, u64 *wp_ret) return 0; } -/* - * Get the first zone number of the superblock mirror - */ -static inline u32 sb_zone_number(int shift, int mirror) -{ - u64 zone = 0; - - ASSERT(0 <= mirror && mirror < BTRFS_SUPER_MIRROR_MAX); - switch (mirror) { - case 0: zone = 0; break; - case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break; - case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break; - } - - ASSERT(zone <= U32_MAX); - - return (u32)zone; -} - int btrfs_reset_dev_zone(int fd, struct blk_zone *zone) { struct blk_zone_range range; diff --git a/kernel-shared/zoned.h b/kernel-shared/zoned.h index 75327610e537..cc0d6b6f166d 100644 --- a/kernel-shared/zoned.h +++ b/kernel-shared/zoned.h @@ -36,6 +36,20 @@ struct blk_zone { /* Number of superblock log zones */ #define BTRFS_NR_SB_LOG_ZONES 2 +/* + * Location of the first zone of superblock logging zone pairs. + * + * - primary superblock: 0B (zone 0) + * - first copy: 512G (zone starting at that offset) + * - second copy: 4T (zone starting at that offset) + */ +#define BTRFS_SB_LOG_PRIMARY_OFFSET (0ULL) +#define BTRFS_SB_LOG_FIRST_OFFSET (512ULL * SZ_1G) +#define BTRFS_SB_LOG_SECOND_OFFSET (4096ULL * SZ_1G) + +#define BTRFS_SB_LOG_FIRST_SHIFT const_ilog2(BTRFS_SB_LOG_FIRST_OFFSET) +#define BTRFS_SB_LOG_SECOND_SHIFT const_ilog2(BTRFS_SB_LOG_SECOND_OFFSET) + /* * Zoned block device models */ @@ -206,6 +220,25 @@ static inline bool zoned_profile_supported(u64 map_type) #endif /* BTRFS_ZONED */ +/* + * Get the first zone number of the superblock mirror + */ +static inline u32 sb_zone_number(int shift, int mirror) +{ + u64 zone = 0; + + ASSERT(0 <= mirror && mirror < BTRFS_SUPER_MIRROR_MAX); + switch (mirror) { + case 0: zone = 0; break; + case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break; + case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break; + } + + ASSERT(zone <= U32_MAX); + + return (u32)zone; +} + static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) { return zone_is_sequential(device->zone_info, pos); From patchwork Wed Apr 6 01:43:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12803784 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7C99C433EF for ; Wed, 6 Apr 2022 16:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237547AbiDFQbV (ORCPT ); Wed, 6 Apr 2022 12:31:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237704AbiDFQah (ORCPT ); Wed, 6 Apr 2022 12:30:37 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CD632DE168 for ; Tue, 5 Apr 2022 18:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1649209429; x=1680745429; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GG+ZeDHCHx9HkO26a6Cm2XY2cf8ReqgI9BCe1pJ1iOQ=; b=dcng/1Zx0evjP76YSPI/J9dtSVvcxfqIOmqFki+uZuWaoWCjYnPcizXS KuifbE1/BCup9UwBzywJ1dClbYLkf79UEeJQbnYxIQHR7KDD3lOyab69z Z2VWoi2m3kly9WCNq6NXtgLNlUhWtHFgJXW8kEQ7eZRqK7DTaxPW1A4I7 Dkfcz39/vNLt/JH5E6sVgeokRXxCswjYBswdpUMNJ8PhAIc6jxDhB7HkA deKnGPAyPrGTk6RfRx3GcNeh1A6jSJKeTOMzxUMzWtmL0R6HgiQS+PtEZ KA55XqMNHQwjrchDCaxXrcU2NXB31jUn5DNZpOQ91pTuEV1w5n/62TcH9 g==; X-IronPort-AV: E=Sophos;i="5.90,238,1643644800"; d="scan'208";a="309153504" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 06 Apr 2022 09:43:48 +0800 IronPort-SDR: yms9kpj29l6FjSxheedTcDVGMA3KuqVk7Env/PiVxz6PwBXt9vtbNOSWRab0YdgvDxISY4foSA ZDAgx0O2swRiDemiDgJc2gYYfHGUNoBz5PY22UZWtzinch1KbeLf8DcHSnr2gj+6AIJ8REtsQL iDrskX6lOowKZk6P46E7dt4Rjnb2pljvcKQXH3SYwa8SeCugkekT4bAHR/JgREqwptrPJBEG02 BVN5PJbyx7WmzIJi4SrryBTFHD7OT9zGv8LQPZN3nhlFSitbXiR0js09yeelQBxNVvKB1ycZcZ 3CbQb0XmS20w7QchGPqIUvbX Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 05 Apr 2022 18:14:31 -0700 IronPort-SDR: t5YFejW2KnwkerNwtEOojzMEzGOFOJ6OMDq1MmbmYu7HnNTLZkbmVZsFrppn4uGhaEykRv2Aeu Dtb9JRkP7B85u7/5byvYRx+7hitRREwNs0jaX4YPrWpn055x79ovB5EhaXAm2VyzH6Ukhh5dKm 2ZXArvjSRduCkDAiVWIRR3BQL4r0a9Mr7IljU9uB336zikmXUDHAYK2gSot64NvHT5oepbUVSr BgzAoMvmbPkwytx+00v0djtnl7f5OHCG99PlqiW4YBfWBPlWLfyclsyorGxGkvq+Uv5bNqlLli 6/s= WDCIronportException: Internal Received: from 5cg2012qdx.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.10]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Apr 2022 18:43:49 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 2/4] btrfs-progs: zoned: fix initial system BG location Date: Wed, 6 Apr 2022 10:43:11 +0900 Message-Id: <20220406014313.993961-3-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406014313.993961-1-naohiro.aota@wdc.com> References: <20220406014313.993961-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently, we create the initial system block group in the zone 2. That will create the BG at 64MB when the zone size is 32 MB, which collides with the regular superblock location. It results in mount failure with: BTRFS info (device nullb0): zoned mode enabled with zone size 33554432 BTRFS error (device nullb0): zoned: block group 67108864 must not contain super block BTRFS error (device nullb0): failed to read block groups: -117 BTRFS error (device nullb0): open_ctree failed Fix that by calculating the proper location of the initial system BG. It avoids using zones reserved for zoned superblock logging and the zones where a regular superblock resides. Signed-off-by: Naohiro Aota --- mkfs/common.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/mkfs/common.c b/mkfs/common.c index 75680d032d30..218854491c14 100644 --- a/mkfs/common.c +++ b/mkfs/common.c @@ -232,6 +232,34 @@ static int create_block_group_tree(int fd, struct btrfs_mkfs_config *cfg, return 0; } +static u64 zoned_system_group_offset(u64 zone_size) +{ + const int zone_shift = ilog2(zone_size); + u32 zone_num = BTRFS_NR_SB_LOG_ZONES; + u64 start = (u64)zone_num * zone_size; + u32 sb_zones[BTRFS_SUPER_MIRROR_MAX]; + int i; + + for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) + sb_zones[i] = sb_zone_number(zone_shift, i); + + for (;;) { + for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { + if (zone_num == sb_zones[i] || + !(btrfs_sb_offset(i) + BTRFS_SUPER_INFO_SIZE <= start || + start + zone_size <= btrfs_sb_offset(i))) + goto next; + } + + return start; +next: + zone_num++; + start += zone_size; + } + + __builtin_unreachable(); +} + /* * @fs_uuid - if NULL, generates a UUID, returns back the new filesystem UUID * @@ -298,7 +326,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) } if ((cfg->features & BTRFS_FEATURE_INCOMPAT_ZONED)) { - system_group_offset = cfg->zone_size * BTRFS_NR_SB_LOG_ZONES; + system_group_offset = zoned_system_group_offset(cfg->zone_size); system_group_size = cfg->zone_size; } From patchwork Wed Apr 6 01:43:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12803465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77564C4332F for ; Wed, 6 Apr 2022 13:51:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234035AbiDFNxK (ORCPT ); Wed, 6 Apr 2022 09:53:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234436AbiDFNwv (ORCPT ); Wed, 6 Apr 2022 09:52:51 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD1362DE84E for ; Tue, 5 Apr 2022 18:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1649209430; x=1680745430; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rOXLxbvaZe1o5dILFHxK0NT+oUhmuZwqonziGjljGkg=; b=WHDO3b0u16pYqKBa87MVuIvF0cD/mKpOph0OtY30uWTjEGSkKnFx3hpq FXRQPlCCq6L33yJXByCXr/2AOfmGxNhervi9t3eFLumFJkhj9Rk3D5dcm ZVfoIKJh2nrlAGzGd4X3PU70e+dAOXeXTpYRqW3x3d7fDSD558elwisDr OILfE+Ouexs/DiKunMyHOwqvfM/6t00SJx7FaRuf62pG74QwKj3VPl6fD HsTozIez/aS2Z2izA3QOYua6oHVVmbKuIbKIcD7EHzq9xXZKNMVaLV6Sj XOeSAwFWgnns7DV7Csx8uRkvsO9d3oPMw9AHxGfkaZ7WnGmRTr9ypKpQU Q==; X-IronPort-AV: E=Sophos;i="5.90,238,1643644800"; d="scan'208";a="309153507" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 06 Apr 2022 09:43:49 +0800 IronPort-SDR: tUnmGwJxdmHH9jEow4amZ0uvbq1ldEJiyd2BRHUrGFNYleBp4rMDtqpWrtFZB++1Aoiyz7ahlW K4Fao+NwY1wTIk8wmntmlaAWNEkf+mvYPzFvEDt+cPrJbxT6RjdNP11kEKF8ct/V+Yc95LNiP/ 7gPkJ/mu17/o95gNWwiduRzv+3tvwr9w94CNAHcZZqJbA7R8n+ePgycKEMzadTGoXmFMTFsaQ7 zISuBBRGQ+4bDaXo0tsJKV87sO2JYBBmUJl+685Z9ad4IX/Ne2h7nwSkTIY3TUBLsCNPHIPGtq rUHb9BbnJgoLDWofYnZn3Sgr Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 05 Apr 2022 18:14:31 -0700 IronPort-SDR: r1n/LFly7Y6OyjEYuR2u3hg7NZ/P3IIVBcnN/MqH7AfGNGKyG9DvBWmOFwWeICKNQXNG7T7bvD pez25qGSX8Z1tKKqega4icrB/NGS/x974p2dF0olmkZzIMzA1VQf1kN+WV5A80NK1LG8s5vcwd UpNmurQ8URv2DvlEmRKr2tDOdhYEGwrAg16yPQSHQmXHXjfzh/68l7nOxUu4i+eYvTx65vNbp6 u2qnwjepmcIDvzLa8PQ2MmVLPSVH0p/a5SfaV2Fk3DhSMIpYmsp93SJKjRaFRfVuVkmJuni+pm VwI= WDCIronportException: Internal Received: from 5cg2012qdx.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.10]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Apr 2022 18:43:49 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 3/4] btrfs-progs: fix ordering of hole_size setting and dev_extent_hole_check() Date: Wed, 6 Apr 2022 10:43:12 +0900 Message-Id: <20220406014313.993961-4-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406014313.993961-1-naohiro.aota@wdc.com> References: <20220406014313.993961-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The hole_size is used by dev_extent_hole_check() to check the hole is OK as a device extent. However, commit b031fe84fda8 ("btrfs-progs: zoned: implement zoned chunk allocator") mis-ported the kernel code and placed dev_extent_hole_check() before setting hole_check. That made the dev_extent_hole_check() call here essentially pass through as we have hole_size == 0 on mkfs time. As a result, mkfs.btrfs creates data BG at 64 MB where the regular superblock exists, when zone size is 16 MB. Fix the ordering of hole_size setting and calling dev_extent_hole_check(). Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index e24428db8412..0199bc26a8b4 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -774,14 +774,13 @@ next: * search_end may be smaller than search_start. */ if (search_end > search_start) { + hole_size = search_end - search_start; if (dev_extent_hole_check(device, &search_start, &hole_size, num_bytes)) { btrfs_release_path(path); goto again; } - hole_size = search_end - search_start; - if (hole_size > max_hole_size) { max_hole_start = search_start; max_hole_size = hole_size; From patchwork Wed Apr 6 01:43:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12803466 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F6A1C433F5 for ; Wed, 6 Apr 2022 13:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234094AbiDFNxL (ORCPT ); Wed, 6 Apr 2022 09:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234447AbiDFNwv (ORCPT ); Wed, 6 Apr 2022 09:52:51 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCE762DE84B for ; Tue, 5 Apr 2022 18:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1649209430; x=1680745430; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iyo/T2F7zIihT49w53yL0fog+bdlpAC+n01ffJe1qCI=; b=fU4yu22ogg75pErIUHcIOlq6hoxWd+6HlGmQ1w/8lc7pQYvwB4F/UeQ5 +8vh5jDywqWwt30jTnUBsAOfVAWq/ya0TagrHM+nLytNOpi/DHjkndbO+ Vsx7Yvx3N0+njk8lgb7XXIID2VSpLQgaHF6wFWNR0N1xUhn1GriltW9pB Pc4/MPAGh+40KR72gfNlkBzzI1oOPHHNe8lYA2nFdAqlVOa6FOcCvYaRw 25HqDrfUXPKCovkogEQcehP8Hg3v5kVD5YsXqlus4Op2z/KXcfY9zM+BZ bmDNUKOf+TgAS4Fc5F1MmN9aBn6uKu5GBdI88UfKoMRCxPLChMMeEcQIw A==; X-IronPort-AV: E=Sophos;i="5.90,238,1643644800"; d="scan'208";a="309153509" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 06 Apr 2022 09:43:49 +0800 IronPort-SDR: CCWAhGVB0S0EkCa6r8X62c1qDmavRUcpSNI74zSOa65NoXX5LHVjHYTj8L3UcuwZlyAmKlghZ+ 2a3AeqzRSF7IxBGb+igIdH2oCl4uC4EFkgjSN5mIjfVCS9St5QuYlMN6wokYm36Q1xwv8uel6D oV9YSIMNfvJrmCwNZNC/ZLGDQuUA15X0g4uMKtuiZ5bUdOoiW8CN7Gj+W6DABPYwAV4rqYZefj AkFGqAqzxYEesaZogT+Z39Guu+zn4LZ+aH0UHUbIwbSxlwYdjnXmqkjrDj0FC3wKMgAz1s35WG XzlH7fIZ2d314yIoZoAaG46t Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 05 Apr 2022 18:14:32 -0700 IronPort-SDR: hzyNIKQfcaAaaLELA6joBUN7ryIgkGkj1ZocysnC393XViebCt+3Rap3R0wg/xQxMaRGEXn/Nj iN4IkG8lq/avlPAxxxqKR9DtuIBO8k5Mjs0tu3eoFjN9gJJyrC4Q37bA2SJlOALP1fVZCFk9q2 OjC1AiQVjHm71S/tecVY813jadThZC4755xT065u02etVtQb7N7zsPjR2re7cw2fxmgz8IxNCa GiztnNDebv6iqNzNxXLCZL7ed3CpWEjFQ+IPDNxeFIsTV2/2iGNrKA3GoianWCju+VPP6tp/aM whw= WDCIronportException: Internal Received: from 5cg2012qdx.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.10]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Apr 2022 18:43:50 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 4/4] btrfs-progs: zoned: fix and simplify dev_extent_hole_check_zoned() Date: Wed, 6 Apr 2022 10:43:13 +0900 Message-Id: <20220406014313.993961-5-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406014313.993961-1-naohiro.aota@wdc.com> References: <20220406014313.993961-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The previous patch revealed a bug in dev_extent_hole_check_zoned(). If the given hole is OK to use as is, it should have just returned the hole. But on the contrary, it shifts the hole start position by one zone. That results in refusing any hole. We don't use btrfs_ensure_empty_zones() in the btrfs-progs version of dev_extent_hole_check_zoned() unlike the kernel side, because btrfs_find_allocatable_zones() itself is doing the necessary checks. So, we can just "return changed" if the "pos" is unchanged. That also makes the loop and "changed" variable unnecessary. So, fix and simplify the code in one shot. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 0199bc26a8b4..598ac553442c 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -583,30 +583,19 @@ static bool dev_extent_hole_check_zoned(struct btrfs_device *device, u64 *hole_start, u64 *hole_size, u64 num_bytes) { - u64 zone_size = device->zone_info->zone_size; u64 pos; - bool changed = false; - - ASSERT(IS_ALIGNED(*hole_start, zone_size)); - - while (*hole_size > 0) { - pos = btrfs_find_allocatable_zones(device, *hole_start, - *hole_start + *hole_size, - num_bytes); - if (pos != *hole_start) { - *hole_size = *hole_start + *hole_size - pos; - *hole_start = pos; - changed = true; - if (*hole_size < num_bytes) - break; - } - *hole_start += zone_size; - *hole_size -= zone_size; - changed = true; + ASSERT(IS_ALIGNED(*hole_start, device->zone_info->zone_size)); + + pos = btrfs_find_allocatable_zones(device, *hole_start, + *hole_start + *hole_size, num_bytes); + if (pos != *hole_start) { + *hole_size = *hole_start + *hole_size - pos; + *hole_start = pos; + return true; } - return changed; + return false; } /**