From patchwork Tue Dec 12 12:37:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489210 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Gbbt9rz3" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D800A10C; Tue, 12 Dec 2023 04:38:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384696; x=1733920696; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=Poy7kvGZE2juSHXFRnwi+t2LcQTptZvXl+fIR2CJQao=; b=Gbbt9rz3hmobQgifqcHxPpqzLrCjwXCAfrUmiKVuEIIxpmfbiHxa1H15 amCQuOHNLwVHYf69T+LBof0YupLyHME3St6RFW/A1WkUN2JuxW0iNptIH JBB0P7biZwTs3oBi3vRxWSXM0mWwiom9jUzn4xI/F+odiZsJpm0HQO6zP Txs7WmBGjQPtm0K3Kk6Wjj3MMzrNMgcB7pO4EUBNXHsv4xEjA1YRFZt61 +Qs/7OdYDwZ/rQSeOvYXrfG8y9tJm/+AoaE+X0u/PmZxZ763jlTlMpoih nmFQQVDBxfP/Nzxmh46Y+XwqvJCHifxs+Mkum90XTUDQXKAeba/FORC5N Q==; X-CSE-ConnectionGUID: Dc1luYC5TPqbW69VnjGZtQ== X-CSE-MsgGUID: C7rufPamS+2oUgir46Oy4g== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629786" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:14 +0800 IronPort-SDR: fWB3rHOB2x8AJctoYVrruqCvm/BR9kOPdTw2sd8gRak3RfUxwAwWH0q4m56BLJ5HClB7fZNVfl M05RYLG8OhCQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:27 -0800 IronPort-SDR: fhUeR6/hDirl0xmEVTtn/EHzTfiTR86jI28zwK+5PBLCGZOwqHoY3FFu5+SoxSo4cedD4YNxZD ZV0FNzkfl19w== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:13 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:37:59 -0800 Subject: [PATCH 01/13] btrfs: factor out helper for single device IO check Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-1-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=1953; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=Poy7kvGZE2juSHXFRnwi+t2LcQTptZvXl+fIR2CJQao=; b=tdbqfIMC7FsCjaWlWYQTNAYg00mwmNnZLJZ1jukrQz3iG8+Ly1UxlQnl/aQRsgJrOyEUYMdWv RcMUrLxBT9yAGBTzKHf34GVMLDNvUUXlpOKg2HY7GlEk7vG9VY7ErE9 X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= The check in btrfs_map_block() deciding if a particular I/O is targeting a single device is getting more and more convoluted. Factor out the check conditions into a helper function, with no functional change otherwise. Signed-off-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig --- fs/btrfs/volumes.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1cc6b5d5eb61..1011178a244c 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6330,6 +6330,28 @@ static int set_io_stripe(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, return 0; } +static bool is_single_device_io(struct btrfs_fs_info *fs_info, + struct btrfs_io_stripe *smap, + struct btrfs_chunk_map *map, + int num_alloc_stripes, + enum btrfs_map_op op, int mirror_num) +{ + if (!smap) + return false; + + if (num_alloc_stripes != 1) + return false; + + if (btrfs_need_stripe_tree_update(fs_info, map->type) && + op != BTRFS_MAP_READ) + return false; + + if ((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && mirror_num > 1) + return false; + + return true; +} + /* * Map one logical range to one or more physical ranges. * @@ -6532,10 +6554,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * physical block information on the stack instead of allocating an * I/O context structure. */ - if (smap && num_alloc_stripes == 1 && - !(btrfs_need_stripe_tree_update(fs_info, map->type) && - op != BTRFS_MAP_READ) && - !((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && mirror_num > 1)) { + if (is_single_device_io(fs_info, smap, map, num_alloc_stripes, op, + mirror_num)) { ret = set_io_stripe(fs_info, op, logical, length, smap, map, stripe_index, stripe_offset, stripe_nr); if (mirror_num_ret) From patchwork Tue Dec 12 12:38:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489212 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Xpt0TSnD" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E12BA10E; Tue, 12 Dec 2023 04:38:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384697; x=1733920697; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=URbmpvR20VX4btmngKh2nyV03iXD9B+5IvYzGplfqg8=; b=Xpt0TSnDghT+4+rwTyViw649yMN48LPpPk0lROp9GsKpBshM9zFDtoz2 el8U5Maf36XttMANzMtXiYX3mFdI7QM497+OHFSiKDNLESybEg0azYjR1 HX1Oo8fhytWIV+7LhgJvbmC9ubNx+N/wDsxynY3Ean+isTTMoUeDb0Th0 vg+9JNjrzdGOJtPEdzDpAQShChjjZpf1PKWj3QP8vsHH5FTwOYINrUQwM kQl7V3uhFyQlhP+Pt38P6YZIgol5MpF8NkgOH7zniy3P0r/Xar+BNYBB6 Lnr3CdpxJSKLApHG8M/MOWsUR9jeXLoxjE4N2sooP3RCQc0Ge0GGD5zHi g==; X-CSE-ConnectionGUID: 6YVYmZvuSg2Z9Z95GqKcrA== X-CSE-MsgGUID: xldAz7kiTb+E+/Pug4hOJg== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629787" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:15 +0800 IronPort-SDR: J06JVZNiQmtfl+MtlNWlqNrKxbD/juee6PHRaL40BhCOwBg0TFlRnN00HXXHPl6yCBptXdwurz 1eGT70MRE8rA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:29 -0800 IronPort-SDR: MMwxy3aCgpBp7rU2yLVsHP/fYEvJiI+UHpkK+XTAZqqUmdyk8NY/cE8GN+sCaPOBdMA0mA4SQF 5vzo3uKBMjeg== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:14 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:00 -0800 Subject: [PATCH 02/13] btrfs: re-introduce struct btrfs_io_geometry Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-2-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=11384; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=URbmpvR20VX4btmngKh2nyV03iXD9B+5IvYzGplfqg8=; b=bnwWZ1qmwgXoV9Z49QY0Hh1JKoUMiZJaZU94Ab0xKtNiy+wUa8Wz+BjDxLaRWzoaG7zc7bZul D67dSzPx+7SDUqe6P6KKUrGsWwHJZLdFhQwu4zHpi7HgUllqZYtPOJc X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Re-introduce struct btrfs_io_geometry, holding the necessary bits and pieces needed in btrfs_map_block() to decide the I/O geometry of a specific block mapping. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 156 +++++++++++++++++++++++++++++------------------------ 1 file changed, 86 insertions(+), 70 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1011178a244c..d0e529b3fd39 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -41,6 +41,16 @@ BTRFS_BLOCK_GROUP_RAID10 | \ BTRFS_BLOCK_GROUP_RAID56_MASK) +struct btrfs_io_geometry { + u32 stripe_index; + u32 stripe_nr; + int mirror_num; + int num_stripes; + u64 stripe_offset; + u64 raid56_full_stripe_start; + int max_errors; +}; + const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { [BTRFS_RAID_RAID10] = { .sub_stripes = 2, @@ -6393,28 +6403,22 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, struct btrfs_io_stripe *smap, int *mirror_num_ret) { struct btrfs_chunk_map *map; + struct btrfs_io_geometry io_geom = { }; u64 map_offset; - u64 stripe_offset; - u32 stripe_nr; - u32 stripe_index; int data_stripes; int i; int ret = 0; - int mirror_num = (mirror_num_ret ? *mirror_num_ret : 0); - int num_stripes; int num_copies; - int max_errors = 0; struct btrfs_io_context *bioc = NULL; struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; int dev_replace_is_ongoing = 0; u16 num_alloc_stripes; - u64 raid56_full_stripe_start = (u64)-1; u64 max_len; ASSERT(bioc_ret); num_copies = btrfs_num_copies(fs_info, logical, fs_info->sectorsize); - if (mirror_num > num_copies) + if (io_geom.mirror_num > num_copies) return -EINVAL; map = btrfs_get_chunk_map(fs_info, logical, *length); @@ -6424,8 +6428,10 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, data_stripes = nr_data_stripes(map); map_offset = logical - map->start; - max_len = btrfs_max_io_len(map, op, map_offset, &stripe_nr, - &stripe_offset, &raid56_full_stripe_start); + io_geom.raid56_full_stripe_start = (u64)-1; + max_len = btrfs_max_io_len(map, op, map_offset, &io_geom.stripe_nr, + &io_geom.stripe_offset, + &io_geom.raid56_full_stripe_start); *length = min_t(u64, map->chunk_len - map_offset, max_len); down_read(&dev_replace->rwsem); @@ -6437,53 +6443,54 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, if (!dev_replace_is_ongoing) up_read(&dev_replace->rwsem); - num_stripes = 1; - stripe_index = 0; + io_geom.num_stripes = 1; + io_geom.stripe_index = 0; + io_geom.mirror_num = (mirror_num_ret ? *mirror_num_ret : 0); if (map->type & BTRFS_BLOCK_GROUP_RAID0) { - stripe_index = stripe_nr % map->num_stripes; - stripe_nr /= map->num_stripes; + io_geom.stripe_index = io_geom.stripe_nr % map->num_stripes; + io_geom.stripe_nr /= map->num_stripes; if (op == BTRFS_MAP_READ) - mirror_num = 1; + io_geom.mirror_num = 1; } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) { if (op != BTRFS_MAP_READ) { - num_stripes = map->num_stripes; - } else if (mirror_num) { - stripe_index = mirror_num - 1; + io_geom.num_stripes = map->num_stripes; + } else if (io_geom.mirror_num) { + io_geom.stripe_index = io_geom.mirror_num - 1; } else { - stripe_index = find_live_mirror(fs_info, map, 0, + io_geom.stripe_index = find_live_mirror(fs_info, map, 0, dev_replace_is_ongoing); - mirror_num = stripe_index + 1; + io_geom.mirror_num = io_geom.stripe_index + 1; } } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { if (op != BTRFS_MAP_READ) { - num_stripes = map->num_stripes; - } else if (mirror_num) { - stripe_index = mirror_num - 1; + io_geom.num_stripes = map->num_stripes; + } else if (io_geom.mirror_num) { + io_geom.stripe_index = io_geom.mirror_num - 1; } else { - mirror_num = 1; + io_geom.mirror_num = 1; } } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { u32 factor = map->num_stripes / map->sub_stripes; - stripe_index = (stripe_nr % factor) * map->sub_stripes; - stripe_nr /= factor; + io_geom.stripe_index = (io_geom.stripe_nr % factor) * map->sub_stripes; + io_geom.stripe_nr /= factor; if (op != BTRFS_MAP_READ) - num_stripes = map->sub_stripes; - else if (mirror_num) - stripe_index += mirror_num - 1; + io_geom.num_stripes = map->sub_stripes; + else if (io_geom.mirror_num) + io_geom.stripe_index += io_geom.mirror_num - 1; else { - int old_stripe_index = stripe_index; - stripe_index = find_live_mirror(fs_info, map, - stripe_index, + int old_stripe_index = io_geom.stripe_index; + io_geom.stripe_index = find_live_mirror(fs_info, map, + io_geom.stripe_index, dev_replace_is_ongoing); - mirror_num = stripe_index - old_stripe_index + 1; + io_geom.mirror_num = io_geom.stripe_index - old_stripe_index + 1; } } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { - if (op != BTRFS_MAP_READ || mirror_num > 1) { + if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) { /* * Needs full stripe mapping. * @@ -6495,29 +6502,33 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * but that can be expensive. Here we just divide * @stripe_nr with @data_stripes. */ - stripe_nr /= data_stripes; + io_geom.stripe_nr /= data_stripes; /* RAID[56] write or recovery. Return all stripes */ - num_stripes = map->num_stripes; - max_errors = btrfs_chunk_max_errors(map); + io_geom.num_stripes = map->num_stripes; + io_geom.max_errors = btrfs_chunk_max_errors(map); /* Return the length to the full stripe end */ *length = min(logical + *length, - raid56_full_stripe_start + map->start + - btrfs_stripe_nr_to_offset(data_stripes)) - + io_geom.raid56_full_stripe_start + + map->start + + btrfs_stripe_nr_to_offset( + data_stripes)) - logical; - stripe_index = 0; - stripe_offset = 0; + io_geom.stripe_index = 0; + io_geom.stripe_offset = 0; } else { - ASSERT(mirror_num <= 1); + ASSERT(io_geom.mirror_num <= 1); /* Just grab the data stripe directly. */ - stripe_index = stripe_nr % data_stripes; - stripe_nr /= data_stripes; + io_geom.stripe_index = io_geom.stripe_nr % data_stripes; + io_geom.stripe_nr /= data_stripes; /* We distribute the parity blocks across stripes */ - stripe_index = (stripe_nr + stripe_index) % map->num_stripes; - if (op == BTRFS_MAP_READ && mirror_num < 1) - mirror_num = 1; + io_geom.stripe_index = + (io_geom.stripe_nr + io_geom.stripe_index) % + map->num_stripes; + if (op == BTRFS_MAP_READ && io_geom.mirror_num < 1) + io_geom.mirror_num = 1; } } else { /* @@ -6525,19 +6536,19 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * device we have to walk to find the data, and stripe_index is * the number of our device in the stripe array */ - stripe_index = stripe_nr % map->num_stripes; - stripe_nr /= map->num_stripes; - mirror_num = stripe_index + 1; + io_geom.stripe_index = io_geom.stripe_nr % map->num_stripes; + io_geom.stripe_nr /= map->num_stripes; + io_geom.mirror_num = io_geom.stripe_index + 1; } - if (stripe_index >= map->num_stripes) { + if (io_geom.stripe_index >= map->num_stripes) { btrfs_crit(fs_info, "stripe index math went horribly wrong, got stripe_index=%u, num_stripes=%u", - stripe_index, map->num_stripes); + io_geom.stripe_index, map->num_stripes); ret = -EINVAL; goto out; } - num_alloc_stripes = num_stripes; + num_alloc_stripes = io_geom.num_stripes; if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL && op != BTRFS_MAP_READ) /* @@ -6555,11 +6566,12 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * I/O context structure. */ if (is_single_device_io(fs_info, smap, map, num_alloc_stripes, op, - mirror_num)) { + io_geom.mirror_num)) { ret = set_io_stripe(fs_info, op, logical, length, smap, map, - stripe_index, stripe_offset, stripe_nr); + io_geom.stripe_index, io_geom.stripe_offset, + io_geom.stripe_nr); if (mirror_num_ret) - *mirror_num_ret = mirror_num; + *mirror_num_ret = io_geom.mirror_num; *bioc_ret = NULL; goto out; } @@ -6579,7 +6591,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * It's still mostly the same as other profiles, just with extra rotation. */ if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK && - (op != BTRFS_MAP_READ || mirror_num > 1)) { + (op != BTRFS_MAP_READ || io_geom.mirror_num > 1)) { /* * For RAID56 @stripe_nr is already the number of full stripes * before us, which is also the rotation value (needs to modulo @@ -6589,12 +6601,13 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * modulo, to reduce one modulo call. */ bioc->full_stripe_logical = map->start + - btrfs_stripe_nr_to_offset(stripe_nr * data_stripes); - for (int i = 0; i < num_stripes; i++) { + btrfs_stripe_nr_to_offset(io_geom.stripe_nr * data_stripes); + for (int i = 0; i < io_geom.num_stripes; i++) { ret = set_io_stripe(fs_info, op, logical, length, &bioc->stripes[i], map, - (i + stripe_nr) % num_stripes, - stripe_offset, stripe_nr); + (i + io_geom.stripe_nr) % io_geom.num_stripes, + io_geom.stripe_offset, + io_geom.stripe_nr); if (ret < 0) break; } @@ -6603,13 +6616,15 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * For all other non-RAID56 profiles, just copy the target * stripe into the bioc. */ - for (i = 0; i < num_stripes; i++) { + for (i = 0; i < io_geom.num_stripes; i++) { ret = set_io_stripe(fs_info, op, logical, length, - &bioc->stripes[i], map, stripe_index, - stripe_offset, stripe_nr); + &bioc->stripes[i], map, + io_geom.stripe_index, + io_geom.stripe_offset, + io_geom.stripe_nr); if (ret < 0) break; - stripe_index++; + io_geom.stripe_index++; } } @@ -6620,18 +6635,19 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, } if (op != BTRFS_MAP_READ) - max_errors = btrfs_chunk_max_errors(map); + io_geom.max_errors = btrfs_chunk_max_errors(map); if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL && op != BTRFS_MAP_READ) { handle_ops_on_dev_replace(op, bioc, dev_replace, logical, - &num_stripes, &max_errors); + &io_geom.num_stripes, + &io_geom.max_errors); } *bioc_ret = bioc; - bioc->num_stripes = num_stripes; - bioc->max_errors = max_errors; - bioc->mirror_num = mirror_num; + bioc->num_stripes = io_geom.num_stripes; + bioc->max_errors = io_geom.max_errors; + bioc->mirror_num = io_geom.mirror_num; out: if (dev_replace_is_ongoing) { From patchwork Tue Dec 12 12:38:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489211 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="X4RI3YDr" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F02BC124; Tue, 12 Dec 2023 04:38:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384697; x=1733920697; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=WzAokk5ODdjvW4/f5P8YZlwWo7Vx235+0DogRPEc7kw=; b=X4RI3YDrHQyqxVDlOnZmj97gXJ4qkSVChz/lUN51Ajht0aTsKyOjRT9E W+2OFcANC19E9n00VQo1/0VD/xb+R1sOwvF+w9uzbgHQNVFJdrV0H3QEa Fm+OAzpphoIHCUle1xyyLXdq2im5DcaDWVizRzyK7tPvingxhPVEbPv9Q xmZk3UOtEahjYTLmG9ao9LsS8vZ4ysfOWUj5N+VrrGxHRCsp8bLBGWQTP 9SSXQzw2UV/MGKKFxQ4MAg5Yf36WKzBl0IS3FfIQKgrwJW1S5RVzUFtIb doJWpHMmWUT5nC/wrfWrDYugb+K1KyVdpbxDfgEatH7QpR3LootVYOVLE w==; X-CSE-ConnectionGUID: 89DOXQceR2iiczdLWR+a7g== X-CSE-MsgGUID: olgMV74wSRWuyRbOb6+cjQ== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629788" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:17 +0800 IronPort-SDR: AmG5PtdcC1XRMmn4LP41gXKp7NBB8qUfOVV/XEhRLkyXSeXF+5AxK3QjfV/oW6hcy11Qazc4vO I8v/Xtbndh0A== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:30 -0800 IronPort-SDR: WH8nRobKMIPo/vxAN7+p3ZQVzg9jIb3Q7237p4t2hGYkt9qzsrF6aAtsa7Ml56sCqf5qqV/HWp +bjsBGj+MPag== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:16 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:01 -0800 Subject: [PATCH 03/13] btrfs: factor out block-mapping for RAID0 Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-3-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=1575; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=WzAokk5ODdjvW4/f5P8YZlwWo7Vx235+0DogRPEc7kw=; b=/uz+vboQJqlbSQp3k+ds0ZfHHXV5k4xJ4As2oVMMjU3ZQ9l5n7fgGn5bPoK5+6++oONxXvg5o 5C58tm0DFHxDubj2hCz6XrGnqkUIT5seSpC14Q2Y6/u3lvoeq7ga/uv X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Now that we have a container for the I/O geometry that has all the needed information for the block mappings of RAID0, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index d0e529b3fd39..a5d85a77da25 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6362,6 +6362,16 @@ static bool is_single_device_io(struct btrfs_fs_info *fs_info, return true; } +static void map_blocks_for_raid0(struct btrfs_chunk_map *map, + enum btrfs_map_op op, + struct btrfs_io_geometry *io_geom) +{ + io_geom->stripe_index = io_geom->stripe_nr % map->num_stripes; + io_geom->stripe_nr /= map->num_stripes; + if (op == BTRFS_MAP_READ) + io_geom->mirror_num = 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6447,10 +6457,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, io_geom.stripe_index = 0; io_geom.mirror_num = (mirror_num_ret ? *mirror_num_ret : 0); if (map->type & BTRFS_BLOCK_GROUP_RAID0) { - io_geom.stripe_index = io_geom.stripe_nr % map->num_stripes; - io_geom.stripe_nr /= map->num_stripes; - if (op == BTRFS_MAP_READ) - io_geom.mirror_num = 1; + map_blocks_for_raid0(map, op, &io_geom); } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) { if (op != BTRFS_MAP_READ) { io_geom.num_stripes = map->num_stripes; From patchwork Tue Dec 12 12:38:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489214 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="llIIDe5i" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 045BBF7; Tue, 12 Dec 2023 04:38:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384701; x=1733920701; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=ebYL8Lh5wqUhbEP90Uoh61na4d5uGMM/U9hqcqH7K+Y=; b=llIIDe5iYhVc6CGXipW7lrSD0wsp+4eBaAF6cvBqv9J/T6cQivUXsl01 ZQjrf0/LQWT67gNoJ/WTNNy0tvVcfnTGF27hXj4WORI07uaqhH9NyEbBy ad7ChXXNuSN/x3dg1DOEFMWiEQD+IoawZmP94hHsG9fTs/6rtAQQtYe1y NFtoybuNP3LQjJMfPigcYgZo0cxtekKJK0AhwMZ08AMNWh6X6wrUIr9A1 nRnmUrcl3tvg8x/0oLe/xAecljc9FGeE0LEJwAFOr+BTuEc7xM+Y3zbfn 7akC9kFnMmemiR+Zt1JXwRN3gnZDALn0eURbFVZHNy3EBLRcM9KAOtLLg A==; X-CSE-ConnectionGUID: V4Y9g6jFSFOPS/tGQSNYmQ== X-CSE-MsgGUID: A6l7RrrfQ5ajfXSA0bNwew== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629789" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:18 +0800 IronPort-SDR: 5cgj/ywiWV1Xwx4jbZTECYaN6dHkn5CkPYWosv1NDLNiEfvi08dgPPeaQKoSUUtkjJChRfUPKD wAuVHpYSM1LQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:31 -0800 IronPort-SDR: caHHQ/Iaccr62S3pNOUgNTh8l3uYglaMj0x4HVxvGpZtXY+6837I9w98bidSfHIQscu4pe5hf5 yWya5NCITmMQ== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:17 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:02 -0800 Subject: [PATCH 04/13] btrfs: factor out RAID1 block mapping Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-4-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=2028; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=ebYL8Lh5wqUhbEP90Uoh61na4d5uGMM/U9hqcqH7K+Y=; b=LM6TyK9cR63cC+HyWnjRomzXJyTGYo2mmltNAh+lgwQBnk7ytBOsp2hupb0maiwPSgQ6vPgjs 5QuN8YthKA/CNWcncr9R7cqJwsG5f2JH0K3BL1ve3bjqYFBPFWKNGrw X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Now that we have a container for the I/O geometry that has all the needed information for the block mappings of RAID1, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index a5d85a77da25..f6f1e783b3c1 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6372,6 +6372,25 @@ static void map_blocks_for_raid0(struct btrfs_chunk_map *map, io_geom->mirror_num = 1; } +static void map_blocks_for_raid1(struct btrfs_fs_info *fs_info, + struct btrfs_chunk_map *map, + enum btrfs_map_op op, + struct btrfs_io_geometry *io_geom, int replace) +{ + if (op != BTRFS_MAP_READ) { + io_geom->num_stripes = map->num_stripes; + return; + } + + if (io_geom->mirror_num) { + io_geom->stripe_index = io_geom->mirror_num - 1; + return; + } + + io_geom->stripe_index = find_live_mirror(fs_info, map, 0, replace); + io_geom->mirror_num = io_geom->stripe_index + 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6459,16 +6478,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, if (map->type & BTRFS_BLOCK_GROUP_RAID0) { map_blocks_for_raid0(map, op, &io_geom); } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) { - if (op != BTRFS_MAP_READ) { - io_geom.num_stripes = map->num_stripes; - } else if (io_geom.mirror_num) { - io_geom.stripe_index = io_geom.mirror_num - 1; - } else { - io_geom.stripe_index = find_live_mirror(fs_info, map, 0, - dev_replace_is_ongoing); - io_geom.mirror_num = io_geom.stripe_index + 1; - } - + map_blocks_for_raid1(fs_info, map, op, &io_geom, + dev_replace_is_ongoing); } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { if (op != BTRFS_MAP_READ) { io_geom.num_stripes = map->num_stripes; From patchwork Tue Dec 12 12:38:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489213 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="qpnHGXKd" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D8CFF; Tue, 12 Dec 2023 04:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384702; x=1733920702; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=8tSsg77Jh959a0uxcl1WAe3mo/6FrLyJjMAFBfZRrMM=; b=qpnHGXKdLzhvCpccNO0ZT0TkjStE99sWyiGGBm6CWYCnMGzZRKQ2/QYu IoawUGvGK7LbBOVDGF2a7NOYS5uwb5XUN4KMAC79T48tKdwsfnt8h7go8 PEoN8fBAc74LLFDDpj39MnttmiIBWtzUkGgrFEZOgUlFvhwd2IsrQHuRY UL5KAxv1MsBjORhHNThGARcXDXH523ZR2Zk39lTVquyTGoXgdi5RyWmdp m8KkNw6uFlKW6ghvQUzgUP9GkG2YR5ruSRopKKJawxIOmGDqxhF4HsesU e47fOa9CKb+EiLtVYAFxSiYMYzdCHVwxAfNnqUB1QB7WEl+rFRaTkcYeo Q==; X-CSE-ConnectionGUID: +fJ9JpiQRUO/saY3erqFjg== X-CSE-MsgGUID: gDJS8AhiRnOVDxZfhomuGw== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629795" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:20 +0800 IronPort-SDR: O8vjKsrK2E1rtCUsHz872Qe5D5FukZVD00YqSvImHaVmCsRoeZLPzr52vvMFjOKfkSqe4o2XEb tRKhwaLCzaZg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:33 -0800 IronPort-SDR: QjNMLaPjJ6RXcxrvEibP4i0X1/swpg9MR3SOFacbK7LRNRnAdj0Skwno5EeuwTF0redLPIJUfx Quku+SPSvTnw== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:18 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:03 -0800 Subject: [PATCH 05/13] btrfs: factor out block mapping for DUP profiles Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-5-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=1714; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=8tSsg77Jh959a0uxcl1WAe3mo/6FrLyJjMAFBfZRrMM=; b=ARMrZTeHJQxstKrYpJ23CIAMX+dVKyPyZHzUPoWeD+Q73R5MetKwQKEkmJgxRP9IFb+oMVvUx DXVswOoPs5eD1Fx44sB2Wm00gdXokfMydHgYVc5Xna5c3fr8oWZIU+e X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Now that we have a container for the I/O geometry that has all the needed information for the block mappings of DUP, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index f6f1e783b3c1..b0a5c53fba51 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6391,6 +6391,23 @@ static void map_blocks_for_raid1(struct btrfs_fs_info *fs_info, io_geom->mirror_num = io_geom->stripe_index + 1; } +static void map_blocks_for_dup(struct btrfs_chunk_map *map, + enum btrfs_map_op op, + struct btrfs_io_geometry *io_geom) +{ + if (op != BTRFS_MAP_READ) { + io_geom->num_stripes = map->num_stripes; + return; + } + + if (io_geom->mirror_num) { + io_geom->stripe_index = io_geom->mirror_num - 1; + return; + } + + io_geom->mirror_num = 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6481,14 +6498,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_blocks_for_raid1(fs_info, map, op, &io_geom, dev_replace_is_ongoing); } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { - if (op != BTRFS_MAP_READ) { - io_geom.num_stripes = map->num_stripes; - } else if (io_geom.mirror_num) { - io_geom.stripe_index = io_geom.mirror_num - 1; - } else { - io_geom.mirror_num = 1; - } - + map_blocks_for_dup(map, op, &io_geom); } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { u32 factor = map->num_stripes / map->sub_stripes; From patchwork Tue Dec 12 12:38:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489215 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="k/PoXMnJ" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4A92FD; Tue, 12 Dec 2023 04:38:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384703; x=1733920703; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=lXJp7Vki0//VmgCnvQn6BIvzp7MNt5URtbIDUaZNqA8=; b=k/PoXMnJEPt14NaJLdJka9Q5/mrcVvnCfg8Uky2u5yIfa0L6C3e3vRTW kHL49jDPt2EvPohCYwLW+vfnyKMuTD5DiGdhWNRRInLMuxAsKdIX0+pAy 3yAw7mTI0dA1ccOb2GuHiJnV3irMem0pBJkbOs08sTZR2YoyELzpqGUcw aw3JWf7v0QzVd77w4VBGeRIVe730Vy1EyLeoqvolcdNEzCp2UTP6eRixZ eBMsETqHtUS1JQfDBcfFr4NhY+hTt9lWnDj5Zt+XyGX2mU2J+xWV3y9Nv 4ZQYWyeBWOwbQ+3HVDJlAL2t1kiSZJyYaUdYNKIBuT8ewmCmcJEpzQwwR g==; X-CSE-ConnectionGUID: daMNu9RUSHO9LoTO8c8C8A== X-CSE-MsgGUID: 6DIaMXuuT7Smg3fvFVgwMQ== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629798" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:21 +0800 IronPort-SDR: wCyq9dJo0BJXILY179PkoUmorCzlwyiDBdNw/9YAT/U7sWKLr7PEg0MwxG1S+fhlOae0jeROwE CDZ5xJngEXHQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:34 -0800 IronPort-SDR: /h257Fekxf+NXY9HO8WkSWfXGX6nO92JgHLxMDvw5r8Xc1jottiO/IJr73IAlR2TiJmZSSMCqc +kPftaDVG9Ew== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:20 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:04 -0800 Subject: [PATCH 06/13] btrfs: factor out block mapping for RAID10 Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-6-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=2605; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=lXJp7Vki0//VmgCnvQn6BIvzp7MNt5URtbIDUaZNqA8=; b=d8m+QckEF6cYQbcvWsipkYLVoLwlaSreKemUA+fZRMjVs7GRVPDazRslJqnJFWPgSoYlrbnUM 87c5xvQ4hTFDUpyasUNrv+D3J/gffiOBSoS2DC+MlOpoCfsAGWstxTv X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Now that we have a container for the I/O geometry that has all the needed information for the block mappings of RAID10, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b0a5c53fba51..9090bfc4fe38 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6408,6 +6408,35 @@ static void map_blocks_for_dup(struct btrfs_chunk_map *map, io_geom->mirror_num = 1; } +static void map_blocks_for_raid10(struct btrfs_fs_info *fs_info, + struct btrfs_chunk_map *map, + enum btrfs_map_op op, + struct btrfs_io_geometry *io_geom, + int replace) +{ + u32 factor = map->num_stripes / map->sub_stripes; + int old_stripe_index; + + io_geom->stripe_index = + (io_geom->stripe_nr % factor) * map->sub_stripes; + io_geom->stripe_nr /= factor; + + if (op != BTRFS_MAP_READ) { + io_geom->num_stripes = map->sub_stripes; + return; + } + + if (io_geom->mirror_num) { + io_geom->stripe_index += io_geom->mirror_num - 1; + return; + } + + old_stripe_index = io_geom->stripe_index; + io_geom->stripe_index = + find_live_mirror(fs_info, map, io_geom->stripe_index, replace); + io_geom->mirror_num = io_geom->stripe_index - old_stripe_index + 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6500,23 +6529,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { map_blocks_for_dup(map, op, &io_geom); } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { - u32 factor = map->num_stripes / map->sub_stripes; - - io_geom.stripe_index = (io_geom.stripe_nr % factor) * map->sub_stripes; - io_geom.stripe_nr /= factor; - - if (op != BTRFS_MAP_READ) - io_geom.num_stripes = map->sub_stripes; - else if (io_geom.mirror_num) - io_geom.stripe_index += io_geom.mirror_num - 1; - else { - int old_stripe_index = io_geom.stripe_index; - io_geom.stripe_index = find_live_mirror(fs_info, map, - io_geom.stripe_index, - dev_replace_is_ongoing); - io_geom.mirror_num = io_geom.stripe_index - old_stripe_index + 1; - } - + map_blocks_for_raid10(fs_info, map, op, &io_geom, + dev_replace_is_ongoing); } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) { /* From patchwork Tue Dec 12 12:38:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489216 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="K/Yb0BNO" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F18D18C; Tue, 12 Dec 2023 04:38:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384710; x=1733920710; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=7IitFGc7/IJjyGbmbRVykpWQDNZ+Fz3j+hjcbSopc1E=; b=K/Yb0BNOsoES05ZFwy5REND1r1cIX9RQdVEIG9LTijrgsXON2l04Z1lQ TfNtO5+L7h5KB6bd7H65ckdAO5mzwuoAzZaFPpIkhLwEwyxTwPaok1Ork Urmh9V86MlwWFkK4kxGG5jusJWn4WYBx1s3d0cOnkmjFhVjQ43QzVxPTn 1AZJ/rnkW0hP2K85p3lrjl9W+GDdomTJQIBweWLZFuTrWAe9dnn1SuZMT 2PFcxQi9RDICzAI2D+pZbY0sXZUbFVmdJK9UIB+E3bFF6kbPEVv8zkCE/ qKzs6MZvuhpv8y1I4lTb7Y9hX9pP4VJt9xDSj9SSE/mwt/lAdKhrfK/LM Q==; X-CSE-ConnectionGUID: pD/fV8xhRcexNxFDJ//omg== X-CSE-MsgGUID: kRCA0+rwTeq+zgKt6hj8XA== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629799" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:22 +0800 IronPort-SDR: R4NX11529yF01cq9XPPIhIyS2B7QsnjTifd/BKHds/GrkRATpWcmFwY/hURfE8oYNZiO6jb++j kD/zgcJI1pdg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:36 -0800 IronPort-SDR: 8J6ZDf1DDploJw+gY5lkK5JekK+E157uSfQee0KdypWrWGmB74LaZBDHO0y6h4YPSaEP7JcZ5L 4oUfsuBCHBZg== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:21 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:05 -0800 Subject: [PATCH 07/13] btrfs: reduce scope of data_stripes in btrfs_map_block Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-7-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=1989; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=7IitFGc7/IJjyGbmbRVykpWQDNZ+Fz3j+hjcbSopc1E=; b=m4KZIBJGlht6nE4zqHrrx7BstIG8G4cLN/crwdkYixYRslsvpO2Vc38LmvGL3ofu+E3yGlXJQ 06Jf6iwdjM6C2PklkZji0KGEd7Oih8sPYImBrGyVe0epBCfvmyAOGPr X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Reduce the scope of 'data_stripes' in btrfs_map_block(). While the change allone doesn't make too much sense, it helps us factoring out a helper function for the block mapping of RAID56 I/O. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9090bfc4fe38..bc0988d8bd56 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6480,7 +6480,6 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, struct btrfs_chunk_map *map; struct btrfs_io_geometry io_geom = { }; u64 map_offset; - int data_stripes; int i; int ret = 0; int num_copies; @@ -6500,8 +6499,6 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, if (IS_ERR(map)) return PTR_ERR(map); - data_stripes = nr_data_stripes(map); - map_offset = logical - map->start; io_geom.raid56_full_stripe_start = (u64)-1; max_len = btrfs_max_io_len(map, op, map_offset, &io_geom.stripe_nr, @@ -6532,6 +6529,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_blocks_for_raid10(fs_info, map, op, &io_geom, dev_replace_is_ongoing); } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { + int data_stripes = nr_data_stripes(map); + if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) { /* * Needs full stripe mapping. @@ -6643,7 +6642,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * modulo, to reduce one modulo call. */ bioc->full_stripe_logical = map->start + - btrfs_stripe_nr_to_offset(io_geom.stripe_nr * data_stripes); + btrfs_stripe_nr_to_offset(io_geom.stripe_nr * + nr_data_stripes(map)); for (int i = 0; i < io_geom.num_stripes; i++) { ret = set_io_stripe(fs_info, op, logical, length, &bioc->stripes[i], map, From patchwork Tue Dec 12 12:38:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489217 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="E0mtm3OD" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DD2518A; Tue, 12 Dec 2023 04:38:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384710; x=1733920710; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=13sSKOdPGCtJkfDz7HQPJxztkCHKHtWtxlS4sYRz4H4=; b=E0mtm3ODGYYYMV8YUegryncaZoWzS4o6t4v9LxRadScZkpdqSjm9x6cg vA1Ek6wO6BCYWJaMRdj3zw2zUeOAo5yUNoSM9ViHXZxrZp0TV0MgG6SrU S3vH4NUVqs0MGgnjC72v3suCpa333uqDt10FpYD1eaSODZl69OliJ7Ca3 b6wyN1a3zkDfb8jXsPpdWZ1U4OKoL/da69PV8E/4GOlpcSK7DlezAsORT 7/RCgbAAShhVdYLT6xVKCMeZt0jfh+bUEM3ry7xUrQFNoPrpzL1Tz6S9Z sBVKZB24NFoEH2y94qaxTXl+t2Ehbn3LIStRgE2SNSxU+xmqT0HLZVLgj g==; X-CSE-ConnectionGUID: va5vw7GKTH2FBlFviEvl2g== X-CSE-MsgGUID: 7MRTnW96QaS6F8qfMtdagA== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629800" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:24 +0800 IronPort-SDR: j0J/dG2cgKpx4DcpuqCRoR9U3+qv9Iyxt69e4py1qaKKfCOEgTOOhEErPFzooqtcZVCEgU/gs9 xt3mSFH/xcyQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:37 -0800 IronPort-SDR: 5scbsRwiXUxhNm5LGPAxCPN18+mYWq7ksdwM55JYQOAmA9fXPdGQOgKwRqgDip5/vxloYNCMhF ETdj34Q+m/kw== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:23 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:06 -0800 Subject: [PATCH 08/13] btrfs: factor out block mapping for RAID5/6 Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-8-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=4237; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=13sSKOdPGCtJkfDz7HQPJxztkCHKHtWtxlS4sYRz4H4=; b=TDOS5Lt38tJFregGC9nNL23Jv/PCsz8I1IJK3qjSuXJmjp4sHbxkXD8Qf6U/zluSNhuTSShXE g170bvYfm06B9G05ZhEWK0oilO0BXLCZROYDmNQO0fnNI4awFm6dmCK X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Now that we have a container for the I/O geometry that has all the needed information for the block mappings of RAID5 and RAID6, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 91 +++++++++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index bc0988d8bd56..fd213bb7d619 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6437,6 +6437,54 @@ static void map_blocks_for_raid10(struct btrfs_fs_info *fs_info, io_geom->mirror_num = io_geom->stripe_index - old_stripe_index + 1; } +static void map_blocks_for_raid56(struct btrfs_chunk_map *map, + enum btrfs_map_op op, + struct btrfs_io_geometry *io_geom, + u64 logical, u64 *length) +{ + int data_stripes = nr_data_stripes(map); + + if (op != BTRFS_MAP_READ || io_geom->mirror_num > 1) { + /* + * Needs full stripe mapping. + * + * Push stripe_nr back to the start of the full stripe + * For those cases needing a full stripe, @stripe_nr + * is the full stripe number. + * + * Originally we go raid56_full_stripe_start / full_stripe_len, + * but that can be expensive. Here we just divide + * @stripe_nr with @data_stripes. + */ + io_geom->stripe_nr /= data_stripes; + + /* RAID[56] write or recovery. Return all stripes */ + io_geom->num_stripes = map->num_stripes; + io_geom->max_errors = btrfs_chunk_max_errors(map); + + /* Return the length to the full stripe end */ + *length = min(logical + *length, + io_geom->raid56_full_stripe_start + map->start + + btrfs_stripe_nr_to_offset(data_stripes)) - + logical; + io_geom->stripe_index = 0; + io_geom->stripe_offset = 0; + return; + } + + ASSERT(io_geom->mirror_num <= 1); + /* Just grab the data stripe directly. */ + io_geom->stripe_index = io_geom->stripe_nr % data_stripes; + io_geom->stripe_nr /= data_stripes; + + /* We distribute the parity blocks across stripes */ + io_geom->stripe_index = + (io_geom->stripe_nr + io_geom->stripe_index) % map->num_stripes; + + if (op == BTRFS_MAP_READ && io_geom->mirror_num < 1) + io_geom->mirror_num = 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6529,48 +6577,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_blocks_for_raid10(fs_info, map, op, &io_geom, dev_replace_is_ongoing); } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { - int data_stripes = nr_data_stripes(map); - - if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) { - /* - * Needs full stripe mapping. - * - * Push stripe_nr back to the start of the full stripe - * For those cases needing a full stripe, @stripe_nr - * is the full stripe number. - * - * Originally we go raid56_full_stripe_start / full_stripe_len, - * but that can be expensive. Here we just divide - * @stripe_nr with @data_stripes. - */ - io_geom.stripe_nr /= data_stripes; - - /* RAID[56] write or recovery. Return all stripes */ - io_geom.num_stripes = map->num_stripes; - io_geom.max_errors = btrfs_chunk_max_errors(map); - - /* Return the length to the full stripe end */ - *length = min(logical + *length, - io_geom.raid56_full_stripe_start + - map->start + - btrfs_stripe_nr_to_offset( - data_stripes)) - - logical; - io_geom.stripe_index = 0; - io_geom.stripe_offset = 0; - } else { - ASSERT(io_geom.mirror_num <= 1); - /* Just grab the data stripe directly. */ - io_geom.stripe_index = io_geom.stripe_nr % data_stripes; - io_geom.stripe_nr /= data_stripes; - - /* We distribute the parity blocks across stripes */ - io_geom.stripe_index = - (io_geom.stripe_nr + io_geom.stripe_index) % - map->num_stripes; - if (op == BTRFS_MAP_READ && io_geom.mirror_num < 1) - io_geom.mirror_num = 1; - } + map_blocks_for_raid56(map, op, &io_geom, logical, length); } else { /* * After this, stripe_nr is the number of stripes on this From patchwork Tue Dec 12 12:38:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489218 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="QLs0QV67" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71B9B197; Tue, 12 Dec 2023 04:38:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384711; x=1733920711; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=3JBwlPmlVxcc4Hbr5ovZi090xqLbOi7L4Oq6IXpdP+c=; b=QLs0QV679G5N/ymlyyps5HWJs45hxlJc+R6+akAIHN4bEM4Bi/PoG+DO Z+mrN3rj6u74m8L54wOP/oJhohVdWIijXtKmB1unfSUk8Rl2QmFfSgX7G jMi1u/X/EVY2Y07OSFBcSfBOKjtFcoZg0336R1GeSI3BwlH6fVHg474HG AA0XySnO6hfMu+a/xx7f9N8/c9iaV3nP6TK9phAe9fgbzOecQmVpqX2cn CoEpTzCKxHJs2efz880SoyqCgpbLuqFjxA7XO+i0H5XLu8ErfHCA619EY Ukajrbuo2NhQ7N5q4pvzXlFOYsRtZ0Ctwc+ol6BedE05bMRbhfS0SWYsw A==; X-CSE-ConnectionGUID: WeyuH8m4SLe4nDnwUH0XBA== X-CSE-MsgGUID: skh67uFoSICKLfzJJ3cuzw== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629801" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:25 +0800 IronPort-SDR: hkw1xN8eTru++8Dqoc6P4XNCkZjZrbsdui5kbs3MjMeMkB7v2jqKuvgl4/Ayv+B/ysfQw1y/S2 R+MCymewRzlQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:38 -0800 IronPort-SDR: yKSyTL4RqjgBc7SWF2fYJaRUNDzPRK+sZWGPoy8X41nvAdlplDIhTKBhy5y5ItabOFKvZyVo9t 6QI2j683Vtrw== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:24 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:07 -0800 Subject: [PATCH 09/13] btrfs: factor out block mapping for single profiles Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-9-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=1483; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=3JBwlPmlVxcc4Hbr5ovZi090xqLbOi7L4Oq6IXpdP+c=; b=r7nRTt3NiVSw2tCG7+pUuEg/CKxGw337avuRqCY47dHeFu/f1OGQZYTu51UFeCF7ybE5cxiJj SacfI6e1ut9AIn6wOV7xbl86esli7DGok75vH3UVFmSj7beg62mv5fx X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Now that we have a container for the I/O geometry that has all the needed information for the block mappings of SINGLE profiles, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index fd213bb7d619..e7bd3a25c516 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6485,6 +6485,14 @@ static void map_blocks_for_raid56(struct btrfs_chunk_map *map, io_geom->mirror_num = 1; } +static void map_blocks_for_single(struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom) +{ + io_geom->stripe_index = io_geom->stripe_nr % map->num_stripes; + io_geom->stripe_nr /= map->num_stripes; + io_geom->mirror_num = io_geom->stripe_index + 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6584,9 +6592,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * device we have to walk to find the data, and stripe_index is * the number of our device in the stripe array */ - io_geom.stripe_index = io_geom.stripe_nr % map->num_stripes; - io_geom.stripe_nr /= map->num_stripes; - io_geom.mirror_num = io_geom.stripe_index + 1; + map_blocks_for_single(map, &io_geom); } if (io_geom.stripe_index >= map->num_stripes) { btrfs_crit(fs_info, From patchwork Tue Dec 12 12:38:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489219 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="kzVTsrVV" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AB3B1AA; Tue, 12 Dec 2023 04:38:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384716; x=1733920716; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=5N+ew4xV5T7Bg5xRXq4tOKGJ+cFKuS/hdyWQo9PfRK4=; b=kzVTsrVVVOLBT6ujfGKRWLb04CHbFyjyrAhuXjr6D4VQywpuIZUJmXMu OuzAKPEbCGB32iKy/sXP3ec3hm+LwQLrEt6P3Akc7Xu3DfSVZs4pJBzAE 1UHdZ/gFdEkhcyKBmWK0K9ebz9ESr4bTpCpuI9DVW9Z2WjgwWTsOWKYaT AmV7jDtbsXJN8vuuk5ig3j/V63bjKOMKyyvIb5ylt7GoNaAekbA8xYnBl 8bIORoYdzPS76tNvBYA9JF9n1k0JPct7yK9YEnKZtDHRpD9YPsE/JS2iP iL10A+KowFJmP6fzWouBH8XvK1q9RnFfVeGTcfGR/Vd8c3ruOpGsqUuO+ Q==; X-CSE-ConnectionGUID: uVLj9uwRRq2AUSArnRqE7Q== X-CSE-MsgGUID: Kw0t9OlYQUaISAH1jqUHgA== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629803" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:26 +0800 IronPort-SDR: vKkvRlQYyDxiFmPXH4dqCmG/4MPVnkwrK5fSUR/1TpDtDXTRpOuF3C1F4muK2CCgzDTmMBzm7u A8lZs6UINL3Q== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:40 -0800 IronPort-SDR: 437019ZkLS5lVX+ILTYrOyq/+MvQ1iB1fXqdv7sacM5yvroTKC9tetv5GjVreidiR/1ZJNVY8B TeusU574/icA== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:26 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:08 -0800 Subject: [PATCH 10/13] btrfs: untagle if else maze in btrfs_map_block Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-10-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=1978; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=5N+ew4xV5T7Bg5xRXq4tOKGJ+cFKuS/hdyWQo9PfRK4=; b=2kMp398nU9E3QkdK1U8I9QCQXm14Ml+zCql16ykYKhLoWPS+u2gLznbChrXeRk1aLFZxP4NCc aCqY/yRLCYRDOrga34Pjc3zOZYRBhwtjHvtfF4KMjTjUbu2yf3xA+EY X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Signed-off-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig --- fs/btrfs/volumes.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index e7bd3a25c516..946333c8c331 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6574,26 +6574,38 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, io_geom.num_stripes = 1; io_geom.stripe_index = 0; io_geom.mirror_num = (mirror_num_ret ? *mirror_num_ret : 0); - if (map->type & BTRFS_BLOCK_GROUP_RAID0) { + + switch (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { + case BTRFS_BLOCK_GROUP_RAID0: map_blocks_for_raid0(map, op, &io_geom); - } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) { + break; + case BTRFS_BLOCK_GROUP_RAID1: + case BTRFS_BLOCK_GROUP_RAID1C3: + case BTRFS_BLOCK_GROUP_RAID1C4: map_blocks_for_raid1(fs_info, map, op, &io_geom, dev_replace_is_ongoing); - } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { + break; + case BTRFS_BLOCK_GROUP_DUP: map_blocks_for_dup(map, op, &io_geom); - } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { + break; + case BTRFS_BLOCK_GROUP_RAID10: map_blocks_for_raid10(fs_info, map, op, &io_geom, dev_replace_is_ongoing); - } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { + break; + case BTRFS_BLOCK_GROUP_RAID5: + case BTRFS_BLOCK_GROUP_RAID6: map_blocks_for_raid56(map, op, &io_geom, logical, length); - } else { + break; + default: /* * After this, stripe_nr is the number of stripes on this * device we have to walk to find the data, and stripe_index is * the number of our device in the stripe array */ map_blocks_for_single(map, &io_geom); + break; } + if (io_geom.stripe_index >= map->num_stripes) { btrfs_crit(fs_info, "stripe index math went horribly wrong, got stripe_index=%u, num_stripes=%u", From patchwork Tue Dec 12 12:38:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489220 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="HpJqw8zq" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FDDB1AE; Tue, 12 Dec 2023 04:38:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384716; x=1733920716; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=m+k8zZj7fOiwTsk10O7T+w0cafCSoG6d6aneRjaYfXI=; b=HpJqw8zqjpnIcr6+/FtBRwUNWkzc/ONLklWqRpLVv7gvMq75ktQzGZhD XrvAUHcEHZgswvBUWDKBrbHWLMgNYAspFAlD1u2QFL2zllRPkDRBSxRCM +KL4hx3y4KMvQc77sXJgu1EQeU2buOdAsk2nbRoTD8orqfTzzyHFj3pQ6 vUz/zAJg4VATn8dlx5H8BAtYzjhdWCzt4GVCOy7qiVuUcTUHet/OG21og 9VI8eGRuvss/aZSwcckhzEq0sMDxV0+KCy9Sd6ilqYs/g+AzC8ExEjhph 5JNLhyU3JNtfFLiH3f/G+NV1iSC3Mo2gOHDsV7ETtM1YXU6Fwi09zm6GP A==; X-CSE-ConnectionGUID: IOXfBpj9SzmwLK28ikQpeA== X-CSE-MsgGUID: zlpYzwIKTPeDpf7laSGAUg== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629805" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:28 +0800 IronPort-SDR: EEZx+MTXO5/EPfiEE0Oqo3Y+V7UigsN4Syyf7I8P7QAy9DwuxGXUslS55HOyNj4viY/v4jWdYb Pj/lRF0LEBig== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:41 -0800 IronPort-SDR: fsU/wqkD+KVd+7gZJQZyM/42QDym7jl2WKEY8ZV6rVeYnw/77LWRt4Ax0M273k/kZL5F6hMNBT 2pCl9aEMoPag== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:27 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:09 -0800 Subject: [PATCH 11/13] btrfs: open code set_io_stripe for RAID56 Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-11-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=1349; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=m+k8zZj7fOiwTsk10O7T+w0cafCSoG6d6aneRjaYfXI=; b=xbO8DGuIlP9LDF+dOqBn9tQlgUQ3uaT19PWrwV0MrDVeQCBR9suWMeo8QrFScmaHU0ztpPxSS q8Vd2PG2TF4Dgo7pmaOOJKF9oElSi9Vsvn0xWedCUaDzEeKjv3OAlu3 X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Open code set_io_stripe() for RAID56, as it a) uses a different method to calculate the stripe_index and b) doesn't need to go through raid-stripe-tree mapping code. Signed-off-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig Signed-off-by: Christoph Hellwig --- fs/btrfs/volumes.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 946333c8c331..7df991a81c4b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6670,13 +6670,16 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, btrfs_stripe_nr_to_offset(io_geom.stripe_nr * nr_data_stripes(map)); for (int i = 0; i < io_geom.num_stripes; i++) { - ret = set_io_stripe(fs_info, op, logical, length, - &bioc->stripes[i], map, - (i + io_geom.stripe_nr) % io_geom.num_stripes, - io_geom.stripe_offset, - io_geom.stripe_nr); - if (ret < 0) - break; + struct btrfs_io_stripe *dst = &bioc->stripes[i]; + u32 stripe_index; + + stripe_index = + (i + io_geom.stripe_nr) % io_geom.num_stripes; + dst->dev = map->stripes[stripe_index].dev; + dst->physical = + map->stripes[stripe_index].physical + + io_geom.stripe_offset + + btrfs_stripe_nr_to_offset(io_geom.stripe_nr); } } else { /* From patchwork Tue Dec 12 12:38:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489221 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="fLh+RUuT" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6E171BB; Tue, 12 Dec 2023 04:38:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384717; x=1733920717; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=gaUiVpID3qEMvXDQr81RAhFpDwEigiqNGfWmpFKH2NQ=; b=fLh+RUuTIwU4mFkFqkZumE0x/WXyXngJK3dePnsIcBP7975vRpt3kmAH hP+xNvIVQWrMSBPutnGInzDlVei6HbPZFG5ckVbW7ZF7pK5gmo8B9Dlu6 HJIz19wh15L6CXdQ6hsLle4noIsptlv+Lbka48nFJyFh7aFfqTUOne5fo PRnPbQSXyT0DPG07L0ouOYJNjI3nmippb+aETjCiLkEE12HkTWdoz1Gc9 k/joIMoYdZWKEHX/zGN2ECjcKet6vptPnwUD+3YJRLKKO/5jzgNuwDIbA rcIgw8/3WKvNxCvSfb9qNFONYkSBKyxOtoPp+CjhdfPOlueK6KiRNzGlL w==; X-CSE-ConnectionGUID: UBsURaulR7m/419IDXBUwQ== X-CSE-MsgGUID: NIU47k/7Qkq6VQW4MmuQVA== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629809" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:29 +0800 IronPort-SDR: eDu+MFhi/3vSWcj9l82fhNEPjsUwGNMwjLvhiT1Eog2yG574DLB1YcO1+ZBLvvw+YdSTInEmsH HoAyYzcHQ2Mw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:43 -0800 IronPort-SDR: Tc0wOz5i5neycLbDMuj5vFhD/Rrzx2Ol9kgrFhhV3Cd8EHKiOaYy/3ot1sPrMm+QwtfwvkdnUw Xotqf2XxxZCg== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:28 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:10 -0800 Subject: [PATCH 12/13] btrfs: pass struct btrfs_io_geometry to set_io_stripe Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-12-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=2493; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=gaUiVpID3qEMvXDQr81RAhFpDwEigiqNGfWmpFKH2NQ=; b=aa5BsgAOxVPVF21/gmUmm8xaPTnvJNyoGCbjrpDaCs5K8w1CO0L5u+UYy28uyLz5A2I8o28QU uc6ygA9K52mCWSt9N/t2M2K+htEMzabGk+Hh+5gTV1uMUXGy+rkI3mn X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Instead of passing three members of 'struct btrfs_io_geometry' into set_io_stripe() pass a pointer to the whole structure and then get the needed members out of btrfs_io_geometry. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 7df991a81c4b..c1fefe34a194 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6326,17 +6326,19 @@ static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, enum btrfs_map_op op, static int set_io_stripe(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, u64 logical, u64 *length, struct btrfs_io_stripe *dst, - struct btrfs_chunk_map *map, u32 stripe_index, - u64 stripe_offset, u64 stripe_nr) + struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom) { - dst->dev = map->stripes[stripe_index].dev; + dst->dev = map->stripes[io_geom->stripe_index].dev; if (op == BTRFS_MAP_READ && btrfs_need_stripe_tree_update(fs_info, map->type)) return btrfs_get_raid_extent_offset(fs_info, logical, length, - map->type, stripe_index, dst); + map->type, + io_geom->stripe_index, dst); - dst->physical = map->stripes[stripe_index].physical + - stripe_offset + btrfs_stripe_nr_to_offset(stripe_nr); + dst->physical = map->stripes[io_geom->stripe_index].physical + + io_geom->stripe_offset + + btrfs_stripe_nr_to_offset(io_geom->stripe_nr); return 0; } @@ -6634,8 +6636,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, if (is_single_device_io(fs_info, smap, map, num_alloc_stripes, op, io_geom.mirror_num)) { ret = set_io_stripe(fs_info, op, logical, length, smap, map, - io_geom.stripe_index, io_geom.stripe_offset, - io_geom.stripe_nr); + &io_geom); if (mirror_num_ret) *mirror_num_ret = io_geom.mirror_num; *bioc_ret = NULL; @@ -6688,10 +6689,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, */ for (i = 0; i < io_geom.num_stripes; i++) { ret = set_io_stripe(fs_info, op, logical, length, - &bioc->stripes[i], map, - io_geom.stripe_index, - io_geom.stripe_offset, - io_geom.stripe_nr); + &bioc->stripes[i], map, &io_geom); if (ret < 0) break; io_geom.stripe_index++; From patchwork Tue Dec 12 12:38:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13489222 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="f6E0fY25" Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DB83D41; Tue, 12 Dec 2023 04:38:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1702384719; x=1733920719; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=1sx5hgMgPsSIl/PcKUCTomxYnHRlrjaft92+/rRZzms=; b=f6E0fY25hsnP2yga+ylQzbCqK/UR6X2Xsb0mnfiiCBSuo97fbGxhQ87+ OxguKuR5afnkNYdo9wXe5VMqSGECNIKNvtFuSpENv37EYncU1MPgvorU5 1YWmGEaQ9/tNH4wSES01LO10XzVtvUp6s0PKq4oy+fBYx+WoArG0RUGar AMJSncZXtvxRX6oOmh6MNVA+MU9PZXn5875GZimBZp6oQB2CCud/vWZ6b Wp0dTRAx4jYevY8OIIrGj/tJFCO3iulRJgfLW+2ltcwrJHpXej+nvbU3j 6SV51u1qLu6P+HhUyGngrJ4Ctmo164++FA1Syf7oEgMCV0w37ab+av9/V A==; X-CSE-ConnectionGUID: /qRWF+KnSwCFVKLRZIxa8g== X-CSE-MsgGUID: bH/lDlXUSBm7uax+SJcjLQ== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629812" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:31 +0800 IronPort-SDR: Zcu8iEFG+rshvP99Jva+7UOWTUW2pfp3Tjhvk9MgZC+WdDKXeOGdqFS1djHiDpDwiJQSzODyVu aPiWG1WmSbWw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:44 -0800 IronPort-SDR: IF2uB1LFDxBsYDMIIthw1UW5SVEX6aIqG9iwKBTbl9ammZcgmjnlKLZ89KLkv9sYvZI4S8eqmc gmn75I9LcGRw== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:30 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:11 -0800 Subject: [PATCH 13/13] btrfs: pass btrfs_io_geometry into btrfs_max_io_len Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-13-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=3139; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=1sx5hgMgPsSIl/PcKUCTomxYnHRlrjaft92+/rRZzms=; b=98BGK4uRkR7z1XT2ETsJTcnrBi4ui/+ejviC/yhcIxHKydQ9dXB3nF8e80OyU079RRKSHXrc2 Id1MqTJEVTND+oxJjoxLazKkYbIjiFrraK+hyESN0v8aoNUkknEiHC+ X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Instead of passing three individual members of 'struct btrfs_io_geometry' into btrfs_max_io_len(), pass a pointer to btrfs_io_geometry. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c1fefe34a194..166750d279ee 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6277,16 +6277,15 @@ static void handle_ops_on_dev_replace(enum btrfs_map_op op, } static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, enum btrfs_map_op op, - u64 offset, u32 *stripe_nr, u64 *stripe_offset, - u64 *full_stripe_start) + u64 offset, struct btrfs_io_geometry *io_geom) { /* * Stripe_nr is the stripe where this block falls. stripe_offset is * the offset of this block in its stripe. */ - *stripe_offset = offset & BTRFS_STRIPE_LEN_MASK; - *stripe_nr = offset >> BTRFS_STRIPE_LEN_SHIFT; - ASSERT(*stripe_offset < U32_MAX); + io_geom->stripe_offset = offset & BTRFS_STRIPE_LEN_MASK; + io_geom->stripe_nr = offset >> BTRFS_STRIPE_LEN_SHIFT; + ASSERT(io_geom->stripe_offset < U32_MAX); if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { unsigned long full_stripe_len = @@ -6301,18 +6300,19 @@ static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, enum btrfs_map_op op, * to go rounddown(), not round_down(), as nr_data_stripes is * not ensured to be power of 2. */ - *full_stripe_start = - btrfs_stripe_nr_to_offset( - rounddown(*stripe_nr, nr_data_stripes(map))); + io_geom->raid56_full_stripe_start = btrfs_stripe_nr_to_offset( + rounddown(io_geom->stripe_nr, nr_data_stripes(map))); - ASSERT(*full_stripe_start + full_stripe_len > offset); - ASSERT(*full_stripe_start <= offset); + ASSERT(io_geom->raid56_full_stripe_start + full_stripe_len > + offset); + ASSERT(io_geom->raid56_full_stripe_start <= offset); /* * For writes to RAID56, allow to write a full stripe set, but * no straddling of stripe sets. */ if (op == BTRFS_MAP_WRITE) - return full_stripe_len - (offset - *full_stripe_start); + return full_stripe_len - + (offset - io_geom->raid56_full_stripe_start); } /* @@ -6320,7 +6320,7 @@ static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, enum btrfs_map_op op, * a single disk). */ if (map->type & BTRFS_BLOCK_GROUP_STRIPE_MASK) - return BTRFS_STRIPE_LEN - *stripe_offset; + return BTRFS_STRIPE_LEN - io_geom->stripe_offset; return U64_MAX; } @@ -6559,9 +6559,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_offset = logical - map->start; io_geom.raid56_full_stripe_start = (u64)-1; - max_len = btrfs_max_io_len(map, op, map_offset, &io_geom.stripe_nr, - &io_geom.stripe_offset, - &io_geom.raid56_full_stripe_start); + max_len = btrfs_max_io_len(map, op, map_offset, &io_geom); *length = min_t(u64, map->chunk_len - map_offset, max_len); down_read(&dev_replace->rwsem);