On Mon, Jun 03, 2019 at 12:05:05PM +0300, Nikolay Borisov wrote:
> Presently btrfs_map_block is used not only to do everything necessary
> to map a bio to the underlying allocation profile but it's also used to
> identify how much data could be written based on btrfs' stripe logic
> without actually submitting anything. This is achieved by passing NULL
> for 'bbio_ret' parameter.
> 
> This patch refactors all callers that require just the mapping length
> by switching them to using btrfs_io_geometry instead of calling
> btrfs_map_block with a special NULL value for 'bbio_ret'. No functional
> change.
> 
> Signed-off-by: Nikolay Borisov <[email protected]>
> ---
>  fs/btrfs/inode.c   | 25 +++++++--------
>  fs/btrfs/volumes.c | 77 +++++++++-------------------------------------
>  2 files changed, 27 insertions(+), 75 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 80fdf6f21f74..a3abba4c2e2c 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -1932,17 +1932,19 @@ int btrfs_bio_fits_in_stripe(struct page *page, 
> size_t size, struct bio *bio,
>       u64 length = 0;
>       u64 map_length;
>       int ret;
> +     struct btrfs_io_geometry geom;

Stack bloatometer does not like it:

__btrfs_map_block                                                 +56 (200 -> 
256)
btrfs_submit_direct                                               +40 (176 -> 
216)
btrfs_bio_fits_in_stripe                                          +40 (40 -> 80)

OLD/NEW DELTA:     +104
PRE/POST DELTA:     +240

>  
>       if (bio_flags & EXTENT_BIO_COMPRESSED)
>               return 0;
>  
>       length = bio->bi_iter.bi_size;
>       map_length = length;
> -     ret = btrfs_map_block(fs_info, btrfs_op(bio), logical, &map_length,
> -                           NULL, 0);
> +     ret = btrfs_io_geometry(fs_info, btrfs_op(bio), logical, map_length,
> +                             &geom);
>       if (ret < 0)
>               return ret;
> -     if (map_length < length + size)
> +
> +     if (geom.len < length + size)

All the function needs from the geometry is one member 'len'.

>               return 1;
>       return 0;
>  }
> @@ -8331,15 +8333,15 @@ static int btrfs_submit_direct_hook(struct 
> btrfs_dio_private *dip)
>       int clone_len;
>       int ret;
>       blk_status_t status;
> +     struct btrfs_io_geometry geom;

And btrfs_submit_direct_hook does not seem to use the geom members at
all, which looks like the parameters are only validated in some way.

Reply via email to