From patchwork Wed Dec 13 14:42:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13491113 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="TnkfyvSy" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B21E124; Wed, 13 Dec 2023 06:43:09 -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=1702478588; x=1734014588; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=fLhd1MyDh4ypvFhcwsIuuCtALl4S244wNQFfdcICrTg=; b=TnkfyvSyeA1/q3KeQOfhhAwE+wgaP92OoIltyfDnTByssZ5gjIy3h25L uvO6K+ktOEbb3awyY68/KlkNhXmsimTN5ijTgecgX+S2ncu1ycUSg3HKy Qq+jF6j5gXTVqjqG/ypIBtDpfUUKMx9tXeDJ8b2UDHKFyz9Qfq7bOKn9x Vnjq2RQNyjoevUO75flU2F5anIYVM7ujnevM4EBK6lwwOPi1rAbQZ5lkD 4vIM9lJz9JEc8h3Fe8ZO7wwOYwLM27GDXjLRhnm17ovddDwh5JW5VUMwh QwmZQUTDaEPh+tjpIiRJOY/tsc0GeDjinCiPtgAoQ8brl76QJlN+D3nbM Q==; X-CSE-ConnectionGUID: Q0HLwt5WQyaDShLA6+Wusg== X-CSE-MsgGUID: SQicrwMvT6yJ0tCm29G4Xw== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802938" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:08 +0800 IronPort-SDR: /iXhflbgZ4L5W8cafBotModBWZbxixjgFWkRGvbVaMeO1VBbGOUfqIef2Vy46+y+27iF45zu91 N4fOknyfYU+Q== 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; 13 Dec 2023 05:48:20 -0800 IronPort-SDR: 3Aep+t61H4Om/uEMNGTfvo6ZNadHR51oXjbTWa4NG5rOF/mybzIYBSH4pOsgRX86BbnwI0WktF OS6Wue9ppxxA== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:07 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:42:56 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-1-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702478586; l=1998; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=fLhd1MyDh4ypvFhcwsIuuCtALl4S244wNQFfdcICrTg=; b=saGTUjHP3jWIxzIxSkKyDz3xz/OmV+KoocqSCfxxEIOuDJWVhwoNUXikb/s7rBbglCCsPfSnl yNM+B483/ppDSAVU0oIH9twkbNc07lWH9SFM1Bw+l/AldagqxAb3d52 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. Reviewed-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- 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 Wed Dec 13 14:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13491114 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="N41Le6Kx" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84B99DD; Wed, 13 Dec 2023 06:43:10 -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=1702478590; x=1734014590; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=kCWRP4ScRPyTqiJ4MDp9iTyJnJWsDUgaRphcdVMeqP4=; b=N41Le6KxFn1+00e4QkNJYWknHyiC5pUZlCIMXZl1JleqpUahAZlo1Q3S c06LK5bQA2/g0ot0tLej1i9/cERf0NOpphmxCAJ7eZqS/jpcZ6OZzATWm c7E370XqTda7YgF/nfcR2nF3PKSXxG6g7j2wcIHgeCxmQgk9ePOufLgJw 0C1sLz7qkhzLYe8u3njnFwQKBSMxB9G3HR2C5fSiyvfhnA9Laof+hywgR 5/9l2s83g4w4NSJ8UreIib1HM5BTwQwUEWnQllmKZrPL6XjKiaM3efWX9 DZxvnnT/tpX402YvnsPfaCB9F+i4Z6W0iNWcCXGttr/NbknHmPPTJyFZs g==; X-CSE-ConnectionGUID: rxeWZ6TySI6feA77rUiLtA== X-CSE-MsgGUID: oJw4pwKgRxye/OJealKLtA== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802945" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:09 +0800 IronPort-SDR: FWVbcpiYP1oJc9svd3OUOlP063r4p9weCnI58aYtoI/Jwtl6e2tD2wzFH2vhFQrBNIqXgMSmf9 YjZkfrBVP/KA== 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; 13 Dec 2023 05:48:21 -0800 IronPort-SDR: Sdqk3/eBzRzzkp2HGk8fT6lwuLwp1XheEUB6rD5taGVGQtS9g2aGj/uFym8ECulRPJu571htm7 Mz5ocnGzDYDw== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:09 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:42:57 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-2-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=11440; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=kCWRP4ScRPyTqiJ4MDp9iTyJnJWsDUgaRphcdVMeqP4=; b=OFP/4/oB9kN+9QYp7QGL72N2aaB/7kQePUB5cM8B57xxcsjfqxEKzWkE0ZgWdL3QvXQU4ufHk wFQ2RN9N/S+Am1+6rQ+f7CW/Uplka857APsWBc8ByWin+H4jp6VfSbR 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 | 159 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 89 insertions(+), 70 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1011178a244c..ea830ff0c0e3 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -41,6 +41,17 @@ 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; + enum btrfs_map_op op; +}; + const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { [BTRFS_RAID_RAID10] = { .sub_stripes = 2, @@ -6393,28 +6404,27 @@ 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); + io_geom.mirror_num = (mirror_num_ret ? *mirror_num_ret : 0); + io_geom.num_stripes = 1; + io_geom.stripe_index = 0; + io_geom.op = op; + 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 +6434,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, io_geom.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 +6449,51 @@ 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; 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 +6505,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 +6539,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 +6569,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 +6594,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 +6604,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 +6619,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 +6638,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 Wed Dec 13 14:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13491115 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="ckNXms9r" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63690E8; Wed, 13 Dec 2023 06:43:11 -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=1702478591; x=1734014591; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=DqGz1rYplJkgJR0SxwKCAVGZlaVGnSqeh82zQn3mpYM=; b=ckNXms9rfHbHwDnRz6oXwqykHduw6xaxeKdEDbv+gix1sMhv0n5HGPHn 4Y0dYVHBgK+FEWtaK2GZtf2Xi7blsPGO7tqVz0BPonqQGwa2XivYkmAFG 7N2Tvm4yYjd9o9TLE+9Jt/2m0gtJgjWCgQmJkP0RzGNyB2lA1S1eh1Rwn 7YIpd+SzlLTQ+A+VYUda1Ial5CPZidsyxXsFVVAHcs/+AKAyfuvo/iEMi bZaE7I9400Btkx+Se9unzpzf3LAjVuD0JGfC5K88Sgb/5gAVQZOxD5do8 j+5t+gkAuCpS3rNmCCEpbAwI91X+TqiyDj4DPDMMRU9D89u8DpeG7LLLU A==; X-CSE-ConnectionGUID: G3elwU++R5S2CLMLHtBxgQ== X-CSE-MsgGUID: 9aZGGctJTzKQeoUe90wQvg== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802950" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:10 +0800 IronPort-SDR: 0ZLJys326bWtX5l6B2E3V467+WDcPbPFazSB5KndUOnuS2UDE0Vh2GHjNzAPvlfu1N9j2TerD0 ZBgW9JkMlGXw== 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; 13 Dec 2023 05:48:23 -0800 IronPort-SDR: mH4/02Fv0lKDus5ePvVTMvCY4GcsQCIgXfl0a07nDa7OLM8yWYJN+BahVF5sUpqok9FeqqBFgI HZ7YOqg1H1NQ== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:10 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:42:58 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-3-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=1489; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=DqGz1rYplJkgJR0SxwKCAVGZlaVGnSqeh82zQn3mpYM=; b=xlbEMd1j1Wu9P6eCyo6iBXspLF9f3x7tz0e67tYGzF/xVt1F9OourzYw6O4kTvg138QGFZQWZ ObmXHrFmD1vCbvc33JVGokDB9k2YSuo0Of+JU6nWruJWmgT2YaYcG7X 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 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ea830ff0c0e3..1d2e6fb7b9bf 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6363,6 +6363,15 @@ static bool is_single_device_io(struct btrfs_fs_info *fs_info, return true; } +static void map_blocks_raid0(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; + if (io_geom->op == BTRFS_MAP_READ) + io_geom->mirror_num = 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6450,10 +6459,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, up_read(&dev_replace->rwsem); 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_raid0(map, &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 Wed Dec 13 14:42: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: 13491116 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="JyF3WpfZ" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0DE3F3; Wed, 13 Dec 2023 06:43:12 -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=1702478592; x=1734014592; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=DVkLebp/jq2o9nPLKBH36Ylzg4UHswQI1Rt/5sJXbtI=; b=JyF3WpfZFnrGLd2wOOttzdXcI02AKRQR8U+/EnWOg1cmDT4rPVgTh6rL X143AyI587MLYxD9bOdvycJb+V5cqFM2WSO4+kFxxKFu0ykMbw+ucVMkH wwMku8VfyYiY32aX/48l58AsoFUQeMmtecI36uMd2fmAqf7QhGyZUKX7u L4o4lKU8sEE0IsQmTVqht9/v6w61/EC1edntnSA/4GIpgh+tpDglg6S8p r7R6Aj1wrmuCTREv8frceRdf0GpbGOJLLxtYxlpC+tDZ7oxoupgow1xsH Qx9GkJGH8I0ccwtyxMOU7mIvaIUW4wUte9fGyDrRmGOWC5P+QNBvIEZFS g==; X-CSE-ConnectionGUID: OrrUzAxyQDCplnkLgDsnEw== X-CSE-MsgGUID: nKJB3GZCQK6JDRStopihqQ== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802956" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:12 +0800 IronPort-SDR: sxwvuniB2EqbXaM9zqPJ0F2Rf9hj9/HuzkLgPrTYHXeONtGeh9ed7LHEZPzY9M4Hfp0huihwwO iw6PoBuTshlA== 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; 13 Dec 2023 05:48:24 -0800 IronPort-SDR: mBAKFcxwrFzfAj2Vom8gDZqGSIAYT3F+pNQ4WUosCO/psNqVrevXsPYu5WI2NFJ7LO1tX4YCKh JU3dwU9wAMVQ== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:11 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:42:59 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-4-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=2037; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=DVkLebp/jq2o9nPLKBH36Ylzg4UHswQI1Rt/5sJXbtI=; b=1youUuYANsh3hL/Mdb6+hv235E6Q8ipshOVB79p0pzI7PCmvrwARxCxk7rgvYcjGQZwztsVG6 //mH5cnu9pzC/MruV7UKKmV9hCGAOgDFkdz+rCb5omSvb2Gd2TaDiCT 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 | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1d2e6fb7b9bf..c11fb6db4679 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6372,6 +6372,26 @@ static void map_blocks_raid0(struct btrfs_chunk_map *map, io_geom->mirror_num = 1; } +static void map_blocks_raid1(struct btrfs_fs_info *fs_info, + struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom, + bool dev_replace_is_ongoing) +{ + if (io_geom->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, + dev_replace_is_ongoing); + io_geom->mirror_num = io_geom->stripe_index + 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6461,16 +6481,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_raid0(map, &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_raid1(fs_info, map, &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 Wed Dec 13 14:43: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: 13491117 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="bi1hDzPp" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF29710D; Wed, 13 Dec 2023 06:43:13 -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=1702478593; x=1734014593; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=OGBopphelKNfH3fDb7Sryq8+Z3p2RDE/ywfM09UR7p4=; b=bi1hDzPpuKz0//o8Oxmm8HLJnQ4g4W7TxEOywbRKxhyjgisp64xgXCzS jJxSduvcv4Dksf+F+5eQ14HX8sPSnQlchYJUD3OCJHH6UueAo6m2BIV++ 9WPCIPFj1qoZFjNV4PqIsTuhVyimqY9/cdol0eAgV97YZs22S7K3a/B+a f/G8yp+z8XJ4pYoSr+tlvy7GEgUUWq5S8wDCxAF3bFiE2FwR1iLOJqsAR 08UmLScHaJj2fxbfN5CYhyDSdsUvjVmKvodgcVl1Ncq6iwBoNlXjcCbEn eUfhoPvmP61UAYqhVA7pb8Upz41M8edVAubjDhJasIfSxPwVgTq9fQY8P Q==; X-CSE-ConnectionGUID: 1f+F10bjSYigoi42PdxRig== X-CSE-MsgGUID: FEuCJKl3SemXdBePbuYRSA== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802960" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:13 +0800 IronPort-SDR: FLJAOc0lbqerwDZ4MToxlU4c9G7Ttz9yqNEZuHaraCPJrIOnuibTmOeMu9t9Q9cB+cWd8Al1ij Znz4+PAH1mEQ== 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; 13 Dec 2023 05:48:25 -0800 IronPort-SDR: rnTZSX//iZgybjgnnAkzZqoPezDuWIFemcqbCoxFEr5w+jxQ2TeSNvkH0WraZ1ksD8KfbGE2Xf NxEebyD4s/Bg== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:12 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:00 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-5-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=1656; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=OGBopphelKNfH3fDb7Sryq8+Z3p2RDE/ywfM09UR7p4=; b=RoUSRB0NVfcBYTvIOqxOOxqc+hkutI1em/Twwdx6l0bDKETDThATmODhCll6UwYpaFA8rq/uH 0Tzc8n5u/9FA6kNzuXkI3dhPx+QfoO14JiDspxKP41PCdWZTtwvmoDQ 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 | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c11fb6db4679..fe2807bb0935 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6392,6 +6392,22 @@ static void map_blocks_raid1(struct btrfs_fs_info *fs_info, io_geom->mirror_num = io_geom->stripe_index + 1; } +static void map_blocks_dup(struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom) +{ + if (io_geom->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. * @@ -6484,14 +6500,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_blocks_raid1(fs_info, map, &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_dup(map, &io_geom); } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { u32 factor = map->num_stripes / map->sub_stripes; From patchwork Wed Dec 13 14:43: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: 13491118 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="i6yZLI7W" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3AEE107; Wed, 13 Dec 2023 06:43:14 -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=1702478594; x=1734014594; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=k/eSjTGoN725k3LZy+WZVmCNR9DvRAZuWjLXRQb2ZVo=; b=i6yZLI7WoRfc6IANfbDlojCNQ/f/XOTQb40S2dpTUn3c9TvFWp78feQq HfiMDal8qp/9nIoDuOCl+HkchLDxYxLkxeh1HhzaknGXDVnHoCF1mRuv0 9/p2y0axZIRDfA8l/41Y5dtSvRwllsk/yCT/WAd/tAMNzXcy7x4fTVOda ea0JaFM5T1UMITQaR6E8dggg18962EkQ3PpI9FKS207Ovo5pE0Lp19yIf XiTVB820IK4JzvX/EXUz+g8zoh/KFlCUPeXH8ZiyqZiaB8oM2Qs4HjNcI XyqJKHVhnX2VLR5PoFPxMlLmAO1eUTDAQAMu+fpknst04GUPQhyyCkRex Q==; X-CSE-ConnectionGUID: Vhjy7St+RmqxN4ifySrVjQ== X-CSE-MsgGUID: 429hW5lOTuib3QA+JrmxTw== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802965" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:14 +0800 IronPort-SDR: NUVmos8vm9cR2oQ4Djni4qHbuIkxqcyumoZpCZC5PsUbne0f8HIrCLuk/2ehSQd+jPSC+jJNL8 T5jyxTmaiy2Q== 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; 13 Dec 2023 05:48:26 -0800 IronPort-SDR: c/s0/YKZMafYfky/XtrydRIzOSGnTzsxNh3F/dDJvjUDtMUqdUa0v9pxypBd9+Wk2oogwsW7Tk Mmfp2cs1adPA== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:13 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:01 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-6-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=2601; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=k/eSjTGoN725k3LZy+WZVmCNR9DvRAZuWjLXRQb2ZVo=; b=eGKcEIqKJEY7oDZiWFy+6o9xNILU5E60gvfBeHaPRV+52HMOLFF4IzrNtknxLTtgz1N/yakLW xIDvxy671pBBC4jAqdH8oNLTRB4FGQuNVSZUWHqH3psw4mEc4///jgn 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 fe2807bb0935..4c9c130cdfd0 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6408,6 +6408,35 @@ static void map_blocks_dup(struct btrfs_chunk_map *map, io_geom->mirror_num = 1; } +static void map_blocks_raid10(struct btrfs_fs_info *fs_info, + struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom, + bool dev_replace_is_ongoing) +{ + 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 (io_geom->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, + dev_replace_is_ongoing); + io_geom->mirror_num = io_geom->stripe_index - old_stripe_index + 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6502,23 +6531,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_dup(map, &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_raid10(fs_info, map, &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 Wed Dec 13 14:43: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: 13491119 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="ZQLgZOZC" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4594E91; Wed, 13 Dec 2023 06:43:18 -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=1702478598; x=1734014598; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=sLjwrenKmqHBOSqsM1KRhm85HG8IZyehA4bXrtvn4bM=; b=ZQLgZOZC275uLopqeMKgSMzkrMY8CtaqDrt3RU1a9H5cio0PV4VMXVrL H+D8ulphFAWtdoyQ29FON/YxeY2BD9jIKW6MkqdLUwxuts82KOiQSbFv2 KDL2Y4eFuvgXrRZCq5Hw9+f8IPZElgOvD8THCjxVOQ3WS3TpyY8cSySkE vm+UqBtLVvKI3E04m2xN0DEk9jEf9yRgr49y5GwxPmAfCAkq4adpvOpOf SKT8TZap/7uPtN4aYiDpaEtdeIFLv2ezwqbC0L1DvEYEKyFbx5jUCpVYY XL1VqxJpcSbgpLtrJjOyZ7in/Lh65Koq4l3zKmtfDEB1HBTDYkiQd/GGK g==; X-CSE-ConnectionGUID: EkFSIohuSm+ooJQ9K/Wkgw== X-CSE-MsgGUID: jPewL/rvQvi5Xyl14Xds4Q== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802972" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:17 +0800 IronPort-SDR: yIkfoK9NMfQ5amNWjB7XCr1Y8+sZR0QjjSpLWtWKGqqujb6rc7nsn96UO5sSk+eg/aXk0q3iTQ c9wfDbRYckTQ== 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; 13 Dec 2023 05:48:29 -0800 IronPort-SDR: jPwWC4S6kGyM8dieutpeuowuWyiIVgIWCh6TWacQP2GwV9yx/q44p3bdBdHoxkLOd8Fc1bUdHW jdCeE/DcoJsw== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:15 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:02 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-7-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=1985; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=sLjwrenKmqHBOSqsM1KRhm85HG8IZyehA4bXrtvn4bM=; b=QCzPri8RzAPG0gQUjoB9ReI3jAolOkhuz/CxGWfC4Z32Nu4ABb2QM8e69FhqOPars7B46FJ2F 0S1GI3+M2PSD6ncphJIeR8ono5Xs/VBqXt7ixv/kwKsS2xRsAZC2ESr 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 4c9c130cdfd0..3a6a2f71d364 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; @@ -6505,8 +6504,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, io_geom.op, map_offset, &io_geom.stripe_nr, @@ -6534,6 +6531,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_blocks_raid10(fs_info, map, &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. @@ -6645,7 +6644,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 Wed Dec 13 14:43: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: 13491120 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="NyZ3MJKX" Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49121F5; Wed, 13 Dec 2023 06:43:18 -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=1702478598; x=1734014598; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=JrLC6otdJpNPxBMTEGtJC5+A4K6Kf+scnbb6ZiQ1bcM=; b=NyZ3MJKX4ayoKXA81odEQhAGJtDl2WRtko/nXlYOYZNgnsn8a8kTSmr5 sQ/AAaiWJRxM28kUfL0FN2mhaF19XlBgE84yMivXBFuFjQ2vStrkjThI1 0ks+I4NY0+ubVb44GWPV7Q4kQ/Ymh6Wwyy6We0N0HeYM43IR26/kz80HF h1RnOJaqqnhsjwM9cI2RSrd0SVCGy8QiIxzG/ebBDEzj5EuWSmapzQ3Bx Labgvp0Av1Fx8EtPH9YlSJKTQMOnxrLJWbti4b1Dr0rKHFuRfpzJ4xO5F lLmZ+ZyqedBisPDozTlaT4ZPJmLH6YcemQfcA1zGlxxNSJcRGRwQtREKW w==; X-CSE-ConnectionGUID: ModD/G22Tb6H3dDQmnAG1A== X-CSE-MsgGUID: 5pr2wx8QRQiuTuRVW5F4HA== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580758" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:18 +0800 IronPort-SDR: 3QbjBlfbIFqCPWx5EZ1PD3MXbVfd8VGMdibjiHnnmFEpE+HXFuPo4wkxtmQEHK1MwezGsrDhpJ twHPojFYFMAg== 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; 13 Dec 2023 05:48:29 -0800 IronPort-SDR: 0e2xv/lp+/Uo5Obqqegq+kFah03nY2x0azHvdUub5ucRxjXix6DpwUxJqgW8ttRGFvy6zzpw1Q VfZ7S57gFRcg== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:16 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:03 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-8-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=4380; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=JrLC6otdJpNPxBMTEGtJC5+A4K6Kf+scnbb6ZiQ1bcM=; b=hNSvkQw//aHD+11hnf5wXBYQNAWrLOptg4mI7qL3TM5DCyXRbJDcMiW8sfTJ6Pb36YbGPDOpM NIxB4YdUYWIA1u+Cs+KodZNRjcsa+n+uk6ukNdWS0mTiDlIHqfdFAC9 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 | 96 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3a6a2f71d364..55614a9eb8a5 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6437,6 +6437,56 @@ static void map_blocks_raid10(struct btrfs_fs_info *fs_info, io_geom->mirror_num = io_geom->stripe_index - old_stripe_index + 1; } +static void map_blocks_raid56_write(struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom, + u64 logical, u64 *length) +{ + int data_stripes = nr_data_stripes(map); + + /* + * 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; +} + +static void map_blocks_raid56_read(struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom) +{ + int data_stripes = nr_data_stripes(map); + + 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 (io_geom->op == BTRFS_MAP_READ && io_geom->mirror_num < 1) + io_geom->mirror_num = 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6531,48 +6581,10 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_blocks_raid10(fs_info, map, &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; - } + if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) + map_blocks_raid56_write(map, &io_geom, logical, length); + else + map_blocks_raid56_read(map, &io_geom); } else { /* * After this, stripe_nr is the number of stripes on this From patchwork Wed Dec 13 14:43: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: 13491121 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="rsq3ow2e" Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4D95DD; Wed, 13 Dec 2023 06:43:19 -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=1702478599; x=1734014599; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=qN9uFU57GBna2r1afgLudejpCt6oeNpZ8RYEEAbqQXg=; b=rsq3ow2eWmjEgFeyR0jpq8WGVr3aVBbipVvjQfs8g+QM/jxxDkmNYsun dchscET/rroFcnDmjXZ3CnM4PpCkoGtbe/zc327lsmXszDShDt0F+NY87 rUMQWE75TNobHNp5N3R+O9jnCvOkBk7EiMM2/zDOesmFFhtr57vqPnvbY Saz6MPtaL5uEAsMAsH3Sap6UTrsBjpOBAP1PMPzCewoVsNXPDIur8u4jU aN+2JEmbXxoy2fQRU5iaIQx4+PhacXxIIK74rqZf4oGzmvgB/EiYvdFYS wH9hLOQulVExhrQuKs53KDKuYaofX7ADa2iZBFXYrbbyBNgNo4sN9aBbD w==; X-CSE-ConnectionGUID: FSnTn6JcTaaJEa7Na8rxyg== X-CSE-MsgGUID: LInRM9QtT9iKNuNtPYzxhQ== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580759" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:18 +0800 IronPort-SDR: lyt6xR+vykByqf1jWQA8GMQ/ft12tNXRgi7Z25mb2GJxiDgjA8doJhOOYCg+DgKQaPcQEHb3Ub TmQl6n7JXF2w== 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; 13 Dec 2023 05:48:30 -0800 IronPort-SDR: J2ayBnMfsZEDf/vIc07aK+WYzQeCZ/WpAJqHvaNHjQ2NotY1+NOxfWGl/LoOA44EUhCMHF8yW/ EwbcbU+id01g== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:17 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:04 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-9-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=1479; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=qN9uFU57GBna2r1afgLudejpCt6oeNpZ8RYEEAbqQXg=; b=GNdQPNmiHfgl1oXaJa/IVRS0l3ajkT51NLCGozaz/MHqjMXwZZ1CW6t4MH4Jx3fi4CkpD97Ym g4JV3WNQke0Ce8JBP4/pBhcFu5cxQp3j3hu7Trc+B1uQk/QkogCGigQ 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 55614a9eb8a5..e23c7d2842a6 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6487,6 +6487,14 @@ static void map_blocks_raid56_read(struct btrfs_chunk_map *map, io_geom->mirror_num = 1; } +static void map_blocks_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. * @@ -6591,9 +6599,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_single(map, &io_geom); } if (io_geom.stripe_index >= map->num_stripes) { btrfs_crit(fs_info, From patchwork Wed Dec 13 14:43: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: 13491123 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="YEFxn6+6" Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7C26111; Wed, 13 Dec 2023 06:43: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=1702478603; x=1734014603; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=e/guiXA3HBcKLNpRnItMMeCwjZTheHhEwP/jrp5atmY=; b=YEFxn6+6IlKeT0YQC4cpeK0ELg1lr/xsOgW5A3XgKFt09X+KbQfDre3h xVWfQTm+rFqSJ2aVK82dExss7co5KFERtMAECGzPm5K25+HTzIpWeQ/pp 0g2pi890oR/fcoNYUoTHktKX3eoN/iBqMRvapkoiV3sPcKZO7Tu6AztTP B+J2DbjRLSR8OJh7imXZ78Pr4sX8DKRNpckvjFcty0N5vi6wafhP3ZqkE VqvQRPG7gI1nCNxA90Jfn434o/vNV652rADDF/nuXAJG/LpdOmo2NNcWI 0akP7X7C+YR1BWxIeg8WQNSkJWqURufHbCnIhiPOSoU+ApwL3vv8ovO2x w==; X-CSE-ConnectionGUID: 3Rfrop7cQL+I8pt+OZDsgg== X-CSE-MsgGUID: NtmwwGUHSf+D2X5YTBQt0w== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580767" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:22 +0800 IronPort-SDR: E3ko+KObtmN9TWOk2pjWdNbkx8lZGuD4z2YPFejS1loJAazcKfeP+3OJ0AtdU1lPoeKRM6ci/G VKdnn5BS/XuQ== 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; 13 Dec 2023 05:48:31 -0800 IronPort-SDR: GdIZ5OuzcBMxPNwuIsC7fpMODao02c7yFLhY+nG/WPXU5q3TmOAJNaJaxsiCANvkOcy6gqcF+c nfFvpZLHs1LA== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:19 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:05 -0800 Subject: [PATCH v2 10/13] btrfs: 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: <20231213-btrfs_map_block-cleanup-v2-10-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702478586; l=2122; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=e/guiXA3HBcKLNpRnItMMeCwjZTheHhEwP/jrp5atmY=; b=4lWlvPgsM4isrIKCCNY0se1/2neTvCtcmnMZFfFbAQn0bacYYcdj2A4V6CHCxVwmCbEM8RHZG jvkhaRP43FxA3v5CAJstrbh3wAgHkxCOhW6ID2+ovZJHFPnZg22Pr1D X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= Untangle the if-else maze in btrfs_map_block into a switch statement, checking the different block-group profile types and call out into the per-profile block mapping helpers. Reviewed-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index e23c7d2842a6..efb31c3005b7 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6578,28 +6578,38 @@ 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); - if (map->type & BTRFS_BLOCK_GROUP_RAID0) { + switch (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { + case BTRFS_BLOCK_GROUP_RAID0: map_blocks_raid0(map, &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_raid1(fs_info, map, &io_geom, dev_replace_is_ongoing); - } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { + break; + case BTRFS_BLOCK_GROUP_DUP: map_blocks_dup(map, &io_geom); - } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { + break; + case BTRFS_BLOCK_GROUP_RAID10: map_blocks_raid10(fs_info, map, &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: if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) map_blocks_raid56_write(map, &io_geom, logical, length); else map_blocks_raid56_read(map, &io_geom); - } 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_single(map, &io_geom); + break; } if (io_geom.stripe_index >= map->num_stripes) { btrfs_crit(fs_info, From patchwork Wed Dec 13 14:43: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: 13491122 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="hxjbiCxM" Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C7EBE8; Wed, 13 Dec 2023 06:43: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=1702478601; x=1734014601; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=Ah3Vw4nWYJIAnXcNelLMdrcDtyNCiNo5U8kP1u49x0w=; b=hxjbiCxMrofXuH7CTxI7TfIP5cxi9L0pOTEAnPrZAsJGllASRlhk/L0m JaDRB7aZrXlDxSdoZPCPNsJFAqZu7suUXZufRYa/0irtJYKwcH1r0J9yq nhu5Sd2RN3h+TOdZeoboBE4E+Sj0EyRfx5h1BUxkbKyHzB9nJCeNChDR6 kTSvj+wEUiv1KKMHR817bCgfkGQKp/nfhVkHi7TcPuqtW/kFZPjZX3RZw byrak2dIkTnoyA728mbHfq5w5lm9nH8V27tlEtqz0ld4Eh+hYyiU6b4HS RF4JWh9HKf8C3VHfL+1Gr9D+O9r1MGGBb//DzVYFLdtfjps3f/WG65nM+ w==; X-CSE-ConnectionGUID: 6RG5a2QoQbSVfa9bIkD+2Q== X-CSE-MsgGUID: Lp4CYsTAQHC565vYKhi2JA== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580766" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:21 +0800 IronPort-SDR: hTgQ5HwwCuP+Wz6gDtS3ZsRJvMDAwZbkgHhw2LA2R59wHV9Czqb8OkS5fek++3435UM57mr5t5 KpitkyOWO2FA== 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; 13 Dec 2023 05:54:13 -0800 IronPort-SDR: VvVdq1CnJZr2JfFT6DnT7dtllm1H9tFvlOJzi52jo7n6yXsIW8fPcKV7HRkmW4vRrZOOuGCU4s KFJTrQHrfg4Q== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:20 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:06 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-11-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702478586; l=1394; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=Ah3Vw4nWYJIAnXcNelLMdrcDtyNCiNo5U8kP1u49x0w=; b=JdXIZ2jgKTDsilTL8y0X1wiwgQYzp3eVnaq/e99QhWGLgO4/80TcF+4a8jehziRY38V4XiH9L WWBcyX0g4I1A/YdBXoqzPYZRosQJR4mU5mYMDBe2orIFftkhZkbM4VZ 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. Reviewed-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- 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 efb31c3005b7..5e4885a01796 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6675,13 +6675,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 Wed Dec 13 14:43: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: 13491124 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="kmYLvyMj" Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9365113; Wed, 13 Dec 2023 06:43: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=1702478603; x=1734014603; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=eZt1O9QucdaQ99WccyAeIMWXNVcbEm/Y3+q0saMB1e4=; b=kmYLvyMjHizh3TsdZFSbhXlm77dPnp7ST3LJS+X5GkGe2otFHSVWRYL+ 7eqU/aI7osADAFMyeWZqhliRcddSjsO6ygZ0fxSkJlmH8GO7rxc9Gb/RO FjMp9o8RZROgNn96Al8nFe1QtKl0feUsDIxZiraf2L769r8PbYGmNwaSO 0DWhNKdiatwsCCAOp+WzrA5dKS6wDEmAT5ITjeZmaDm+IU3N/0ADBXfoF qV0sfUJdb3k/TgkPN6xUSgnmAYmeY1XlLzwdVVnw8Z9sPV7oggYUG1J38 LCuDfWozEoBYw35YAxhCUrAit1ffdFVdDcrMkfSVimFR1al8t2uJhZmzn w==; X-CSE-ConnectionGUID: UiNuIYSbTj+0pO70I3pRrw== X-CSE-MsgGUID: s9FO/aUeQkyvOyC0yD1ThQ== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580769" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:22 +0800 IronPort-SDR: ctGPnXkYGwXbRolnSzBm89i7vg3m3zdNMdvCeF26KmMh2AR9p9+LPa4rDdMT5wdv/UUSlrssbX yx9zFGXMjpAw== 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; 13 Dec 2023 05:48:34 -0800 IronPort-SDR: n1d5fkQCkaI8Fdxj7iL1ktPusJ8p+V4vkMrytCZTeuAigmV32ihbqQhQ8BM1D9HqUyagPCYDGp NCmBpl3MpoCQ== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:21 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:07 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-12-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=2892; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=eZt1O9QucdaQ99WccyAeIMWXNVcbEm/Y3+q0saMB1e4=; b=g41Ospujk+QFP0sv8LXM/Gi1HPxraC4KaS5+vr9p2XRrIj+7JcgZIcoTnZd1cpUmQmL0imz3A vWBspq5WS/UC5cvDkzyu03wXNWGML/vtQXAofqiYT/5bC46CRLtmDkj 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 | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5e4885a01796..440ac0c1c907 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6325,19 +6325,22 @@ static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, enum btrfs_map_op op, return U64_MAX; } -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) +static int set_io_stripe(struct btrfs_fs_info *fs_info, u64 logical, + u64 *length, struct btrfs_io_stripe *dst, + 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)) + if (io_geom->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; } @@ -6638,9 +6641,8 @@ 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); + ret = set_io_stripe(fs_info, logical, length, smap, map, + &io_geom); if (mirror_num_ret) *mirror_num_ret = io_geom.mirror_num; *bioc_ret = NULL; @@ -6692,11 +6694,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * stripe into the bioc. */ 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); + ret = set_io_stripe(fs_info, logical, length, + &bioc->stripes[i], map, &io_geom); if (ret < 0) break; io_geom.stripe_index++; From patchwork Wed Dec 13 14:43: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: 13491125 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="p17WjYou" Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 216E4DD; Wed, 13 Dec 2023 06:43:24 -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=1702478604; x=1734014604; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=+TftUUx2tLHphusHbKwAkIsPHhEjw8xGZXfDg5e4VA4=; b=p17WjYouU1pa/eNVZPgTrWjTBzHnz05WyWMmLwwi9giSrIxig+Tn9fiZ wKdAUfJDuauP8S+L6UHW5yxM0L6yaEH8bvKJeDh70McHs5Eee9dOdbH3P /dLnyE7W7Vj9IRSSPBPo6x+enq4mkk6l5iCS2DT/7rUItzq6dvsNczseD Vaa9bvFGZjBYprUORmvc8rndYlBuXUJTnkVElaYFpSsf07tytCELBCsIM FN3cNh5xRDG5/Saaos6hl8SvY0Yo46jic+HCCUz8om6CiisApFLnN3kGr K+ygMXWSHpQpz2Ehv2I7iS0uHF62TgrXO3HenB8NgtyVWddSlqu1e/vBU Q==; X-CSE-ConnectionGUID: nf+DZJhFT1OtkMLl9oEkSA== X-CSE-MsgGUID: Z1/XJVbrRsy7gnBZRYfW/Q== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580771" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:23 +0800 IronPort-SDR: zUSHzdLmWTnWUHuSxoV6+WxTQKZgy33EHNmSsTK70enuTJmDB0F7QOy4UcGzEI9K1sstDffQ5c FnRT3Ss7FF+A== 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; 13 Dec 2023 05:48:35 -0800 IronPort-SDR: 2i3JYJmaowjXk8a9dnNE++rmRUZIdVWsy/NP6EHrCjfPlhv3hf3ObCzWhCPWIdLAgtfL6N8nhW m4+7t5h9m5Zw== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:22 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:08 -0800 Subject: [PATCH v2 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: <20231213-btrfs_map_block-cleanup-v2-13-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=3294; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=+TftUUx2tLHphusHbKwAkIsPHhEjw8xGZXfDg5e4VA4=; b=8Y2fUAr7KwnhLCRKmviEJLcDpFAOVutymltmuVbA1agTg8HC3E24PFd8X0JTUWyVO9qGYEPa7 IfrGUGc+C1eAQ8pSyQn4yfpMQNTqq3ipnA6+6TvCoRKiiNBwVroRyJv 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 | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 440ac0c1c907..af803b162d0b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6277,17 +6277,16 @@ static void handle_ops_on_dev_replace(enum btrfs_map_op op, bioc->replace_nr_stripes = nr_extra_stripes; } -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) +static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, 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 = @@ -6302,18 +6301,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); + if (io_geom->op == BTRFS_MAP_WRITE) + return full_stripe_len - + (offset - io_geom->raid56_full_stripe_start); } /* @@ -6321,7 +6321,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; } @@ -6567,9 +6567,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, io_geom.op, map_offset, &io_geom.stripe_nr, - &io_geom.stripe_offset, - &io_geom.raid56_full_stripe_start); + max_len = btrfs_max_io_len(map, map_offset, &io_geom); *length = min_t(u64, map->chunk_len - map_offset, max_len); down_read(&dev_replace->rwsem);