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

Ming Lei
2025-12-18T09:40:17Z

On Thu, Dec 18, 2025 at 07:31:45AM +0100, 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;

The incoming bio can't be a cloned bio, so

WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED));

should be added.

Otherwise, it looks fine.

Thanks,
Ming