From patchwork Wed Feb 19 07:57:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981641 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F4561B85D7 for ; Wed, 19 Feb 2025 07:58:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951896; cv=none; b=RsHM2z/ONSvGprx2455YAEJPK57d8Ki3eMso1smUSwjCECm+HU9MdBVHc3IiH6/ACV3eJ+6mH4b2aYJe8n+vfmATunFAhaH+gtRCmGAl7hfFli441o/zjlvSJjD8it54wnrBqtTYE0GzsLmxXtCUWOvHmOyV1AgsXFARjzch2m4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951896; c=relaxed/simple; bh=+GmoyTrFRY8sm8RZBOJoyQcldsVlHuimZi/L5L+2JOs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YxqADqQ8f70pQ/qaBSkw7OMzEVO5IZgPqnV93UnUy5tw9wDGwd6AkrQDmsFKEHt808LS/JEEQCt8UQ3N1w0xlj1JLyS3jkkk4w0I9oMnjeuq3CCuNG9PtfXJDSQkK79DMMxhGq3h3PPPAp+ULvAKRhmM7mn5gtMB9Kwjs+bZJDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=RccEu3Vj; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="RccEu3Vj" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951890; x=1771487890; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+GmoyTrFRY8sm8RZBOJoyQcldsVlHuimZi/L5L+2JOs=; b=RccEu3VjTRg92dYGwgjd+89k5t5rxOgk7uBgDPHRW/zkOZ8q7GFzAbkH H8FAkoZVJXhDWlPAydXccFwcSA3pJ5/OBGsmidkI9Uee5CYGb8UiNF5fa tTMMhE6jdep//0LmIQMvaZ9SnrILpPcvSIjXLq/+LJz5tGqgUwjGbbp7J O8l7vHwgdmE5xItOZoAyNTWx0z2jv7UsW1OWlNUqQuLa9If/Yh6UI1mew w4oOhlNQ67LEgOUlbfkxboydirymmzJBudPG6iSnyt7e7t6bbE69Z3vOr gf3LB4UB3Qjg0tBk2oiKrv0I7LGYz/2DJtI+DGpAqlDxrqQP+kq4HVxIk A==; X-CSE-ConnectionGUID: /24X8xeBSnuIP0gWbCwo4Q== X-CSE-MsgGUID: wkLUdqCIS76go7JMiX7qcg== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310799" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:04 +0800 IronPort-SDR: 67b58151_X84fmAJsBtoe4E+Kjra6v7xjW06rw7/unME/8kQy1ijgts/ s27GvdGUqWsN3Kg5R2KV+L0vHlNeKTf8eCbLaRw== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:30 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:03 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 01/12] btrfs-progs: introduce min_not_zero() Date: Wed, 19 Feb 2025 16:57:45 +0900 Message-ID: <63892ea2d5c1b429e828ac270b517fbd05d5bd77.1739951758.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce min_not_zero() macro from the kernel. Signed-off-by: Naohiro Aota --- include/kerncompat.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/kerncompat.h b/include/kerncompat.h index 42c84460c1e5..e95bb4a53342 100644 --- a/include/kerncompat.h +++ b/include/kerncompat.h @@ -127,6 +127,16 @@ } #endif +/** + * min_not_zero - return the minimum that is _not_ zero, unless both are zero + * @x: value1 + * @y: value2 + */ +#define min_not_zero(x, y) ({ \ + typeof(x) __x = (x); \ + typeof(y) __y = (y); \ + __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) + static inline void print_trace(void) { #ifndef BTRFS_DISABLE_BACKTRACE From patchwork Wed Feb 19 07:57:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981642 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F2EF1A315E for ; Wed, 19 Feb 2025 07:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951897; cv=none; b=ubwah9yPUQkhSbxX5IUXECEEyWZxWzK+PRjpOct/CjUubFX2hFiUN6k8UKjd7bIpzx6A7fMOXmY/RREmOHoboZSujO7lwc8l55QNrrumLYNM8EpIGjRLouZVMU3LPw8USOAex/Uru+mA1huSc++XC0oot63CPIwq935xPH+avZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951897; c=relaxed/simple; bh=MppZ9PrHLju78y/W9D+X52JUgf00fP8+kOtxv7KfvY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R+5hD+TjOm8J59rIfL+iH3xAU9JSirSK1omU2gDQn3j9rRag8IH/oTIeOunqbdILHoe0zFUePZ9NnKyScZdVuM3m//X4Il/V3u8x7+crkRXctT6zGv5AwfMugpfQxEwNPbZWBM5WtJRvtDvhdJiKV5G8ZSb4S2MY9fRSk9dDsOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=rrveHa9/; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="rrveHa9/" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951892; x=1771487892; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MppZ9PrHLju78y/W9D+X52JUgf00fP8+kOtxv7KfvY4=; b=rrveHa9/uofHTq7VBssmjxrcDTuk/oKEY+sV/GbdALirHLRaVMdF8sDk FRmeQWo1/McbSLd5fquxX8IuUjsxeqRNFk/2EzydyNpleSZeX/Rzt0dD6 81ejBJc9Y0EQeOrbZpm9+HRoUHjQ2TQe6b0OPgbwy8zRvdynBumfUzEL+ guP9yvvcDjMOIKH5dcvFsjhr5rUjVVSn0VdYaTVtEGhY2dZyx4E5tG8Gd 6iFtW877EZgjnioAfjfjCCt4y02olWGOfcFbGeP8bJ0c8vUMDXe+r20go gt9phHoMGfsBUqRNpdr2lTsC6LkEoMT4yHT8973DYPuElM/56rwDPKPHV A==; X-CSE-ConnectionGUID: sgxxQi6YQZes4wI7cGHoqQ== X-CSE-MsgGUID: /dA8dMXXQRSL9H0/Oi3Jig== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310802" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:05 +0800 IronPort-SDR: 67b58152_HaDpThY8jhuCG63a+kNYtwS2wZEauYo5ZTohB0wAhlwLf4v 10P1EEj0upapj11P15n3p1kDzHK5grdUpPDsWzQ== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:30 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:04 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 02/12] btrfs-progs: zoned: introduce a zone_info struct in btrfs_load_block_group_zone_info Date: Wed, 19 Feb 2025 16:57:46 +0900 Message-ID: <48e5d55e3d4e773cb7952ac14978466dcf93a32a.1739951758.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is an userland side update to follow kernel-side commit 15c12fcc50a1 ("btrfs: zoned: introduce a zone_info struct in btrfs_load_block_group_zone_info"). This will make the code unification easier. This commit introduces zone_info structure to hold per-zone information in btrfs_load_block_group_zone_info. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 46 ++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index fd8a776dc471..b06774482cfd 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -828,6 +828,11 @@ bool zoned_profile_supported(u64 map_type, bool rst) return false; } +struct zone_info { + u64 physical; + u64 alloc_offset; +}; + int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, struct btrfs_block_group *cache) { @@ -837,10 +842,9 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, struct map_lookup *map; u64 logical = cache->start; u64 length = cache->length; - u64 physical = 0; + struct zone_info *zone_info = NULL; int ret = 0; int i; - u64 *alloc_offsets = NULL; u64 last_alloc = 0; u32 num_conventional = 0; @@ -867,30 +871,29 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, } map = container_of(ce, struct map_lookup, ce); - alloc_offsets = calloc(map->num_stripes, sizeof(*alloc_offsets)); - if (!alloc_offsets) { - error_msg(ERROR_MSG_MEMORY, "zone offsets"); + zone_info = calloc(map->num_stripes, sizeof(*zone_info)); + if (!zone_info) { + error_msg(ERROR_MSG_MEMORY, "zone info"); return -ENOMEM; } for (i = 0; i < map->num_stripes; i++) { + struct zone_info *info = &zone_info[i]; bool is_sequential; struct blk_zone zone; device = map->stripes[i].dev; - physical = map->stripes[i].physical; + info->physical = map->stripes[i].physical; if (device->fd == -1) { - alloc_offsets[i] = WP_MISSING_DEV; + info->alloc_offset = WP_MISSING_DEV; continue; } - is_sequential = btrfs_dev_is_sequential(device, physical); - if (!is_sequential) - num_conventional++; - + is_sequential = btrfs_dev_is_sequential(device, info->physical); if (!is_sequential) { - alloc_offsets[i] = WP_CONVENTIONAL; + num_conventional++; + info->alloc_offset = WP_CONVENTIONAL; continue; } @@ -898,28 +901,27 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, * The group is mapped to a sequential zone. Get the zone write * pointer to determine the allocation offset within the zone. */ - WARN_ON(!IS_ALIGNED(physical, fs_info->zone_size)); - zone = device->zone_info->zones[physical / fs_info->zone_size]; + WARN_ON(!IS_ALIGNED(info->physical, fs_info->zone_size)); + zone = device->zone_info->zones[info->physical / fs_info->zone_size]; switch (zone.cond) { case BLK_ZONE_COND_OFFLINE: case BLK_ZONE_COND_READONLY: error( "zoned: offline/readonly zone %llu on device %s (devid %llu)", - physical / fs_info->zone_size, device->name, + info->physical / fs_info->zone_size, device->name, device->devid); - alloc_offsets[i] = WP_MISSING_DEV; + info->alloc_offset = WP_MISSING_DEV; break; case BLK_ZONE_COND_EMPTY: - alloc_offsets[i] = 0; + info->alloc_offset = 0; break; case BLK_ZONE_COND_FULL: - alloc_offsets[i] = fs_info->zone_size; + info->alloc_offset = fs_info->zone_size; break; default: /* Partially used zone */ - alloc_offsets[i] = - ((zone.wp - zone.start) << SECTOR_SHIFT); + info->alloc_offset = ((zone.wp - zone.start) << SECTOR_SHIFT); break; } } @@ -943,7 +945,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, ret = -EINVAL; goto out; } - cache->alloc_offset = alloc_offsets[0]; + cache->alloc_offset = zone_info[0].alloc_offset; out: /* An extent is allocated after the write pointer */ @@ -957,7 +959,7 @@ out: if (!ret) cache->write_offset = cache->alloc_offset; - kfree(alloc_offsets); + kfree(zone_info); return ret; } From patchwork Wed Feb 19 07:57:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981644 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C86041C3029 for ; Wed, 19 Feb 2025 07:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951898; cv=none; b=kKG35VdgcAoGGUgqFoVDd0YwicO36jWzftTtj+Xq8bqskLYwPRlQxs37ExZeQ3zZ8en4QZv6U3Lf7tEoSnjzdUoO2uJhCGy9Vs2Jtm8ruqAb0WWv6qSSEH0ImkkVQQh95oQ986ox6SbvnyMlxxnGNAiPHD+1OS2iVZupi7uo52o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951898; c=relaxed/simple; bh=6t5MgUF49kRf9OwZbGpXEVELI8+Fg7uXQvdw4/3oE58=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GKWf067z3Gmz+Lw/KZj6u8INOsK5HiBxG8GnoHmik5Qp3t1pdl+4zg3Ps0Rvu+plJL4vF5G8LMCKsap8LbAA11qy6yqfYYZwmYXm6cMBf7RgG2a80Hvq4cb+M/qCt6yQa8MWzG7U6ZXlN4r5lKLoJZkQFFyCPrUaCliy+U3BlEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=qqJOaKg7; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="qqJOaKg7" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951892; x=1771487892; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6t5MgUF49kRf9OwZbGpXEVELI8+Fg7uXQvdw4/3oE58=; b=qqJOaKg7hJbw3w20MFRZm5S179GMdnpnQF5GXCcDpLV/ixV15r6nyWfx r8AXx1t9I0SV0y1w3uKn2yjQYr91j44H//Yw8Nv36qa2YZP8Q7Qc33mkr bl2NQ4o0qpEmEKm+BbSXVdIM7OGvSJJf7xEfls48fDeb9nJ2bBM82gA4o uIX26ShTEXApp+43rqWRW+430i7Sa2nxhqzrfz0DxBz3qOnZZWtN3veQb VeaxK2Lf2sIRVDjHCJNxicGTRboMZTcGVh8T8kNoMwgyrODFpEgTBTZhi wZI3DWgMw3hYkmvA77H91SWJDjjSwvJtUPgDqr6b0fByrBfzopF78T9z9 Q==; X-CSE-ConnectionGUID: QTdtT2OQTCOIjeZsko/tJg== X-CSE-MsgGUID: 9SXZX4muRa61zIw2i8oX2w== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310804" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:06 +0800 IronPort-SDR: 67b58153_yHmizFlOWuGy27Vg3OmDUYewfQaT/bJ6+j/VF9xi8wxTrOg YTLPTcZqN413ys+QkPnpX8JE95umbaXldPGJK0A== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:31 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:05 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 03/12] btrfs-progs: zoned: support zone capacity Date: Wed, 19 Feb 2025 16:57:47 +0900 Message-ID: <8c68704eca02321ab9577d4a1e96eb83751fbc35.1739951758.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The userland tools did not load and use the zone capacity. Support it properly. Signed-off-by: Naohiro Aota --- kernel-shared/ctree.h | 1 + kernel-shared/extent-tree.c | 2 +- kernel-shared/zoned.c | 9 ++++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index 8c923be96705..a6aa10a690bb 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -285,6 +285,7 @@ struct btrfs_block_group { */ u64 alloc_offset; u64 write_offset; + u64 zone_capacity; u64 global_root_id; }; diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c index 20eef4f3df7b..2b7a962f294b 100644 --- a/kernel-shared/extent-tree.c +++ b/kernel-shared/extent-tree.c @@ -300,7 +300,7 @@ again: goto new_group; if (btrfs_is_zoned(root->fs_info)) { - if (cache->length - cache->alloc_offset < num) + if (cache->zone_capacity - cache->alloc_offset < num) goto new_group; *start_ret = cache->start + cache->alloc_offset; cache->alloc_offset += num; diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index b06774482cfd..319ee88d5b06 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -776,7 +776,7 @@ static int calculate_alloc_pointer(struct btrfs_fs_info *fs_info, length = fs_info->nodesize; if (!(found_key.objectid >= cache->start && - found_key.objectid + length <= cache->start + cache->length)) { + found_key.objectid + length <= cache->start + cache->zone_capacity)) { ret = -EUCLEAN; goto out; } @@ -830,6 +830,7 @@ bool zoned_profile_supported(u64 map_type, bool rst) struct zone_info { u64 physical; + u64 capacity; u64 alloc_offset; }; @@ -894,6 +895,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, if (!is_sequential) { num_conventional++; info->alloc_offset = WP_CONVENTIONAL; + info->capacity = device->zone_info->zone_size; continue; } @@ -904,6 +906,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, WARN_ON(!IS_ALIGNED(info->physical, fs_info->zone_size)); zone = device->zone_info->zones[info->physical / fs_info->zone_size]; + info->capacity = (zone.capacity << SECTOR_SHIFT); + switch (zone.cond) { case BLK_ZONE_COND_OFFLINE: case BLK_ZONE_COND_READONLY: @@ -927,6 +931,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, } if (num_conventional > 0) { + /* Zone capacity is always zone size in emulation */ + cache->zone_capacity = cache->length; ret = calculate_alloc_pointer(fs_info, cache, &last_alloc); if (ret || map->num_stripes == num_conventional) { if (!ret) @@ -946,6 +952,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, goto out; } cache->alloc_offset = zone_info[0].alloc_offset; + cache->zone_capacity = zone_info[0].capacity; out: /* An extent is allocated after the write pointer */ From patchwork Wed Feb 19 07:57:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981643 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2231A1C4A13 for ; Wed, 19 Feb 2025 07:58:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951897; cv=none; b=jtd2dUaih2BLy00zyqhBbN2zTEGUsYt5SS+A8KhBWK0FSev+TUyKAvA141/d6g9/URE6828494+abMSVaJTIYf3/Ld6t/rhGCsdhzIjbywdTXk9UwNzNzf8QJJqXaijX82HOaQuAiUk07oC7kNw+u9hFTWkIlR6M+gWd8RTwo44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951897; c=relaxed/simple; bh=l0MELxl+UYSrAkXECBypm34bdJVZBkjGfRlCTd1xIeI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o88Ez1j/UJfui35g2UNa5Ti+oXeRu2wNfecNCG6sZwBN0DvLZLK920rJrY80Xb8XS1/GEYtenU9KaIVpUSB5Qzh/LnDvRimSKJ2EBPq1fM2z1E/J3wc2SBGYRcWOKPpjdD5qOvJNMb6ZZLPh2weuzOppLvtLnBN/ZZyZnUeMfjk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=eNU03J2N; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="eNU03J2N" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951896; x=1771487896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l0MELxl+UYSrAkXECBypm34bdJVZBkjGfRlCTd1xIeI=; b=eNU03J2N2oN984ivLaoyeMs4FoxQj48ecI5dkbJnDu90iWignzn0Ie8g HnqiLfck7FaaSqAKKIoXPOWf3C4y1bawm7LmR9slDCdELV5USAC9LJ6a2 yS/HH1dIGg6AJ+aLwPewHfXiY+MHYzj7qJwCSbrQGrZwrPsZ/9Xm8v06v VbChPkwKqZvCCraJFsWA+/EYaCS4n6CEB4eYkrsIyK/QyYBkXZTfmb4op cz/3QmoeP4Scto+/S/dV5pvqet34c3zID00q5mAyD3ee35NfVZWajLVH0 Q30xzWBVXflxdv3MnAD6gb/4YZZ8JbSEpZW4cQIJou4zinoTlQ8CM/GcD Q==; X-CSE-ConnectionGUID: I0GhGNyyRTuj/uHViR/jxA== X-CSE-MsgGUID: aJ38rfM2QQWS3EnyqR3fGA== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310806" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:06 +0800 IronPort-SDR: 67b58154_vZCyP20u+NYTsCXBOpttyRNwM9EBDfQxEZOQUE/E5T8hW5q 9K40aaGMkuAodTlP6u4IJazg8X87fNBhBdMjB8Q== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:32 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:06 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 04/12] btrfs-progs: zoned: load zone activeness Date: Wed, 19 Feb 2025 16:57:48 +0900 Message-ID: <58ad7ad0db8a17c2e27a54314869c3e94f7ab048.1739951758.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Properly load the zone activeness on the userland tool. Also, check if a device has enough active zone limit to run btrfs. Signed-off-by: Naohiro Aota --- kernel-shared/ctree.h | 1 + kernel-shared/zoned.c | 77 +++++++++++++++++++++++++++++++++++++++---- kernel-shared/zoned.h | 3 ++ 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index a6aa10a690bb..f10142df80eb 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -368,6 +368,7 @@ struct btrfs_fs_info { unsigned int allow_transid_mismatch:1; unsigned int skip_leaf_item_checks:1; unsigned int rebuilding_extent_tree:1; + unsigned int active_zone_tracking:1; int transaction_aborted; diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 319ee88d5b06..a97466635ecb 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -23,6 +23,7 @@ #include #include #include "kernel-lib/list.h" +#include "kernel-lib/bitmap.h" #include "kernel-shared/volumes.h" #include "kernel-shared/zoned.h" #include "kernel-shared/accessors.h" @@ -57,6 +58,16 @@ static u64 emulated_zone_size = DEFAULT_EMULATED_ZONE_SIZE; #define BTRFS_MAX_ZONE_SIZE (8ULL * SZ_1G) #define BTRFS_MIN_ZONE_SIZE (SZ_4M) +/* + * Minimum of active zones we need: + * + * - BTRFS_SUPER_MIRROR_MAX zones for superblock mirrors + * - 3 zones to ensure at least one zone per SYSTEM, META and DATA block group + * - 1 zone for tree-log dedicated block group + * - 1 zone for relocation + */ +#define BTRFS_MIN_ACTIVE_ZONES (BTRFS_SUPER_MIRROR_MAX + 5) + static int btrfs_get_dev_zone_info(struct btrfs_device *device); enum btrfs_zoned_model zoned_model(const char *file) @@ -132,6 +143,18 @@ static u64 max_zone_append_size(const char *file) return strtoull((const char *)chunk, NULL, 10); } +static unsigned int max_active_zone_count(const char *file) +{ + char buf[32]; + int ret; + + ret = device_get_queue_param(file, "max_active_zones", buf, sizeof(buf)); + if (ret <= 0) + return 0; + + return strtoul((const char *)buf, NULL, 10); +} + #ifdef BTRFS_ZONED /* * Emulate blkdev_report_zones() for a non-zoned device. It slices up the block @@ -273,7 +296,8 @@ static int report_zones(int fd, const char *file, struct stat st; struct blk_zone_report *rep; struct blk_zone *zone; - unsigned int i, n = 0; + unsigned int i, nreported = 0, nactive = 0; + unsigned int max_active_zones; int ret; /* @@ -336,6 +360,20 @@ static int report_zones(int fd, const char *file, exit(1); } + zinfo->active_zones = bitmap_zalloc(zinfo->nr_zones); + if (!zinfo->active_zones) { + error_msg(ERROR_MSG_MEMORY, "active zone bitmap"); + exit(1); + } + + max_active_zones = max_active_zone_count(file); + if (max_active_zones && max_active_zones < BTRFS_MIN_ACTIVE_ZONES) { + error("zoned: %s: max active zones %u is too small, need at least %u active zones", + file, max_active_zones, BTRFS_MIN_ACTIVE_ZONES); + exit(1); + } + zinfo->max_active_zones = max_active_zones; + /* Allocate a zone report */ rep_size = sizeof(struct blk_zone_report) + sizeof(struct blk_zone) * BTRFS_REPORT_NR_ZONES; @@ -347,7 +385,7 @@ static int report_zones(int fd, const char *file, /* Get zone information */ zone = (struct blk_zone *)(rep + 1); - while (n < zinfo->nr_zones) { + while (nreported < zinfo->nr_zones) { memset(rep, 0, rep_size); rep->sector = sector; rep->nr_zones = BTRFS_REPORT_NR_ZONES; @@ -374,17 +412,36 @@ static int report_zones(int fd, const char *file, break; for (i = 0; i < rep->nr_zones; i++) { - if (n >= zinfo->nr_zones) + if (nreported >= zinfo->nr_zones) break; - memcpy(&zinfo->zones[n], &zone[i], + memcpy(&zinfo->zones[nreported], &zone[i], sizeof(struct blk_zone)); - n++; + switch (zone[i].cond) { + case BLK_ZONE_COND_EMPTY: + break; + case BLK_ZONE_COND_IMP_OPEN: + case BLK_ZONE_COND_EXP_OPEN: + case BLK_ZONE_COND_CLOSED: + set_bit(nreported, zinfo->active_zones); + nactive++; + break; + } + nreported++; } sector = zone[rep->nr_zones - 1].start + zone[rep->nr_zones - 1].len; } + if (max_active_zones) { + if (nactive > max_active_zones) { + error("zoned: %u active zones on %s exceeds max_active_zones %u", + nactive, file, max_active_zones); + exit(1); + } + zinfo->active_zones_left = max_active_zones - nactive; + } + kfree(rep); return 0; @@ -1080,6 +1137,7 @@ int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info) static int btrfs_get_dev_zone_info(struct btrfs_device *device) { struct btrfs_fs_info *fs_info = device->fs_info; + int ret; /* * Cannot use btrfs_is_zoned here, since fs_info::zone_size might not @@ -1091,7 +1149,14 @@ static int btrfs_get_dev_zone_info(struct btrfs_device *device) if (device->zone_info) return 0; - return btrfs_get_zone_info(device->fd, device->name, &device->zone_info); + ret = btrfs_get_zone_info(device->fd, device->name, &device->zone_info); + if (ret) + return ret; + + if (device->zone_info->max_active_zones) + fs_info->active_zone_tracking = 1; + + return 0; } int btrfs_get_zone_info(int fd, const char *file, diff --git a/kernel-shared/zoned.h b/kernel-shared/zoned.h index c593571c4b69..d004ff16f198 100644 --- a/kernel-shared/zoned.h +++ b/kernel-shared/zoned.h @@ -72,7 +72,10 @@ struct btrfs_zoned_device_info { enum btrfs_zoned_model model; u64 zone_size; u32 nr_zones; + unsigned int max_active_zones; struct blk_zone *zones; + atomic_t active_zones_left; + unsigned long *active_zones; bool emulated; }; From patchwork Wed Feb 19 07:57:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981646 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1B091C54A7 for ; Wed, 19 Feb 2025 07:58:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951902; cv=none; b=gCzDdxqrOrq1gqrfLdsK091BBpxu3BgGhlEgnEaEqoZjJmjhnZbI/9YT8ULd9fUyNik90Kia72WzkXcMJWwBNTXZme4YwER6ZSFjTxsLhnf6sd10tSgBkrj1tHnCgMny52Z/eXuaRL95+GplPAyvzdv6TupZDzqnNphqg5oS8kE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951902; c=relaxed/simple; bh=wrHS5cUCM5L5AttiYjQt+RQCbR4CsmRd5QhN57OxLzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=avuNZoTjJGY+XDHDUaBTn3k3KfovU1D/KcKSeaW5zfdrCmszNXyiKPsDvRv/WnHZZlSrhU/mze55ioXDsP75R9Mw6ASIs90IWazoe3cmDpFsiePPyN4ZSKDuz6jxVR7eZZ6babS9weqrltfZm+QgEmcHqyz+agiIaL8n+OrXU/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=lI9FVlPk; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="lI9FVlPk" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951897; x=1771487897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wrHS5cUCM5L5AttiYjQt+RQCbR4CsmRd5QhN57OxLzc=; b=lI9FVlPkFpS7N4wIpUngu1+i296E4+FQ0wTef7l0IcFqr2Ud2ypqS1vH VnlblW4A36ctN2BMQQuuL//+uy4E806gtBjmCmpKmA0u4loyzPap+uuH1 OxqVFWJIPAMOKxWjLRXH4rqMjsGU5INCtx+2j25KnOj2GMDlwcfpeMrox vD/aEvUAkLWN7B0I0AnMW1WMnv62dezK7JItxCLF3KKFmgJCaZsGazOsV hyX4qWbeFSWyxwawdbQdtXTrDQ9a7+sdE4Q5mTfTM+ftG5oLD7mbhpltU pKveUUX6sN/h0yglq7roePXOgYNryWNEC2OlHoCMisKen+drHMJ7QhAGs Q==; X-CSE-ConnectionGUID: zNkK7FJjR6+8e7E5wIj3nA== X-CSE-MsgGUID: Q5/vM9gmQWqhJEB1SBG9tw== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310808" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:07 +0800 IronPort-SDR: 67b58154_6mGAanfhtTAyA7QONGh9JlDl+BWiJyB3aHzGcqpuV0WVeHs ho0K+Va8J6sVrlOG9nzXqzqNo/Lzrywpv1riSHg== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:33 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:06 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 05/12] btrfs-progs: zoned: activate block group on loading Date: Wed, 19 Feb 2025 16:57:49 +0900 Message-ID: <0a272ad61dca26d4ee7f1e7ba474685b21825a05.1739951758.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce "zone_is_active" member to struct btrfs_block_group and activate it on loading a block group. Note that activeness check for the extent allocation is currently not implemented. The activeness checking requires to activate a non-active block group on the extent allocation, which also require finishing a zone in the case of hitting the active zone limit. Since mkfs should not hit the limit, implementing the zone finishing code would not be necessary at the moment. Signed-off-by: Naohiro Aota --- kernel-shared/ctree.h | 1 + kernel-shared/zoned.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index f10142df80eb..da0635d567dc 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -286,6 +286,7 @@ struct btrfs_block_group { u64 alloc_offset; u64 write_offset; u64 zone_capacity; + bool zone_is_active; u64 global_root_id; }; diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index a97466635ecb..ee6c4ee61e4a 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -901,6 +901,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, u64 logical = cache->start; u64 length = cache->length; struct zone_info *zone_info = NULL; + unsigned long *active = NULL; int ret = 0; int i; u64 last_alloc = 0; @@ -935,6 +936,13 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, return -ENOMEM; } + active = bitmap_zalloc(map->num_stripes); + if (!active) { + free(zone_info); + error_msg(ERROR_MSG_MEMORY, "active bitmap"); + return -ENOMEM; + } + for (i = 0; i < map->num_stripes; i++) { struct zone_info *info = &zone_info[i]; bool is_sequential; @@ -948,6 +956,10 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, continue; } + /* Consider a zone as active if we can allow any number of active zones. */ + if (!device->zone_info->max_active_zones) + set_bit(i, active); + is_sequential = btrfs_dev_is_sequential(device, info->physical); if (!is_sequential) { num_conventional++; @@ -983,6 +995,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, default: /* Partially used zone */ info->alloc_offset = ((zone.wp - zone.start) << SECTOR_SHIFT); + set_bit(i, active); break; } } @@ -1008,8 +1021,10 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, ret = -EINVAL; goto out; } + /* SINGLE profile case. */ cache->alloc_offset = zone_info[0].alloc_offset; cache->zone_capacity = zone_info[0].capacity; + cache->zone_is_active = test_bit(0, active); out: /* An extent is allocated after the write pointer */ From patchwork Wed Feb 19 07:57:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981647 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 085B41C54A5 for ; Wed, 19 Feb 2025 07:58:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951903; cv=none; b=Xsjtw969NADjTGS/CGv9c+iJsiY2ZgExqRJecZVBehq5a+Wzj9vu7BBZI68007TUNYd41CJ5cVIryMGzbZpQXVMmQm6jseH8WKrwq5ziNy4WgKP1OqI7mPR9KpKonIAui8Smr4Qc1J4b7A5qDPWmlx1mnqSifUZCGhYcXkV4c/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951903; c=relaxed/simple; bh=yXhAD6P03SJMemKKQjfkaDbiWr7LwH2+E5dAXD+GlNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eRU8pjDrHb7zYkcHyn8uI9laVbwFTVTTw/MPpCgIhHXufzagArtGfPypLJ+6udHygmIQ7izPBc7JsyZvl3ISMc+zxAss+aIBN0vStLZM/0Zd21Y6V/WBe3UYTjq9vJlZHMTJUqJFejqhkXCJ5iT3QMUE9J2SKrBz6WLnIYz+3c0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=ArUlFp0r; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="ArUlFp0r" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951898; x=1771487898; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yXhAD6P03SJMemKKQjfkaDbiWr7LwH2+E5dAXD+GlNY=; b=ArUlFp0r9wnKu0Simqz4eBICQ2M9l9TGtrWsW2VfQezxPaARvEBXvGC0 qgyNMWY+3jNECMs2N1hjjFOFvkadc85X9a0KmzAqq+v25OsSq65Gn36Cw enzrnBU4GJ3/ZnsHTyhYSmn785woHGhaszUjhoHTFlQQyXMZuM/r3Q9r/ 2ciYXqRTl8+ii8GYdcBTon0d4Z8IE0Q8mjzkAogjZrua9AEnFaqrAgBb4 8/ASF/4W0K9feyL9y+nHcPyxaLYjgfdgGYkD4Ej/frxNGDLQENBDw0+Ca noeAaCZntSRqlYFaX6K8Zb7iaNGwD0jNsxnAegKwG8txWC3qXfEIqrGJw Q==; X-CSE-ConnectionGUID: fzb8jNdnQdGYmRcV5qBCnA== X-CSE-MsgGUID: 4JXpAGynR6+8F6Ro9JfkzA== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310809" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:08 +0800 IronPort-SDR: 67b58155_XKLoxNdEOSjL8KEOSV5CXCLkALCq7hD80eSzZ7Ju0Pru8fq 4lQPEK7NcaNaQk2nIEvd4Zvm5Q1Sqiom7BBHjVQ== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:33 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:07 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 06/12] btrfs-progs: factor out btrfs_load_zone_info() Date: Wed, 19 Feb 2025 16:57:50 +0900 Message-ID: <13b005c387446c5bb3e0212ba31423e1458688de.1739951758.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that, we have zone capacity and (basic) zone activeness support. It's time to factor out btrfs_load_zone_info() as same as the kernel side. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 124 ++++++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 53 deletions(-) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index ee6c4ee61e4a..4045cf0d2b98 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -891,10 +891,76 @@ struct zone_info { u64 alloc_offset; }; +static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx, + struct zone_info *info, unsigned long *active, + struct map_lookup *map) +{ + struct btrfs_device *device; + struct blk_zone zone; + + info->physical = map->stripes[zone_idx].physical; + + device = map->stripes[zone_idx].dev; + + if (device->fd == -1) { + info->alloc_offset = WP_MISSING_DEV; + return 0; + } + + /* Consider a zone as active if we can allow any number of active zones. */ + if (!device->zone_info->max_active_zones) + set_bit(zone_idx, active); + + if (!btrfs_dev_is_sequential(device, info->physical)) { + info->alloc_offset = WP_CONVENTIONAL; + info->capacity = device->zone_info->zone_size; + return 0; + } + + /* + * The group is mapped to a sequential zone. Get the zone write + * pointer to determine the allocation offset within the zone. + */ + WARN_ON(!IS_ALIGNED(info->physical, fs_info->zone_size)); + zone = device->zone_info->zones[info->physical / fs_info->zone_size]; + + if (zone.type == BLK_ZONE_TYPE_CONVENTIONAL) { + error("zoned: unexpected conventional zone %llu on device %s (devid %llu)", + zone.start << SECTOR_SHIFT, device->name, + device->devid); + return -EIO; + } + + info->capacity = (zone.capacity << SECTOR_SHIFT); + + switch (zone.cond) { + case BLK_ZONE_COND_OFFLINE: + case BLK_ZONE_COND_READONLY: + error( + "zoned: offline/readonly zone %llu on device %s (devid %llu)", + info->physical / fs_info->zone_size, device->name, + device->devid); + info->alloc_offset = WP_MISSING_DEV; + break; + case BLK_ZONE_COND_EMPTY: + info->alloc_offset = 0; + break; + case BLK_ZONE_COND_FULL: + info->alloc_offset = fs_info->zone_size; + break; + default: + /* Partially used zone */ + info->alloc_offset = ((zone.wp - zone.start) << SECTOR_SHIFT); + set_bit(zone_idx, active); + break; + } + + return 0; +} + int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, struct btrfs_block_group *cache) { - struct btrfs_device *device; struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; struct cache_extent *ce; struct map_lookup *map; @@ -944,60 +1010,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, } for (i = 0; i < map->num_stripes; i++) { - struct zone_info *info = &zone_info[i]; - bool is_sequential; - struct blk_zone zone; - - device = map->stripes[i].dev; - info->physical = map->stripes[i].physical; - - if (device->fd == -1) { - info->alloc_offset = WP_MISSING_DEV; - continue; - } - - /* Consider a zone as active if we can allow any number of active zones. */ - if (!device->zone_info->max_active_zones) - set_bit(i, active); + ret = btrfs_load_zone_info(fs_info, i, &zone_info[i], active, map); + if (ret) + goto out; - is_sequential = btrfs_dev_is_sequential(device, info->physical); - if (!is_sequential) { + if (zone_info[i].alloc_offset == WP_CONVENTIONAL) num_conventional++; - info->alloc_offset = WP_CONVENTIONAL; - info->capacity = device->zone_info->zone_size; - continue; - } - - /* - * The group is mapped to a sequential zone. Get the zone write - * pointer to determine the allocation offset within the zone. - */ - WARN_ON(!IS_ALIGNED(info->physical, fs_info->zone_size)); - zone = device->zone_info->zones[info->physical / fs_info->zone_size]; - - info->capacity = (zone.capacity << SECTOR_SHIFT); - - switch (zone.cond) { - case BLK_ZONE_COND_OFFLINE: - case BLK_ZONE_COND_READONLY: - error( - "zoned: offline/readonly zone %llu on device %s (devid %llu)", - info->physical / fs_info->zone_size, device->name, - device->devid); - info->alloc_offset = WP_MISSING_DEV; - break; - case BLK_ZONE_COND_EMPTY: - info->alloc_offset = 0; - break; - case BLK_ZONE_COND_FULL: - info->alloc_offset = fs_info->zone_size; - break; - default: - /* Partially used zone */ - info->alloc_offset = ((zone.wp - zone.start) << SECTOR_SHIFT); - set_bit(i, active); - break; - } } if (num_conventional > 0) { From patchwork Wed Feb 19 07:57:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981645 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C8A61C5D44 for ; Wed, 19 Feb 2025 07:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951900; cv=none; b=fYhrZZZSdobVi4IUKqsFCQn7vKG5TDUu+aN483E5F2z3Khw5CnoCqiYAi3A2k/OVJlR1LoZVbj0XhiRcmza7kOczGTkTjYDOR589nP485ay0Qv56B2Mz1cF+Ut4gb2Z4Px521IFJvc+71ggwdqlLHqmV9GwfmkvoMHTIBaUt1fY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951900; c=relaxed/simple; bh=sUmSo10U0500bOerBdfktQaQwZHt39MTwCzMtKDfq1Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p9YWnQ/r41vXT7j7ZCVl5Ow0X5p7g/9GS54hu0wNIUkQhfiFdtRKp6V5rBwsmEANCQvWxzP3/CQb/RB6LEwfj3isyPuNTiQOkH849UHUSnQ5nI86pFPSJf0fr3gsZD34G3Pcm+CUq2WYGG+l1BhIvRkhDnl0g3/0MW8fervSB1A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=oLubzzP8; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="oLubzzP8" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951898; x=1771487898; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sUmSo10U0500bOerBdfktQaQwZHt39MTwCzMtKDfq1Y=; b=oLubzzP8lgSpeF1RYnFGSDlCLBlpivgvPyDFjdXeVW1F81HFppNQZgwe aTmbqguERYX+Xm0zlotyvHs/TxJg+2QhYuGK80GP27bwFuw2+vchsn1OP rBB/R6wcw/5QhZri3OEG9y3nFCdGYNbL7Dp9+emonlx0xlBx8zB3rbDxr EJGNcFs/mXCDye93JKuJRsspUva6wla9/qt5MoeWQUiDUH+efI4g597TW rKaOjv5Q7CYDAJY+IkVccdFuTDz4PZlQVx9jGgXJOG4qMKqKBNehW6Y9D RFCirg6XJeiYDTLb5DL5X25zLGPvZlQC5WUMCQkc1HMPDV6bm+tpucWmu w==; X-CSE-ConnectionGUID: I5GA30mpQue46+/Imq+Hng== X-CSE-MsgGUID: WJ7RSro6Tze1hDIVCdSsKQ== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310812" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:09 +0800 IronPort-SDR: 67b58156_vGAhKgt1DbsYXPlMOY+0UCattNvvLw+0o8w1dBTe0FCbHI1 FMlf7bLLH8kSdbLXEREJiy6j8wYi+emJW03W74A== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:34 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:08 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 07/12] btrfs-progs: zoned: factor out SINGLE zone info loading Date: Wed, 19 Feb 2025 16:57:51 +0900 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, the userland tool only considers the SINGLE profile, which make it fail when a DUP block group is created over one conventional zone and one sequential required zone. Before adding the other profiles support, let's factor out per-profile code (actually, SINGLE only) into functions just like as the kernel side. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 47 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 4045cf0d2b98..e3240714b415 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -958,6 +958,26 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx, return 0; } +static int btrfs_load_block_group_single(struct btrfs_fs_info *fs_info, + struct btrfs_block_group *bg, + struct zone_info *info, + unsigned long *active) +{ + if (info->alloc_offset == WP_MISSING_DEV) { + btrfs_err(fs_info, + "zoned: cannot recover write pointer for zone %llu", + info->physical); + return -EIO; + } + + bg->alloc_offset = info->alloc_offset; + bg->zone_capacity = info->capacity; + if (test_bit(0, active)) + bg->zone_is_active = 1; + return 0; +} + + int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, struct btrfs_block_group *cache) { @@ -972,6 +992,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, int i; u64 last_alloc = 0; u32 num_conventional = 0; + u64 profile; if (!btrfs_is_zoned(fs_info)) return 0; @@ -1039,10 +1060,28 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, ret = -EINVAL; goto out; } - /* SINGLE profile case. */ - cache->alloc_offset = zone_info[0].alloc_offset; - cache->zone_capacity = zone_info[0].capacity; - cache->zone_is_active = test_bit(0, active); + + profile = map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK; + switch (profile) { + case 0: /* single */ + ret = btrfs_load_block_group_single(fs_info, cache, &zone_info[0], active); + break; + case BTRFS_BLOCK_GROUP_DUP: + case BTRFS_BLOCK_GROUP_RAID1: + case BTRFS_BLOCK_GROUP_RAID1C3: + case BTRFS_BLOCK_GROUP_RAID1C4: + case BTRFS_BLOCK_GROUP_RAID0: + case BTRFS_BLOCK_GROUP_RAID10: + /* Temporarily fails these case, until following commits. */ + fallthrough; + case BTRFS_BLOCK_GROUP_RAID5: + case BTRFS_BLOCK_GROUP_RAID6: + default: + error("zoned: profile %s not yet supported", + btrfs_bg_type_to_raid_name(map->type)); + ret = -EINVAL; + goto out; + } out: /* An extent is allocated after the write pointer */ From patchwork Wed Feb 19 07:57:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981649 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61A371C3C12 for ; Wed, 19 Feb 2025 07:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951905; cv=none; b=tTXxNxF8NErM2Fb/qQ3gJxd6h74FkotK3I+8TveciA26PGkh1MZw9vrX9HCEbIpZ7ym67DCpA8V831GZCWlQKvNXuEJbyUl7QvVOvsGfreufbD2K6JJl7hpzCbR6GY3XU6qVWHjSN1gUFFwmk8FCKYTV0CwbaKct/SjX4zSroHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951905; c=relaxed/simple; bh=9ZCYiRJ9PFdL67rXBN3m5N7l9Wz7CJZZ76R7QtZnCJk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ftacvkm4lT9hzy4g+HrEwZKTFWQ13nZ8LMNz4zHuXTILkIjx5bNjbPlFryk4wFpIbT9GNnon//QcNXCvqgHcHM6OQOXtXCS/5kxoejn8hKni1MmuR5GRcHQ8+nYBr+SQi+ZCGQAunBm9JwIDnNlzBoJ8+aqvk0x7uPgdKu6A3io= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=Nfx3T6Gv; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Nfx3T6Gv" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951900; x=1771487900; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9ZCYiRJ9PFdL67rXBN3m5N7l9Wz7CJZZ76R7QtZnCJk=; b=Nfx3T6GvZ7oyhqwUGmUsWpMNMk1sw5yy+FjiqEitK7drMwSoIhyvvLs9 z8/CTVYSK7Q0YFonpVE1Wj0SpEajRfZQQI+64wEybHtKzYrbQkRQHCTie 0vDy8Mb1XAU2ASZRkYBJXgJ8MEybnUdWMq+s/2jHorVam8Bcym/hTCerj RUW6n8QiIOCh9WdHLzKmX0LyMLRvY842jcn18wq/LqMGoXLSa3/Xlvq2b t7S5HI4EAQJze2R6O0CIS/HJdZUxgRPbewy3foKzYXoG3qpJoWsJakGLl wQFX6VfclTwtLoJ4fDQAVm1jTWSsSouL/+SzsPE3fwpiN7YJeh6MtvkfH A==; X-CSE-ConnectionGUID: 1eL6fzhZRMe8TpXe20/frg== X-CSE-MsgGUID: G8KkHyzQSQaputxAUTI2GA== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310813" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:10 +0800 IronPort-SDR: 67b58157_5VDVOYMGIM170JrgdSl1zovF6nFaQNKuvaT6HGn4UVMUk71 I4+X0MZ1qHaDvhokA16h5GnCIuMW9y50dOB3DIQ== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:35 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:09 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 08/12] btrfs-progs: zoned: implement DUP zone info loading Date: Wed, 19 Feb 2025 16:57:52 +0900 Message-ID: <927039bcd75a21e173f732929dc883fd010ab456.1739951758.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DUP support is added like the kernel side. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index e3240714b415..f0a44587679b 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -977,6 +977,46 @@ static int btrfs_load_block_group_single(struct btrfs_fs_info *fs_info, return 0; } +static int btrfs_load_block_group_dup(struct btrfs_fs_info *fs_info, + struct btrfs_block_group *bg, + struct map_lookup *map, + struct zone_info *zone_info, + unsigned long *active) +{ + if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) { + btrfs_err(fs_info, "zoned: data DUP profile needs raid-stripe-tree"); + return -EINVAL; + } + + bg->zone_capacity = min_not_zero(zone_info[0].capacity, zone_info[1].capacity); + + if (zone_info[0].alloc_offset == WP_MISSING_DEV) { + btrfs_err(fs_info, + "zoned: cannot recover write pointer for zone %llu", + zone_info[0].physical); + return -EIO; + } + if (zone_info[1].alloc_offset == WP_MISSING_DEV) { + btrfs_err(fs_info, + "zoned: cannot recover write pointer for zone %llu", + zone_info[1].physical); + return -EIO; + } + if (zone_info[0].alloc_offset != zone_info[1].alloc_offset) { + btrfs_err(fs_info, + "zoned: write pointer offset mismatch of zones in DUP profile"); + return -EIO; + } + + if (test_bit(0, active) != test_bit(1, active)) { + return -EIO; + } else if (test_bit(0, active)) { + bg->zone_is_active = 1; + } + + bg->alloc_offset = zone_info[0].alloc_offset; + return 0; +} int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, struct btrfs_block_group *cache) @@ -1067,6 +1107,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, ret = btrfs_load_block_group_single(fs_info, cache, &zone_info[0], active); break; case BTRFS_BLOCK_GROUP_DUP: + ret = btrfs_load_block_group_dup(fs_info, cache, map, zone_info, active); + break; case BTRFS_BLOCK_GROUP_RAID1: case BTRFS_BLOCK_GROUP_RAID1C3: case BTRFS_BLOCK_GROUP_RAID1C4: From patchwork Wed Feb 19 07:57:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981652 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1106D1C4A3B for ; Wed, 19 Feb 2025 07:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951908; cv=none; b=J+PylQt7JzM9snbXTDisGNn9f1pu4BWIOYoL7G3zGclnKeczS0naEcuTM1xZ/F2TWq58VpnBpKSTjlVHsH3YOg5SSIk1N91AEA+KVOIoTHKFGrMyKn6pGhvzYKmwpLgZ98LBZ61/Ek+gvZ4MGuHJ4BptnvkvOVhxyPk2D5twmlY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951908; c=relaxed/simple; bh=wDB1LTf7zAX6T0ivV5OtwomJVIYYw7AEyMOTzV20grs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=slpy0AjFWOLj+F3OSLhdEwwbODizGCNKqdpavASVG8ONgbiM9V9nROe5wMJlu/5icgnFCFN53uXPQpRd0egRm5ZHEQLrTxSfVFt5n+OX1NdjO9cBucR2NtolyhpF4QV4koXDBsC/9LYf/NWbH4DCrCEY9ktxbEUOP301XOXAhQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=Xdq0aI6h; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Xdq0aI6h" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951903; x=1771487903; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wDB1LTf7zAX6T0ivV5OtwomJVIYYw7AEyMOTzV20grs=; b=Xdq0aI6he8BEbRuos1D5bXf/aKOTLMpvpPeFQqRVlQ6tkBQ6oKnzVT5+ qkBGcLAvE5taw8DaTwo/Cz0blYdsT49yZQIIAgbqziGCqtFIRHW1ydffJ IHQuu4PorjYqs0iWGn3++YcB6462uXPXsyHVtKJAv7ypFziJCpKeIjtUW yblQjItDIXWcIFndzNCoUBbKWnO8smsq0XnbM2Lue+XBIRbt5eknEGIGm zWYzg+IwMqWDwUVjBXQQec79FihRYHx38lglj4fSdp/YkxDxaCo7fUKE6 YT0X/wtDsxrVX3vIk+bBYndhSO4BW2p2tewNdWKIc8aZhoq70lMXsfkFf w==; X-CSE-ConnectionGUID: Xl+/Kmw8Td2bNL6PIo5NhA== X-CSE-MsgGUID: MtrCYJiGQ7GVtlbtZXmKtQ== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310815" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:10 +0800 IronPort-SDR: 67b58157_aRMEhTKB5P5+gdTAjyGvBugdqhlGVCTibT+uJ30WdRaqzfO ReNhjwfBsEkxfSfmabhnnACFvICYMOnt4lqbhSQ== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:36 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:10 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 09/12] btrfs-progs: zoned: implement RAID1 zone info loading Date: Wed, 19 Feb 2025 16:57:53 +0900 Message-ID: <95b5685c2d4a7f6bb7330b6b0baf4e92833eb605.1739951758.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Implement it just like the kernel side. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index f0a44587679b..e3ee1dc941dc 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -1018,6 +1018,50 @@ static int btrfs_load_block_group_dup(struct btrfs_fs_info *fs_info, return 0; } +static int btrfs_load_block_group_raid1(struct btrfs_fs_info *fs_info, + struct btrfs_block_group *bg, + struct map_lookup *map, + struct zone_info *zone_info, + unsigned long *active) +{ + int i; + + if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) { + btrfs_err(fs_info, "zoned: data %s needs raid-stripe-tree", + btrfs_bg_type_to_raid_name(map->type)); + return -EINVAL; + } + + /* In case a device is missing we have a cap of 0, so don't use it. */ + bg->zone_capacity = min_not_zero(zone_info[0].capacity, zone_info[1].capacity); + + for (i = 0; i < map->num_stripes; i++) { + if (zone_info[i].alloc_offset == WP_MISSING_DEV || + zone_info[i].alloc_offset == WP_CONVENTIONAL) + continue; + + if (zone_info[0].alloc_offset != zone_info[i].alloc_offset) { + btrfs_err(fs_info, + "zoned: write pointer offset mismatch of zones in %s profile", + btrfs_bg_type_to_raid_name(map->type)); + return -EIO; + } + if (test_bit(0, active) != test_bit(i, active)) { + return -EIO; + } else { + if (test_bit(0, active)) + bg->zone_is_active = 1; + } + } + + if (zone_info[0].alloc_offset != WP_MISSING_DEV) + bg->alloc_offset = zone_info[0].alloc_offset; + else + bg->alloc_offset = zone_info[i - 1].alloc_offset; + + return 0; +} + int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, struct btrfs_block_group *cache) { @@ -1112,6 +1156,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, case BTRFS_BLOCK_GROUP_RAID1: case BTRFS_BLOCK_GROUP_RAID1C3: case BTRFS_BLOCK_GROUP_RAID1C4: + ret = btrfs_load_block_group_raid1(fs_info, cache, map, zone_info, active); + break; case BTRFS_BLOCK_GROUP_RAID0: case BTRFS_BLOCK_GROUP_RAID10: /* Temporarily fails these case, until following commits. */ From patchwork Wed Feb 19 07:57:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981648 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98E861C5D6F for ; Wed, 19 Feb 2025 07:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951905; cv=none; b=u9K9c+6VznuBwcShqqqZjLwjVxHrZftoexB2niZhxJEc+35eg0q/+4UPbJclBxc7uhDP5aT2b5EPWqwr7RgJdyaHa7KkZE6V1O4GY4A8qDba3vNf45Dd02ObJcEAS1a9ntKUa2hnBWJwelC/1Fx3txe/dgbv7bFKjJltisVBAJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951905; c=relaxed/simple; bh=7upQIkgKUuxpYyu2GxV6ghyvxI+5dqpWALw7zr7sWOg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WUz3Lnd58dEKu+8uiu6xY5Bid94UeyYwyvrFfqd/YvX7Kn/wZHT+oBPeE3YrbibnJAexynANm8grPaaDZF/6BLOHRdU8HlrTRkKHkljl7cooSO+ESJ2/YkQbuSoLVuu75eEf7NcehE1fZVKmTobXNy14drIFmSMT+bQBg9EtuMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=mPk9/wFE; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="mPk9/wFE" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951903; x=1771487903; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7upQIkgKUuxpYyu2GxV6ghyvxI+5dqpWALw7zr7sWOg=; b=mPk9/wFEUgeZILJwS2IBF6gHqAmxVj3O0jBqMdZbslmo5ghfokO+99CP +CPDTQdLfwOuZKStQkQ8EgLKO6BVViSSofljPWZ89/YwS94bZg7MC9+JB HQy6yfy1EOVHKeWPdapf5sJZie7rcYSJ7fE43JOQTKCynvHsEo2lfDWeV 92eNMsmGkr4geUlxuA9prPK0cCbgoTIQqSnpPpwZrgzbt0HR63DSfN0V2 yKuYkE99BFkLYxBAbl1Q19ydC5m94sGwo+LFLxTw8szwUDK311pqb5FL6 ERF4moLLNJ4XRtzVPJpBi8rtYVQFYdtDXyM9edCA1EAFvc4pK2sH7ZmmY w==; X-CSE-ConnectionGUID: 6P3CgM4bT+a7ZsUT/kKcMA== X-CSE-MsgGUID: C5KB7Q4vTN+HvsbyF/YxpA== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310816" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:11 +0800 IronPort-SDR: 67b58158_NpU+86LiAo7inLwKkkhE0SaKplaId7hDGc17oGAjQ5mapxk uKWBmLIEwlyqc6CFhhgLp82sK8du8aktYmDuxog== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:36 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:10 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 10/12] btrfs-progs: zoned: implement RAID0 zone info loading Date: Wed, 19 Feb 2025 16:57:54 +0900 Message-ID: <851b1454917770a0a9aed84564d0ecc2596c85a8.1739951758.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Implement it just like the kernel side. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index e3ee1dc941dc..10e59b837efd 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -1062,6 +1062,36 @@ static int btrfs_load_block_group_raid1(struct btrfs_fs_info *fs_info, return 0; } +static int btrfs_load_block_group_raid0(struct btrfs_fs_info *fs_info, + struct btrfs_block_group *bg, + struct map_lookup *map, + struct zone_info *zone_info, + unsigned long *active) +{ + if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) { + btrfs_err(fs_info, "zoned: data %s needs raid-stripe-tree", + btrfs_bg_type_to_raid_name(map->type)); + return -EINVAL; + } + + for (int i = 0; i < map->num_stripes; i++) { + if (zone_info[i].alloc_offset == WP_MISSING_DEV || + zone_info[i].alloc_offset == WP_CONVENTIONAL) + continue; + + if (test_bit(0, active) != test_bit(i, active)) { + return -EIO; + } else { + if (test_bit(0, active)) + bg->zone_is_active = 1; + } + bg->zone_capacity += zone_info[i].capacity; + bg->alloc_offset += zone_info[i].alloc_offset; + } + + return 0; +} + int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, struct btrfs_block_group *cache) { @@ -1159,6 +1189,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, ret = btrfs_load_block_group_raid1(fs_info, cache, map, zone_info, active); break; case BTRFS_BLOCK_GROUP_RAID0: + ret = btrfs_load_block_group_raid0(fs_info, cache, map, zone_info, active); + break; case BTRFS_BLOCK_GROUP_RAID10: /* Temporarily fails these case, until following commits. */ fallthrough; From patchwork Wed Feb 19 07:57:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981650 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EBC51C54A5 for ; Wed, 19 Feb 2025 07:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951906; cv=none; b=p9CJyYL5EW3MQnKlIxoak0RfyEmN9IPP190uJJq2lYqZ1mpwlHgJNWVNCuphPkIrIGuV7Aq9dwiED7eXA13jHoGAOoh8GmJHm4zT6pCJfXsrQyeZYztkbwj5onIod3KaXIUVqH/BSjqj2PzgtiHOAlTBfBjHEvfIJH4B7d9RhkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951906; c=relaxed/simple; bh=5u8ScMQqwj3zbKZ4tGZAkxHjJl4hMxRUyCQc4ft3HD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UhkY8UKMzul2AuxwpDhSRVRyuLqiso+1Q4+C2zODhthbQrmL0PMpknb8szVAAONEZzTC6bP0Olx9vUdlBhpgVwSA4n+gs5tSCXwATENTTvG/XzUygjvbqDMHYdlSA04EI0tFfrcmsuuIfu3msDhRY3WHEViH1i/k+VkLh1qK+3M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=VyMwiYlo; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="VyMwiYlo" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951905; x=1771487905; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5u8ScMQqwj3zbKZ4tGZAkxHjJl4hMxRUyCQc4ft3HD0=; b=VyMwiYloTsT17F6FGIFJOKUJEZjzUzBgA1ISA/u1TsiVDDty8bDocGzx EUYbaHlBwO3/eK9Z2NjJD8ZCcI9wsVM3wvrvRxixqIOfJhl/EM8La0Wrd n31Xsc1j4QJCraIKo6HRKCQJxIOqlpX6bJePk0KQcSS5dw6c8xGy0+x/F PCNhI90WjiiQ/gSD7+Vg1uo591QP9snBoQ/7FvuTI+tuEk5mk8XMyN/VV W4kexzHwhEi9z5/aQFf/8TqdEdxU0d8Fzz0MyO6Ae0v3HDjI0CV5OXyKs kLYa+iFXN00X2PN4dSE7avvn4rR1uHPFf9bzILUwH+gJCW9263EPmssNn Q==; X-CSE-ConnectionGUID: x22sfK1pQuSwnViSYLAqlw== X-CSE-MsgGUID: 8GQJgHvRTCCZdWaztuP96Q== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310818" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:12 +0800 IronPort-SDR: 67b58159_nt2sGs7w/o4G+Q/A6CD6VHWLZMYqTkD5eMwofMvjoSkuwhC PNlyjwRUBfBLPQCzAHnHW7p7NiFrE+mLe8MGNUQ== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:37 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:11 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 11/12] btrfs-progs: implement RAID10 zone info loading Date: Wed, 19 Feb 2025 16:57:55 +0900 Message-ID: <6c6dbc1e3396ac30723de8b74e40aa4fe9a59a1a.1739951758.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Just same as the kernel side. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 10e59b837efd..484bade1d2ed 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -1092,6 +1092,39 @@ static int btrfs_load_block_group_raid0(struct btrfs_fs_info *fs_info, return 0; } +static int btrfs_load_block_group_raid10(struct btrfs_fs_info *fs_info, + struct btrfs_block_group *bg, + struct map_lookup *map, + struct zone_info *zone_info, + unsigned long *active) +{ + if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) { + btrfs_err(fs_info, "zoned: data %s needs raid-stripe-tree", + btrfs_bg_type_to_raid_name(map->type)); + return -EINVAL; + } + + for (int i = 0; i < map->num_stripes; i++) { + if (zone_info[i].alloc_offset == WP_MISSING_DEV || + zone_info[i].alloc_offset == WP_CONVENTIONAL) + continue; + + if (test_bit(0, active) != test_bit(i, active)) { + return -EIO; + } else { + if (test_bit(0, active)) + bg->zone_is_active = 1; + } + + if ((i % map->sub_stripes) == 0) { + bg->zone_capacity += zone_info[i].capacity; + bg->alloc_offset += zone_info[i].alloc_offset; + } + } + + return 0; +} + int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, struct btrfs_block_group *cache) { @@ -1192,8 +1225,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, ret = btrfs_load_block_group_raid0(fs_info, cache, map, zone_info, active); break; case BTRFS_BLOCK_GROUP_RAID10: - /* Temporarily fails these case, until following commits. */ - fallthrough; + ret = btrfs_load_block_group_raid10(fs_info, cache, map, zone_info, active); + break; case BTRFS_BLOCK_GROUP_RAID5: case BTRFS_BLOCK_GROUP_RAID6: default: From patchwork Wed Feb 19 07:57:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13981651 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB1B31C5F0C for ; Wed, 19 Feb 2025 07:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951907; cv=none; b=ua14SUjfvt6PbLFIVcASZMwTFpPYcN1Bpk4vCIaijfQS0BvuES3H+IX3JOEc1d/m0ih1nXM7k+MELiJZNvMkLh2fZLqmPtTxvj2NnDRVNe17v8PRpFa2NwqTQ7Pell7nnYvyy9+Bs4bhGzUDj/0uTPiNSSsrcajRRmIJRrvdPTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739951907; c=relaxed/simple; bh=rE7EPQMY/i12LbqPqDYzxx0lVd1FxSol+C69vuSJYjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M3wWMyG+2NdOLxsuar1N3fj/dJZ8ckkI5znnELAaO19Nh51k0dtHuZ3OZJEbY1YXhqyLhsl1wAiV6I+8myLkpsuyWBQFVw+isQ8FFXNfkYtJFXNmrveSKnGquGka2JZws/9NcsPMOZd3Ue70/LLhPOgn7ogXxgzQ+uEfWyOJTr0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=NgFjSzbC; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="NgFjSzbC" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739951905; x=1771487905; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rE7EPQMY/i12LbqPqDYzxx0lVd1FxSol+C69vuSJYjc=; b=NgFjSzbCq5eRQrUBHszZJr+eMoLwtEqFpGdTZDuf6uANVT3eiNMhq0aC KnuBRRuxCGWXJehLcNIFlu6d2TZa01t9LlKpU0HstznuD/KHaUG8L7MFx XFXzQ/pU+TYqmD/Wbu0scWxVz8++eVLC90EHCuN5oX0FwZMS94r28Pn22 NaMIv9izt6DB8KnBf70nx4ae2dRFHWBRDnSMrIDr6TLEEiF6YdPJRTRwr gyIq3dPOJk8aNX+qVgLXONtKjTFuxemd3YcdH4QR3P1o5Q75os1kIZYrF 1Tk2dH7/X1XgJ9H9BmFt5Lu5XsTwEIG+7vLzum2SZLZkOwyUD+C62zyHN w==; X-CSE-ConnectionGUID: lzBDQvMAQ5Cog49vfSxfhw== X-CSE-MsgGUID: Bl7m34hbTz6ZkwbaQmJ36w== X-IronPort-AV: E=Sophos;i="6.13,298,1732550400"; d="scan'208";a="38310820" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Feb 2025 15:58:13 +0800 IronPort-SDR: 67b5815a_+A7QIDmthqDlBj3jccA+Ax5ijk6JoQXaW8brAX0TBgH9kzi zJhAxouZ2ZNkl82vwn0qR1XI/jtpnGaLAmJSvXw== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Feb 2025 22:59:38 -0800 WDCIronportException: Internal Received: from 5cg20343qs.ad.shared (HELO naota-xeon..) ([10.224.109.7]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Feb 2025 23:58:12 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 12/12] btrfs-progs: zoned: fix alloc_offset calculation for partly conventional block groups Date: Wed, 19 Feb 2025 16:57:56 +0900 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When one of two zones composing a DUP block group is a conventional zone, we have the zone_info[i]->alloc_offset = WP_CONVENTIONAL. That will, of course, not match the write pointer of the other zone, and fails that block group. This commit solves that issue by properly recovering the emulated write pointer from the last allocated extent. The offset for the SINGLE, DUP, and RAID1 are straight-forward: it is same as the end of last allocated extent. The RAID0 and RAID10 are a bit tricky that we need to do the math of striping. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 65 +++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 484bade1d2ed..d96311af70b2 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -981,7 +981,7 @@ static int btrfs_load_block_group_dup(struct btrfs_fs_info *fs_info, struct btrfs_block_group *bg, struct map_lookup *map, struct zone_info *zone_info, - unsigned long *active) + unsigned long *active, u64 last_alloc) { if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) { btrfs_err(fs_info, "zoned: data DUP profile needs raid-stripe-tree"); @@ -1002,6 +1002,12 @@ static int btrfs_load_block_group_dup(struct btrfs_fs_info *fs_info, zone_info[1].physical); return -EIO; } + + if (zone_info[0].alloc_offset == WP_CONVENTIONAL) + zone_info[0].alloc_offset = last_alloc; + if (zone_info[1].alloc_offset == WP_CONVENTIONAL) + zone_info[1].alloc_offset = last_alloc; + if (zone_info[0].alloc_offset != zone_info[1].alloc_offset) { btrfs_err(fs_info, "zoned: write pointer offset mismatch of zones in DUP profile"); @@ -1022,7 +1028,7 @@ static int btrfs_load_block_group_raid1(struct btrfs_fs_info *fs_info, struct btrfs_block_group *bg, struct map_lookup *map, struct zone_info *zone_info, - unsigned long *active) + unsigned long *active, u64 last_alloc) { int i; @@ -1036,9 +1042,10 @@ static int btrfs_load_block_group_raid1(struct btrfs_fs_info *fs_info, bg->zone_capacity = min_not_zero(zone_info[0].capacity, zone_info[1].capacity); for (i = 0; i < map->num_stripes; i++) { - if (zone_info[i].alloc_offset == WP_MISSING_DEV || - zone_info[i].alloc_offset == WP_CONVENTIONAL) + if (zone_info[i].alloc_offset == WP_MISSING_DEV) continue; + if (zone_info[i].alloc_offset == WP_CONVENTIONAL) + zone_info[i].alloc_offset = last_alloc; if (zone_info[0].alloc_offset != zone_info[i].alloc_offset) { btrfs_err(fs_info, @@ -1066,7 +1073,7 @@ static int btrfs_load_block_group_raid0(struct btrfs_fs_info *fs_info, struct btrfs_block_group *bg, struct map_lookup *map, struct zone_info *zone_info, - unsigned long *active) + unsigned long *active, u64 last_alloc) { if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) { btrfs_err(fs_info, "zoned: data %s needs raid-stripe-tree", @@ -1075,9 +1082,24 @@ static int btrfs_load_block_group_raid0(struct btrfs_fs_info *fs_info, } for (int i = 0; i < map->num_stripes; i++) { - if (zone_info[i].alloc_offset == WP_MISSING_DEV || - zone_info[i].alloc_offset == WP_CONVENTIONAL) + if (zone_info[i].alloc_offset == WP_MISSING_DEV) continue; + if (zone_info[i].alloc_offset == WP_CONVENTIONAL) { + u64 stripe_nr, full_stripe_nr; + u64 stripe_offset; + int stripe_index; + + stripe_nr = last_alloc / map->stripe_len; + stripe_offset = stripe_nr * map->stripe_len; + full_stripe_nr = stripe_nr / map->num_stripes; + stripe_index = stripe_nr % map->num_stripes; + + zone_info[i].alloc_offset = full_stripe_nr * map->stripe_len; + if (stripe_index > i) + zone_info[i].alloc_offset += map->stripe_len; + else if (stripe_index == i) + zone_info[i].alloc_offset += (last_alloc - stripe_offset); + } if (test_bit(0, active) != test_bit(i, active)) { return -EIO; @@ -1096,7 +1118,7 @@ static int btrfs_load_block_group_raid10(struct btrfs_fs_info *fs_info, struct btrfs_block_group *bg, struct map_lookup *map, struct zone_info *zone_info, - unsigned long *active) + unsigned long *active, u64 last_alloc) { if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) { btrfs_err(fs_info, "zoned: data %s needs raid-stripe-tree", @@ -1105,9 +1127,24 @@ static int btrfs_load_block_group_raid10(struct btrfs_fs_info *fs_info, } for (int i = 0; i < map->num_stripes; i++) { - if (zone_info[i].alloc_offset == WP_MISSING_DEV || - zone_info[i].alloc_offset == WP_CONVENTIONAL) + if (zone_info[i].alloc_offset == WP_MISSING_DEV) continue; + if (zone_info[i].alloc_offset == WP_CONVENTIONAL) { + u64 stripe_nr, full_stripe_nr; + u64 stripe_offset; + int stripe_index; + + stripe_nr = last_alloc / map->stripe_len; + stripe_offset = stripe_nr * map->stripe_len; + full_stripe_nr = stripe_nr / (map->num_stripes / map->sub_stripes); + stripe_index = stripe_nr % (map->num_stripes / map->sub_stripes); + + zone_info[i].alloc_offset = full_stripe_nr * map->stripe_len; + if (stripe_index > (i / map->sub_stripes)) + zone_info[i].alloc_offset += map->stripe_len; + else if (stripe_index == (i / map->sub_stripes)) + zone_info[i].alloc_offset += (last_alloc - stripe_offset); + } if (test_bit(0, active) != test_bit(i, active)) { return -EIO; @@ -1214,18 +1251,18 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, ret = btrfs_load_block_group_single(fs_info, cache, &zone_info[0], active); break; case BTRFS_BLOCK_GROUP_DUP: - ret = btrfs_load_block_group_dup(fs_info, cache, map, zone_info, active); + ret = btrfs_load_block_group_dup(fs_info, cache, map, zone_info, active, last_alloc); break; case BTRFS_BLOCK_GROUP_RAID1: case BTRFS_BLOCK_GROUP_RAID1C3: case BTRFS_BLOCK_GROUP_RAID1C4: - ret = btrfs_load_block_group_raid1(fs_info, cache, map, zone_info, active); + ret = btrfs_load_block_group_raid1(fs_info, cache, map, zone_info, active, last_alloc); break; case BTRFS_BLOCK_GROUP_RAID0: - ret = btrfs_load_block_group_raid0(fs_info, cache, map, zone_info, active); + ret = btrfs_load_block_group_raid0(fs_info, cache, map, zone_info, active, last_alloc); break; case BTRFS_BLOCK_GROUP_RAID10: - ret = btrfs_load_block_group_raid10(fs_info, cache, map, zone_info, active); + ret = btrfs_load_block_group_raid10(fs_info, cache, map, zone_info, active, last_alloc); break; case BTRFS_BLOCK_GROUP_RAID5: case BTRFS_BLOCK_GROUP_RAID6: