diff mbox series

[3/3] btrfs: pass btrfs_io_geometry to is_single_device_io

Message ID 20241212-btrfs_need_stripe_tree_update-cleanups-v1-3-d842b6d8d02b@kernel.org (mailing list archive)
State New
Headers show
Series btrfs: reduce repeated calls to btrfs_need_stripe_tree_update() | expand

Commit Message

Johannes Thumshirn Dec. 12, 2024, 12:54 p.m. UTC
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Now that we have the stripe tree decision saved in struct
btrfs_io_geometry we can pass it into is_single_device_io() and get rid of
another call to btrfs_need_raid_stripe_tree_update().

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/volumes.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Filipe Manana Dec. 13, 2024, 12:10 p.m. UTC | #1
On Thu, Dec 12, 2024 at 1:01 PM Johannes Thumshirn <jth@kernel.org> wrote:
>
> From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>
> Now that we have the stripe tree decision saved in struct
> btrfs_io_geometry we can pass it into is_single_device_io() and get rid of
> another call to btrfs_need_raid_stripe_tree_update().
>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>  fs/btrfs/volumes.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 088ba0499e184c93a402a3f92167cccfa33eec58..3636586371f6de2df76ecc67c2dbf2fdf3848995 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -6362,7 +6362,7 @@ static bool is_single_device_io(struct btrfs_fs_info *fs_info,
>                                 const struct btrfs_io_stripe *smap,
>                                 const struct btrfs_chunk_map *map,
>                                 int num_alloc_stripes,
> -                               enum btrfs_map_op op, int mirror_num)
> +                               struct btrfs_io_geometry *io_geom)
>  {
>         if (!smap)
>                 return false;
> @@ -6370,10 +6370,11 @@ static bool is_single_device_io(struct btrfs_fs_info *fs_info,
>         if (num_alloc_stripes != 1)
>                 return false;
>
> -       if (btrfs_need_stripe_tree_update(fs_info, map->type) && op != BTRFS_MAP_READ)
> +       if (io_geom->use_rst && io_geom->op != BTRFS_MAP_READ)
>                 return false;
>
> -       if ((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && mirror_num > 1)
> +       if ((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) &&
> +           io_geom->mirror_num > 1)

You can leave this in a single line, it stays at 83 characters, which
is not too long, making the code a bit more readable.

>                 return false;
>
>         return true;
> @@ -6648,8 +6649,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 (is_single_device_io(fs_info, smap, map, num_alloc_stripes, op,
> -                               io_geom.mirror_num)) {
> +       if (is_single_device_io(fs_info, smap, map, num_alloc_stripes,
> +                               &io_geom)) {

Same here, can place the whole thing in a single line, it stays at 82
characters, making it more readable than 2 lines.

Like suggested for the previous patches, you can also mention this
reduces the object size since btrfs_need_stripe_tree_update() is a
non-trivial inline function.

Thanks.

>                 ret = set_io_stripe(fs_info, logical, length, smap, map, &io_geom);
>                 if (mirror_num_ret)
>                         *mirror_num_ret = io_geom.mirror_num;
>
> --
> 2.43.0
>
>
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 088ba0499e184c93a402a3f92167cccfa33eec58..3636586371f6de2df76ecc67c2dbf2fdf3848995 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6362,7 +6362,7 @@  static bool is_single_device_io(struct btrfs_fs_info *fs_info,
 				const struct btrfs_io_stripe *smap,
 				const struct btrfs_chunk_map *map,
 				int num_alloc_stripes,
-				enum btrfs_map_op op, int mirror_num)
+				struct btrfs_io_geometry *io_geom)
 {
 	if (!smap)
 		return false;
@@ -6370,10 +6370,11 @@  static bool is_single_device_io(struct btrfs_fs_info *fs_info,
 	if (num_alloc_stripes != 1)
 		return false;
 
-	if (btrfs_need_stripe_tree_update(fs_info, map->type) && op != BTRFS_MAP_READ)
+	if (io_geom->use_rst && io_geom->op != BTRFS_MAP_READ)
 		return false;
 
-	if ((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && mirror_num > 1)
+	if ((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) &&
+	    io_geom->mirror_num > 1)
 		return false;
 
 	return true;
@@ -6648,8 +6649,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 (is_single_device_io(fs_info, smap, map, num_alloc_stripes, op,
-				io_geom.mirror_num)) {
+	if (is_single_device_io(fs_info, smap, map, num_alloc_stripes,
+				&io_geom)) {
 		ret = set_io_stripe(fs_info, logical, length, smap, map, &io_geom);
 		if (mirror_num_ret)
 			*mirror_num_ret = io_geom.mirror_num;