Re: [PATCH v2 2/3] btrfs: remove btrfs_bio_alloc() helper

David Sterba
2021-09-14T16:45:57Z

On Tue, Sep 14, 2021 at 09:25:42AM +0800, Qu Wenruo wrote:
> comp_bio->bi_end_io = end_compressed_bio_read;
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 1aed03ef5f49..5ef7c506aee6 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -3121,16 +3121,19 @@ static inline void btrfs_io_bio_init(struct btrfs_io_bio *btrfs_bio)
> }
>
> /*
> - * The following helpers allocate a bio. As it's backed by a bioset, it'll
> - * never fail.

This note should stay, it's not obvious why we don't need to handle the
allocation failure.

> We're returning a bio right now but you can call btrfs_io_bio
> - * for the appropriate container_of magic
> + * Allocate a btrfs_io_bio, with @nr_iovecs as maxinum iovecs.

maximum

> + *
> + * If @nr_iovecs is 0, it will use BIO_MAX_VECS as @nr_iovces instead.
> + * This behavior is to provide a fail-safe default value.
> */
> -struct bio *btrfs_bio_alloc(u64 first_byte)
> +struct bio *btrfs_io_bio_alloc(unsigned int nr_iovecs)
> {
> struct bio *bio;
>
> - bio = bio_alloc_bioset(GFP_NOFS, BIO_MAX_VECS, &btrfs_bioset);
> - bio->bi_iter.bi_sector = first_byte >> 9;
> + ASSERT(nr_iovecs <= BIO_MAX_VECS);
> + if (nr_iovecs == 0)
> + nr_iovecs = BIO_MAX_VECS;
> + bio = bio_alloc_bioset(GFP_NOFS, nr_iovecs, &btrfs_bioset);
> btrfs_io_bio_init(btrfs_io_bio(bio));
> return bio;
> }