Re: [PATCH 1/3] block: add a bio_reuse helper

Hannes Reinecke
2025-12-18T09:20:39Z

On 12/18/25 07:31, Christoph Hellwig wrote:
> Add a helper to allow an existing bio to be resubmitted withtout
> having to re-add the payload.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> block/bio.c | 25 +++++++++++++++++++++++++
> include/linux/bio.h | 1 +
> 2 files changed, 26 insertions(+)
>
> diff --git a/block/bio.c b/block/bio.c
> index e726c0e280a8..1b68ae877468 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -311,6 +311,31 @@ void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf)
> }
> EXPORT_SYMBOL(bio_reset);
>
> +/**
> + * bio_reuse - reuse a bio with the payload left intact
> + * @bio bio to reuse
> + *
> + * Allow reusing an existing bio for another operation with all set up
> + * fields including the payload, device and end_io handler left intact.
> + *
> + * Typically used for bios first used to read data which is then written
> + * to another location without modification.
> + */
> +void bio_reuse(struct bio *bio)
> +{
> + unsigned short vcnt = bio->bi_vcnt, i;
> + bio_end_io_t *end_io = bio->bi_end_io;
> + void *private = bio->bi_private;
> +
> + bio_reset(bio, bio->bi_bdev, bio->bi_opf);
> + for (i = 0; i < vcnt; i++)
> + bio->bi_iter.bi_size += bio->bi_io_vec[i].bv_len;
> + bio->bi_vcnt = vcnt;
> + bio->bi_private = private;
> + bio->bi_end_io = end_io;
> +}
> +EXPORT_SYMBOL_GPL(bio_reuse);
> +

'reuse' has a different connotation for me; I woudl have expected
a 'reused' bio to be used for any purposes.
Maybe 'bio_reprep'?

Otherwise looks good.

Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich