Re: [RFC PATCH 01/37] block: introduce bio_init_fields() helper

From: Christoph Hellwig
Date: Tue Jan 19 2021 - 01:31:13 EST


I don't think a helper just to initialize a few fields is very useful.
But there is something in this area I've wanted to do for a while:

> +static inline void bio_init_fields(struct bio *bio, struct block_device *bdev,
> + sector_t sect, void *priv,
> + bio_end_io_t *end_io,
> + unsigned short prio, unsigned short whint)
> +{
> + bio_set_dev(bio, bdev);
> + bio->bi_iter.bi_sector = sect;
> + bio->bi_private = priv;
> + bio->bi_end_io = end_io;
> + bio->bi_ioprio = prio;
> + bio->bi_write_hint = whint;

Ensuring that the device, sector and op are always initialized would
really helper some of the bio mapping helpers, so I'd rather
add a new

struct bio *bio_new(struct block_device *bdev, sector_t sector,
unsigned int op, unsigned int max_bvecs, gfp_t gfp_mask)

helper, where max_bvecs is clamped to BIO_MAX_PAGES.

bi_private, bi_end_io, bi_ioprio and bi_write_hint on the other hand
are purely optional and can be easily set just by the users that care.