From patchwork Mon Feb 17 02:37:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977004 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 DEE0B7464 for ; Mon, 17 Feb 2025 02:37:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759874; cv=none; b=R5LrRjH09idKiCoR3S8x5pUr2dfP5hSmrji3KTW7KfI92AuAgXcdEeoDU2mJt9CitP7ZuhcfAfYi5FHMwUGDJK9IcDylXe59+XGqg1m5IiU/NqRlhKRFMJuqtMjs4q17cejOv/Wh6iaZgWqVd1tJwxIL2MhsRy1X+zD0EN0tR50= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759874; c=relaxed/simple; bh=+GmoyTrFRY8sm8RZBOJoyQcldsVlHuimZi/L5L+2JOs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HFn1AuUwfel9aKDBwmSELNAnijx7DQUr1rgngwjvxvUpxUReApQqR75A1akO2gPFR1YuegCnp0b3TaKXoHRbKlM6m+D0Nn9qUdLHMWDEkPdxggRi3/CRJxkiStPNpIS+kgVxvl+R9Xi5CT011w9yLRSOb+swpZlvLkmoVfPycTY= 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=kvKy9jA5; arc=none smtp.client-ip=68.232.141.245 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="kvKy9jA5" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759872; x=1771295872; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+GmoyTrFRY8sm8RZBOJoyQcldsVlHuimZi/L5L+2JOs=; b=kvKy9jA5Db7zLaRng0Zl62LZFtyy2ygUv9X1fKu5q2OK046rcrfWJvy/ V6+BVp+9qC9ZAvaR738oMv+OjeMeCMqPkWKgxyr+Lky/LmdZIZ4k1jmrW +xIdXzRBNFByxtQ/8hRcp3OSAzou+FRjS6IkkIMq3BwyUlvzWjj+08tIZ iwkfH5zfyf5hqpqeWfyMXi74SIyWrBHhXyAXLFp4P8/kP7Gk8gSa1e9ma d2R+yTdVtw4m6N6msZLQQB2mNdD2kHfWFhb3r5fT4y6UxJBV6uSGs2P5n 7TueXAK+3INqXsUgOUEjIRRK5uQCqUmDQAIJli5W1ltdCp4k7HqJX3i5d w==; X-CSE-ConnectionGUID: xbD3LYUPTai10+8kRESeYA== X-CSE-MsgGUID: bophf5QOSB2kaHajNCFHXQ== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877171" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:47 +0800 IronPort-SDR: 67b29343_Arr2UZAhh45uuX/xz+cKypTbYJem92bHv32y3gYpj/6r+Fm HzNdhKjhPzcIHBANTXtrjaPIRlEUhV2hWmNnDaw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:15 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:47 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 01/12] btrfs-progs: introduce min_not_zero() Date: Mon, 17 Feb 2025 11:37:31 +0900 Message-ID: <63892ea2d5c1b429e828ac270b517fbd05d5bd77.1739756953.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 Mon Feb 17 02:37:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977005 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 02FAB20328 for ; Mon, 17 Feb 2025 02:37:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759875; cv=none; b=JeDHUWl0EqHsIG+KnMjr9WV068qWXEtCcOiYTZiLSAyAKekRuLJngdt43WMABqoppT6DjoRW+IU3CbezA1F3MhVsNOL3pQPUN9QmtHaDINEt8ctzmqG/i4HVukMQfWPFr/9xeg79T0hOQuTC/C8E4CUPUpaz0DfQzR8WGkajNDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759875; c=relaxed/simple; bh=MppZ9PrHLju78y/W9D+X52JUgf00fP8+kOtxv7KfvY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OqVCGZDOh7M6bS8mibH44zfIBGd1o51gZYDfD+8Qnqw6xCXLbkzPnwSl5lhNmDO3bM740JqGMLrDxUpl4oL1ch4OT4wxX0F/TnvVSaDnYZ7yj9QVPJu1ECrhct8uu/UdIZu08IiznR01YXmh4RyJmVfj3IL72XtT9vwSn5JIJfI= 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=Cpiw1o/T; arc=none smtp.client-ip=68.232.141.245 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="Cpiw1o/T" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759873; x=1771295873; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MppZ9PrHLju78y/W9D+X52JUgf00fP8+kOtxv7KfvY4=; b=Cpiw1o/TFByyi/hQUpDtVKpAUOlSVmLtP1yQKiWOpw7FPvJqAw68EcWU aftC+JBvLrI/r9XTSFsYGqxgUgXk0vxZVRMa+auNFiQDNl01fM2oKCSrc +7iHCMO05L/8tWobwn6Un6Znmg+pK94LlYeqk9u661gGwwZ7sh/xBFDw9 +31Bn8wD29UZ455yKtEGwWZWI/kngYPvEQvjjBhzAFPOxofeWFh/gOPFZ nYgTYz/g+X34AWoPxO5CiQRERLjtTLVbDNIItKpod/8NKI2SaKLjgH7wn MovKEcei4U3GJFzWrmFwCk9i8JMJj6943R/hee1+zSKG0fPfTji9kVnyL A==; X-CSE-ConnectionGUID: 42NaB2UNTs+LY46hsEM2GQ== X-CSE-MsgGUID: 00tLDPUHQkSPYtVFSKeZYw== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877173" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:49 +0800 IronPort-SDR: 67b29345_Po5Lrquxd8R9/fcQr3q7EyzNRbadNmtIDdYqRK973D37kcu LFNmYxSHBtH2vGWnaXpE8fTV6QANv6hIvRsKisQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:17 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:49 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 02/12] btrfs-progs: zoned: introduce a zone_info struct in btrfs_load_block_group_zone_info Date: Mon, 17 Feb 2025 11:37:32 +0900 Message-ID: <48e5d55e3d4e773cb7952ac14978466dcf93a32a.1739756953.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 Mon Feb 17 02:37:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977006 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 77216145323 for ; Mon, 17 Feb 2025 02:37:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759875; cv=none; b=VkRdh2U01dmYAoHz+Dt83j8vTnJrvKGGfTMyKaxuF2zsfjC1kaMML8WOZCpsePw0+lrnOecg3yIhEDsU/ihda4LO92jufKQS8uu3cJVWxqJMRXnuBSpcD0iy64MVrGyslIaFyO8Yc6JjqXhItqLGhDR4PaznGtjRgZsQby52R58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759875; c=relaxed/simple; bh=6t5MgUF49kRf9OwZbGpXEVELI8+Fg7uXQvdw4/3oE58=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PjIaUmu9zykFRtMTAsMzbjH5zsv+E2hjUzhUv0r9XszgrN5k00y2NmyWzvvTSrG0YoWp5X1BbE4AV0IjY+Vrpag4rNPUH10rRghXpm2PEdnOTntQVheEJxHG5l47v/FeUtkexvQxm3qnGYCNf9XDI8PEYCJw02TuBj7jzHA2Kpw= 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=qmcKHPB2; arc=none smtp.client-ip=68.232.141.245 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="qmcKHPB2" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759874; x=1771295874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6t5MgUF49kRf9OwZbGpXEVELI8+Fg7uXQvdw4/3oE58=; b=qmcKHPB223CkCcN2jLE75uKnEWs9vq30OANB9Mcxhb20cShKC0SL1yIM s+UWitZEOy5ML1cV3GuDg0LotuMLNJxNO0hUnbWenCcW7TieTGaHzIajK /I4ZGhfzwfww7WWva0dcFI48IzIO/vR4KplGlasaqluTwDH/COSmTV1Nm bnOWPAEn3NLxM+OTw0R3ikZAX1wZ+AfNLq6qdXDPKr4Zydedq3rN6RXMS IVO3/RNpHvI0AEU/KGOWxnAdw1TGWw2NZuJkE+hVxHgDlANRdqHdMgeHE G2X7+Bb8poT0fogk82e6dDYX6TY1BrWbVfZoHdT1tisEKvJc6Zx6FkAEX Q==; X-CSE-ConnectionGUID: E5dxU8MCQCyFbuUysFwWHQ== X-CSE-MsgGUID: zdPhd1rHQRiRYWO0F9naAg== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877174" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:50 +0800 IronPort-SDR: 67b29346_uF1hsDUbxRRN0ueBdVFdAZSaB+x2xnMC6Dp6qzpuVjiQP12 Kr9KexjCtWyOirveHxMWnY3qyCRYiuqBZkvHeFw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:18 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:50 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 03/12] btrfs-progs: zoned: support zone capacity Date: Mon, 17 Feb 2025 11:37:33 +0900 Message-ID: <8c68704eca02321ab9577d4a1e96eb83751fbc35.1739756953.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 Mon Feb 17 02:37:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977007 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 B4CF91487D5 for ; Mon, 17 Feb 2025 02:37:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759876; cv=none; b=tT7pwuoXubO4sULeFLpd7YbzS6CJMSj8fzoaPUQpRMpfyd403AX22F2p2n2hg0KxK7fFZH14ffD2rB9ZR8il7aqYPbCWDhtAwALAwYpvPtkEz1M2ky3thklKmwJxw0glUnThgZMWRgkFwT4nCRAr2ckd7gaExKJrYzp/eTEc7d8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759876; c=relaxed/simple; bh=l0MELxl+UYSrAkXECBypm34bdJVZBkjGfRlCTd1xIeI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cwYMd0b7Lp4hSc9moIspGK4ntjHC1GyecRMYeWDzAhBaWUsXamBNIerJKNmjoSC8nlLmK/zEj0YxKwYJvU0NMf/jlJ0HV4BaHetEGufAzLpCu9yP4+lBjUVNeXCHqPkMvs/Y7u7ECH/6ODegS6qEP53GaI9PNpEJtGsc0tqSipA= 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=iETxpGwm; arc=none smtp.client-ip=68.232.141.245 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="iETxpGwm" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759874; x=1771295874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l0MELxl+UYSrAkXECBypm34bdJVZBkjGfRlCTd1xIeI=; b=iETxpGwmcRQWzkzGagwUQATOfOJx8t1KilH/osJCNcwEjjWmMsKHmnYr ahUcNYOHG93A4Ps44jMuPlnFL2GFSGKy1VbXKrA3MDGroux+CK0zKHIP8 xHY0VcaVhrv22pJ6+k+bI6hYljYV8mArzdbl/UHGTlvjbaB9M+Ai6sSQh Ks9n4ER+w4J9Jlgfz3CowLc7LopjPNpHhoYMaDDpUSxlrXja/R09zGrZt 5mS8zuAcBng5A5aH2yQIEFcvnKAklct2JO3LoHg685j5s7rmC8LCRqOOR Na/4Q+Ck8WGiZp0FLJKTz1Canbu8N/P085jB+zVgp3CPELcojQdBhrOgs A==; X-CSE-ConnectionGUID: 1wKeWexJRoa2TNEOCuSHSg== X-CSE-MsgGUID: lt4r5YedT2axY2tk++qkwg== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877175" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:51 +0800 IronPort-SDR: 67b29347_CKQ9JPbAUDKtO9zARqHYUHrmZJ9IJDS/eOtUJ36/m0Iose4 0fMD+N8gh/DfNAZ9TXO9O21xCRjQXOGTsCsbTRQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:19 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:50 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 04/12] btrfs-progs: zoned: load zone activeness Date: Mon, 17 Feb 2025 11:37:34 +0900 Message-ID: <58ad7ad0db8a17c2e27a54314869c3e94f7ab048.1739756953.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 Mon Feb 17 02:37:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977008 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 CA9EC14A0B3 for ; Mon, 17 Feb 2025 02:37:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759877; cv=none; b=kqHeb63udIuCFoyYQBiQi3hYzOkLMp2oa6IJ6t79ENFYBXJ+bkNrRcoyt/j9cphEfETvR69vWPy7zvQS8XBn7fb9ROZH7bzcg3UAgXkOwIqjtKPv9FNV3sx1skqUbVHHXRsRCx4ErAXJ56VxDrgG/Wf/eUiDg4h133+d2ESNISE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759877; c=relaxed/simple; bh=wrHS5cUCM5L5AttiYjQt+RQCbR4CsmRd5QhN57OxLzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bKRGiBlwn/Lgs/efRfXWJm8tTuNihcbVnHB/dLnuX6gUqy22cEwupFdb4zDWq2K6BX8deHyDmD3hvkSNli56oKeiW2Wy3AOZ1r7xo/PZtE6Z423UaofGOzFdCihG7L5hz+tK/KCyeUCDak0jCK/uPqiZecPkcqpZt/bSHXpksyI= 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=TzkBxIFO; arc=none smtp.client-ip=68.232.141.245 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="TzkBxIFO" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759875; x=1771295875; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wrHS5cUCM5L5AttiYjQt+RQCbR4CsmRd5QhN57OxLzc=; b=TzkBxIFOcA3kNvEk8lx93tgwj43h9+FnjYJuv10KC3pH6kbwTCKjs2MH ZDrIbjFQv+6DL+DnncmHPBSSsfYGeuSIE9/RiSfWnxgaxQ8lMf6U4S9RI e7PtMfdewxkoMrGQIJw+zkKqbUEDrqtONtDPSWTuguPEHZBoD7veQa6C/ 83ZVszgT7L14MhnhLBvzyBbwyrUVaDuSumbZfGO8xcEGEOLk2lGZ0Zpyl u6/LCgZpG94SF/C9bdXU0ICXf0HVVf5a0MuHRZlHyjJ9yjZgJOm9murde qCB6IklAtmLcZqpn5jBu/2dZxZVOEYe67CWVj6TjU6QuvqYc4yXh+wjuG g==; X-CSE-ConnectionGUID: maucAVaaRo6BJZcxVb8K7Q== X-CSE-MsgGUID: K7kFAUbUQ1azQxwFhaTHSg== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877178" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:52 +0800 IronPort-SDR: 67b29348_/H5eR4if2t2y/PGizk+GZzeS61z1fdhp2u9X8bBADhHes3h DpcRjcWBQbDfDydLQI8OjvHZCJJRJcmEXaTF3dA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:20 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:51 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 05/12] btrfs-progs: zoned: activate block group on loading Date: Mon, 17 Feb 2025 11:37:35 +0900 Message-ID: <0a272ad61dca26d4ee7f1e7ba474685b21825a05.1739756953.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 Mon Feb 17 02:37:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977009 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 1A43A14D2B7 for ; Mon, 17 Feb 2025 02:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759877; cv=none; b=KKdCxD8qGrPygyrGfc6eZu3dpCZS6X2SgZnFExTuQMLWjpoi12VZQjg3u+rK0B2pOom82YGwWFcx+Bzscv3iOeCP2N8AEzhvFsBoTmWQKP8PqfpMDSlQh4YA4uLxwuIuyIa9SsmaQ+1cDrEAMtBAX/Xd90JasqNHvXXHaxKE2DM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759877; c=relaxed/simple; bh=yXhAD6P03SJMemKKQjfkaDbiWr7LwH2+E5dAXD+GlNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dPf6RWujy6cRU7jslcrA7FRlaSxosxLECHpTtPQIyF5U5SmSNmzjJZSWffXcpqHUOLdwluPHeu5WBjHQyeyqc7X2TmOrV04/A8PBMTao18gLLysbWhElXl2CSz2ekVFMBo0DkY+xpmdniJYLKLcfwotzOXIFcx9jTOKpvrMCcz0= 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=fJgglkiE; arc=none smtp.client-ip=68.232.141.245 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="fJgglkiE" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759875; x=1771295875; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yXhAD6P03SJMemKKQjfkaDbiWr7LwH2+E5dAXD+GlNY=; b=fJgglkiE5blOb3pixxeAcOlvOkW0hAZmypICVG0cYSAowwJuSWeIkcB5 IFqHzShKw7MKsXD35HszDNZzBBMGjlu8G10hMVllXCgLo073HBZSWXBgg AduyrhuZDFH0236KxGmOXosL+YKqn804Ifr8KMFK/88FDS6JypzKkAkfz 0eahgnsKZHt2H1TuBeKH9ValbuAVw9fReIGTplCZ495kZRqnQa0ApTRGO yFsHzbJTtoEQzuZ9b78S5Yvi4vhImWVNQWRphFfJEd1mgzTcv/whwINUX Utm59sIIEPCFK+N4uurJAV2RbG1fCCexw7lKCC5ZKvJKGwyXmr3KTMqai w==; X-CSE-ConnectionGUID: Z/6NVwM7QO6MVPhGJG45gg== X-CSE-MsgGUID: i+vfu6NpQOWhad8swqA4Ag== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877179" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:52 +0800 IronPort-SDR: 67b29348_5EOnZVRltFQ+FE0VbZsrIaYDUmCpCPg3rC1iJF9JykHtwvD aSXcTZksfN4VxIuoX2bUk+DctWbD57dUFm+SO1A== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:20 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:52 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 06/12] btrfs-progs: factor out btrfs_load_zone_info() Date: Mon, 17 Feb 2025 11:37:36 +0900 Message-ID: <13b005c387446c5bb3e0212ba31423e1458688de.1739756953.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 Mon Feb 17 02:37:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977010 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 8E17D1531E8 for ; Mon, 17 Feb 2025 02:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759878; cv=none; b=GTgrpwQbqDmk4NZYqVgwDy9T+SuMWRXOOxXQuwwMcWDanJ8yeKGOFRYyM6PDTKH54QTtQ2IAsI7kcBtud/W6I94jxheHHnbRvwzbiCEk4DkuGkf5t8/X0HF4aDsAItasYkGJJVyZkQfKdL8j20au1/VPk2DLnWyWz6KtD4Kw8JA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759878; c=relaxed/simple; bh=x98HO+Od0wUM+b91JwZMMisWEGzHFTXUmgURwl+FebY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a/clEFIc3rJTCunwf92GwHlqFYOSO4bzFqQpvIHqDKTuZy6J7zmPy/N3Jqs5z/VVpzED/QYh7XRM5gS8mVN54C+XvBcvL+ZHsaFDqrxluW7xNmBLCnxsHmV6bAScSJJfnAd5Q4PhsOYRbNilm/PnpPC7eyZ2mqzVOMLQd0ip534= 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=AM9RWfEj; arc=none smtp.client-ip=68.232.141.245 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="AM9RWfEj" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759876; x=1771295876; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x98HO+Od0wUM+b91JwZMMisWEGzHFTXUmgURwl+FebY=; b=AM9RWfEjkFOHuhTxytvzxGZl8w+FhDZQqouySwJbUYWcvo3OYf/OJjp8 YvmJKFqesdILpZDVcBAdHnej470tvqiNw9qNFuMF5O/meOLEr/jjzg++X g14yNAcOGyGnqa4BKCrZwEyW4XYGnWyi8TgOYExBmBa+kWiMklJTPeL0J CXv5PV+O7mdweklJzXzVEGJFTxOmcPlg6rD4Nd9Z7nKIEo31znaliZpEy PTEZCnPeFfV7MKpS0TEQjwJ3CVZTEu3rwh6g3WZv1UfKLl1CN5hscezg9 nBzO7FdAVypzeSCj1BWqM+LoVP6hT0mb6NunoDrrZti1DSrqX23KjWzRp Q==; X-CSE-ConnectionGUID: WTGYj7IuSPWzjfWd3hdWwA== X-CSE-MsgGUID: M+/59twLSVa3g19SSGXwcw== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877180" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:53 +0800 IronPort-SDR: 67b29349_AAQJBwzLLHCMpAwPV9FFng+NoTp2OU+7q3kvRpe+2ghy3iT TNar7i2jyA0+gbOTK8t+uvIa++wmmwAGVmAJ3Iw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:21 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:53 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 07/12] btrfs-progs: zoned: factor out SINGLE zone info loading Date: Mon, 17 Feb 2025 11:37:37 +0900 Message-ID: <11de06f6243f4f048d19f105a170cbd6f8e5f4c3.1739756953.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 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 | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 4045cf0d2b98..3bc7d6ba1924 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,20 @@ 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_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 Mon Feb 17 02:37:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977011 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 86EC8154BF0 for ; Mon, 17 Feb 2025 02:37:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759879; cv=none; b=Ffv53RTzsjPw5CatZHhv6mcv1Ltw0vH/di0fUMpPmPtc3n76r18qlMBK4JccVoLldK8mT8KMy/xPSwKNnz/uuczcQvhrXvmHu0bmlvgAPqQWhfi0osy46Dl2bxPVZY3IxslCPzqvkp5AMM9fzfFcMbKzi3CNMdWGcnUyK+S/B74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759879; c=relaxed/simple; bh=XyRsHkETUyYYLNR4SHzQnv3YJprO43QSz2YZfBfOO2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XPHbAo3w+5LLxe8IXGRHtGWmEDgtLHQInPOfqAxM5v5c2I0g06QlxSdQhTnSjEWFv2xuNu5z0IcxIrLdOqyHrXIsFctcMhZJ5AOHnN+Vt8IaFvU2IwCDTJT7D+gV0fW+PMQMzJTaS0WqDo2pg3TtCEzRA63jO6UDFFWDCIOUud4= 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=nEMopIgK; arc=none smtp.client-ip=68.232.141.245 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="nEMopIgK" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759877; x=1771295877; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XyRsHkETUyYYLNR4SHzQnv3YJprO43QSz2YZfBfOO2Q=; b=nEMopIgKamH2sSJo/Z7wC8TLmAehtVsupfhPt5/4Hxn8PlgAHtoPJEH7 c1woa3qjL7ND3zeElzvQEEn78HJw1DVIcpGGT3QkQo0gBa37T/sKmj2tG 9nLOLYX5aD0O7CYS2VZEq0apOhR1OcSiAwPmxPjBi8T9V9O4+QA1Fxbl/ /Ddbj6r4ucytfMiLhgOeUE7dtC5YllpJ5z0NwBMK4DpuYDjRFh+v5yJ9f hz4CfHbdjVxnEiyRzsOVLuX1HBL3/IABgwURFXklCiPOrftK6klvmkLwJ YDFJuqOfwBYYC+6JNuz1uACqPOFQ4Z+CC8ZoS4Ga13Zw+/skOmR85ceL0 A==; X-CSE-ConnectionGUID: qDe+u9bBRxGYlRdPz0Tq2g== X-CSE-MsgGUID: Ty/OQZ5iS9a+oNgl8r/rLA== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877181" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:54 +0800 IronPort-SDR: 67b2934a_Wi79Xbj582gJW1MkgeJF5QuzlrAfv97VXyNXBjNeRhZpVZ4 hPcjfXkjdPT0PfIYOVkD2xpjKdbJq09PTySfTGg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:22 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:53 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 08/12] btrfs-progs: zoned: implement DUP zone info loading Date: Mon, 17 Feb 2025 11:37:38 +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 DUP support is added like the kernel side. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 3bc7d6ba1924..dd1ddd01cfba 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) @@ -1066,6 +1106,9 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, case 0: /* single */ 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_RAID5: case BTRFS_BLOCK_GROUP_RAID6: default: From patchwork Mon Feb 17 02:37:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977012 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 DDDBF154C12 for ; Mon, 17 Feb 2025 02:37:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759879; cv=none; b=Xfb/cvokJgyy3ZsSgR/Pt9IvB6sVzCtG2A+ESamUF4pwSzMszwCmJc3rFKlGrNdGC7TqF9d6asi+FGLbkOLLZO97zZjShrvuyPXgvuG3xy50+o7BGqjROk+vzLDMyETiBHo3y9xZeVjvUShtsotTbExOoGteJZVjfYyMtx94Tvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759879; c=relaxed/simple; bh=CMmAxJYBEeYSWdkyk9Atzxou6BUDtKaGCsLgPRb7+8Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z1IUYDUH7V/LUE0CKe2lJcIe9v5jSE8KCK1Bk3MwF0UGGOOhrLVhSXc9GYihIibr09xu2lZXcKzFo/ulKAYRXFN8UwsDyaYHuMXz910t6dxjQqp55fgsj18MSmldrOEiDq+gQUlxf9YFlbgT/mM5ay0zo9RRj2Tn2zL7NnWWOxQ= 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=o8XOz+js; arc=none smtp.client-ip=68.232.141.245 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="o8XOz+js" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759877; x=1771295877; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CMmAxJYBEeYSWdkyk9Atzxou6BUDtKaGCsLgPRb7+8Q=; b=o8XOz+js2ypM9KhqSCQUHVnhQoliJD73NTPsrf1zpkN2LqUXffBZypSa 58QlJZL+fzhLFowfAgZGGuDgjGz0jE6fhKPgUhjgnMUKDCoPDiZMwecbt Df2l56bOp/S2UjH7AaZs5s73lupOzJ57oMHcMxnJPzc9jds63yhpD/smP zLMZoVCJzyhRTuUlc6GJ55Gc7yZmBYN3NDKVbV2+Kfg/6ndY0rzYgXIKC IQTjXe1VAKaLfjei/ePewf18BBoutbwc6ykPh5iOD13paWWh5gKFjtaIi RGC0Gp4iTmKJpNcGdJlqnYZ1KwIZaABtR8v27ducumi6nnuCESxgZW0xB A==; X-CSE-ConnectionGUID: yAJXi5A3RomVV5dWsP19FA== X-CSE-MsgGUID: dbI5h4H1Smi7uiB6AvuVzQ== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877182" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:55 +0800 IronPort-SDR: 67b2934b_ZJbcG9xHvZX4l3Sg+joiIkaJOxg4L18iyt6ByCHAJ8V+bDa juh43FC1scZ9BGfBc+r1c5Zth4ohM/bIDBdfVzw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:23 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:54 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 09/12] btrfs-progs: zoned: implement RAID1 zone info loading Date: Mon, 17 Feb 2025 11:37:39 +0900 Message-ID: <55ebdaf57d776bbe07d493c01316d56421e15772.1739756953.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 | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index dd1ddd01cfba..e1cb57d938c5 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) { @@ -1109,6 +1153,11 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, 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: + ret = btrfs_load_block_group_raid1(fs_info, cache, map, zone_info, active); + break; case BTRFS_BLOCK_GROUP_RAID5: case BTRFS_BLOCK_GROUP_RAID6: default: From patchwork Mon Feb 17 02:37:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977013 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 4FA3F15666D for ; Mon, 17 Feb 2025 02:37:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759879; cv=none; b=mSH0GloLbC/I3EkFcI155Y1t4Q2HXr64idZQCJEWU1c+0Yl9+ghoupZzVqvJSOzZxdPOZhgzeQkCGauH5lfUsdWEmKCeGahW6egmFoEIrZTkDrC9jhBLoTO1kYfKanyiUK7fNQajaQXTpmlr9QKeD58/D2f+1V6dezo+aOQ+5cU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759879; c=relaxed/simple; bh=O27OusdYNhsgxH74Swmaccj4rSCsOhnr5NYlFVkGR8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oe3f+feTX0anv5UFUXsQzgHrP4rME8/iftDEBassS5Eu3Z5FyLmur1jVa1AaXIGNALZYlB9i9tq/oNZWYsEUUOmsZujZ5KkKa4ZQlVa4ds3M4UZgfabVR90U96nD3AU8p2kirfxVzemcLQqOLpKWwaNGjB4FIKaKxtAbFt6ctA4= 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=D93cUbz1; arc=none smtp.client-ip=68.232.141.245 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="D93cUbz1" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759878; x=1771295878; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=O27OusdYNhsgxH74Swmaccj4rSCsOhnr5NYlFVkGR8s=; b=D93cUbz1G+9RWKh6N97ej3lRkgYe6NIaovejnG6p6WZ1/CvaYMY2/+Sv o2E/75W4PcXaYSrfulESpLed/dHEJ0yLhbrIIK9zBqqq/ln3jgrg8B5zS cUPnbF6EhsW8jfe5ZJxMvBeSfv8Ry/QUwxmKkLPYOrM2vadH5I0LzYOIR 1nZieinAQscqKIKdbAjuogG7zSET6hue6tSF0Sd3Jce4+INBxmmUM3eiW Mu4mEMMYq5B4Q4jpagh5ijMnz8sGvd8dno/nTMhQPeXnE7PSOfztelmWu xJ94TTcUgheH1/AEBQjga7pKszgO2NPRPyn6H9HGQVuqE6StYAOGqdnhx Q==; X-CSE-ConnectionGUID: PMTVCDNqSD+XAMoDRH25QQ== X-CSE-MsgGUID: KByaIgELSouKsR71IO4gvA== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877184" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:55 +0800 IronPort-SDR: 67b2934c_RkR+3/ylI/l09Unp0vmTJYIEDV9ZkI82xpY4f3pD6GkTJFF ghiXrntSA7mg+X+GElHVVqZZsw+u9e2Q/h49kjQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:24 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:55 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 10/12] btrfs-progs: zoned: implement RAID0 zone info loading Date: Mon, 17 Feb 2025 11:37:40 +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 Implement it just like the kernel side. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index e1cb57d938c5..66d76427d216 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) { @@ -1158,6 +1188,9 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, case BTRFS_BLOCK_GROUP_RAID1C4: 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_RAID5: case BTRFS_BLOCK_GROUP_RAID6: default: From patchwork Mon Feb 17 02:37:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977014 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 363ED1632D7 for ; Mon, 17 Feb 2025 02:37:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759880; cv=none; b=a15iOH6j/6PdKpttLf4bhqxEwN8B00lPZjizbc7RyjfpsQAlybajGsKy/gGGxFBGAHZZzBaJTAuNdJaEAaOzrCgd6Ngzcp62BN3MrWi3gdZfJlF//skYtru5sZ+DyqtyukvVWsYziwUrvnvnn5vU5G6AilPy8XX7k8xJT1IF8Zg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759880; c=relaxed/simple; bh=b+yGm9FvXIHtDZI9mURLWLDlVxw1yY58rwvu/aAEMpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jgSWC4Hnwde2rNypzap/zlxOmyfNQIea5EBSExcars/MiYmbidGipeGx0Haj9GPxcNe+PZic3Z87YBY4Rv/tmWst+6lo9uxKzMiXW4P6Eieetd5MdEdwg23v+zkwJDhcx8k7tXohrv7OYxjqTQezWehz0BToM6PBsSdpJ9a4eCA= 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=afC+3QXg; arc=none smtp.client-ip=68.232.141.245 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="afC+3QXg" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759879; x=1771295879; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b+yGm9FvXIHtDZI9mURLWLDlVxw1yY58rwvu/aAEMpk=; b=afC+3QXgTuVMhR7+MUXsgBOTTWObe5bR2pAr0TxdY14moj6QsMd350mZ zSLPdyGy0048NRVJ5puEK8CwnkAxhk3PFXAps5YzDpHmV1OzZRzfXSrUr E7xfGoFtSQw5hMZA32MrEi7j8CXrBjcvUbOb+79Vjvnlh4JjPVpAOeuYW baWxk0rsXz4mNsetzf5Td8+9c8BG1LFvS0/V/N+M+YfCTxxg3gQuRrrj9 TtoGApCmlF+tsnuEDP9k9MkYU/f+FgXIwP2R4oo5/DSh8iGn/HDWI+18K OtCXo3gplxCjlDtoyi1zhr8mb29ALulxs4cHhBQaQndt3NJLo4+37RyhY A==; X-CSE-ConnectionGUID: S8854YCrR3eBuuEpa5TVHA== X-CSE-MsgGUID: 9Z5zvQvoRMynatgeq6nCBg== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877186" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:56 +0800 IronPort-SDR: 67b2934c_YijFnOw3mgE9ougtYG7W216Tz918ub5+gvjdQ+kBi3Zxh6R bgzwmP/B3MLs9qDfPmn4Itc2uOLPd93rywjGH3g== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:24 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:56 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 11/12] btrfs-progs: implement RAID10 zone info loading Date: Mon, 17 Feb 2025 11:37:41 +0900 Message-ID: <4e9ffca4b694c1e16a2b30b153e1de490058a601.1739756953.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 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 66d76427d216..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) { @@ -1191,6 +1224,9 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, case BTRFS_BLOCK_GROUP_RAID0: ret = btrfs_load_block_group_raid0(fs_info, cache, map, zone_info, active); break; + case BTRFS_BLOCK_GROUP_RAID10: + 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 Mon Feb 17 02:37:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13977015 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 8652E634EC for ; Mon, 17 Feb 2025 02:37:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759881; cv=none; b=JMMAU21S8UqyUFaoH/2k7qENSnHbTI3RNK3bygsE//fTIEtVoFc3pyx29exbNttlH6WEr27WygY9OfzQH18rMdX4JJKKW7i0UhH59T6GqsR8cIovgpll1SkBRgs4gnZgAQ+JSXgKkfGwh748gOUjQvrY2dnCQ2UveZpZwkV3m3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739759881; c=relaxed/simple; bh=rE7EPQMY/i12LbqPqDYzxx0lVd1FxSol+C69vuSJYjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SBxQ1saY7CwbxJiDrzUjju65VcGmjA3Gbzb18qIdaCEUd6JJnrlkokDKUuEpbTTQifAwD8Osa+cq2lYHIrOvyOTgbB8P/dDnMkf6EuPJfNtVFMkDV45hOJzWJdK+1AlHoZHsxe36R3LkIqWqqTpnf0mMIFor1+q5sFyov9UlK1g= 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=N07n+YRu; arc=none smtp.client-ip=68.232.141.245 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="N07n+YRu" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1739759879; x=1771295879; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rE7EPQMY/i12LbqPqDYzxx0lVd1FxSol+C69vuSJYjc=; b=N07n+YRuJF2Z5BpYHf03Z0DNEq4D2S62wHfGZgEy09jRhtzvjOH2pVuy fKKQ0j/4mTxWoPa1eoeIdVkO5tpY/Nzk1N1gddLpdHCvCaFFdnxX8DTzc 3za+ifYCpzfj5IaoUVDq/AE67kw0wU9J0tw+RSGpYU6suk2K1IXEd7GBc r/QQdOm/BcmuvZbUED29PmRF8zjIC0N8dL7c1vm1GTYFdZ6dWcd2Lga1N q1YVMlLy/qrK8DWHqY5ELicu21Zv11Cb01xPqJXdnTotLyn+M+mMhb0Jl g+ko/MfGuTWsJ8NMpFYgasOBotf/7U+7G/SESiUHFwbS9xdTr7Nqc5eEm A==; X-CSE-ConnectionGUID: 2oNZMPlNTyKNHg1RRu5yKQ== X-CSE-MsgGUID: Z6pqOqviSlG12UhWQjQhNQ== X-IronPort-AV: E=Sophos;i="6.13,291,1732550400"; d="scan'208";a="39877188" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Feb 2025 10:37:57 +0800 IronPort-SDR: 67b2934d_xvmQIvbDnZWomafTOcFmH5x8Gsh7Uvmv9rISFetVxOHBHG5 +fq26VI+fG48h6q9/DorRpa3GmSJzUYoZAVWLPg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Feb 2025 17:39:25 -0800 WDCIronportException: Internal Received: from 5cg2075f7l.ad.shared (HELO naota-xeon..) ([10.224.109.184]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Feb 2025 18:37:57 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 12/12] btrfs-progs: zoned: fix alloc_offset calculation for partly conventional block groups Date: Mon, 17 Feb 2025 11:37:42 +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: