Re: [PATCH 1/5] block: new sector copy api

Hannes Reinecke
2025-05-22T10:02:19Z

On 5/22/25 00:31, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
>
> Provide a basic block level api to copy a range of a block device's
> sectors to a new destination on the same device. This just reads the
> source data into host memory, then writes it back out to the device at
> the requested destination.
>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
> block/blk-lib.c | 62 +++++++++++++++++++++++++++++++++++++++++
> block/ioctl.c | 30 ++++++++++++++++++++
> include/linux/blkdev.h | 2 ++
> include/uapi/linux/fs.h | 3 ++
> 4 files changed, 97 insertions(+)
>
> diff --git a/block/blk-lib.c b/block/blk-lib.c
> index 4c9f20a689f7b..a819ded0ed3a9 100644
> --- a/block/blk-lib.c
> +++ b/block/blk-lib.c
> @@ -368,3 +368,65 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
> return ret;
> }
> EXPORT_SYMBOL(blkdev_issue_secure_erase);
> +
> +/**
> + * blkdev_copy - copy source sectors to a destination on the same block device
> + * @dst_sector: start sector of the destination to copy to
> + * @src_sector: start sector of the source to copy from
> + * @nr_sects: number of sectors to copy
> + * @gfp: allocation flags to use
> + */
> +int blkdev_copy(struct block_device *bdev, sector_t dst_sector,
> + sector_t src_sector, sector_t nr_sects, gfp_t gfp)
> +{

Hmm. This interface is for copies _within_ the same bdev only.
Shouldn't we rather expand it to have _two_ bdev arguments to
eventually handle copies between bdevs?
In the end the function itself wouldn't change...

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