Re: [dm-devel] [RFC PATCH v4 2/3] block: add simple copy support

From: Selva Jove
Date: Tue Jan 05 2021 - 09:24:36 EST


Hi Darrick,


On Tue, Jan 5, 2021 at 12:33 AM Darrick J. Wong <darrick.wong@xxxxxxxxxx> wrote:
>
> SelvaKumar S: This didn't show up on dm-devel, sorry for the OT reply...
>
> On Mon, Jan 04, 2021 at 12:47:11PM +0000, Damien Le Moal wrote:
> > On 2021/01/04 19:48, SelvaKumar S wrote:
> > > Add new BLKCOPY ioctl that offloads copying of one or more sources
> > > ranges to a destination in the device. Accepts copy_ranges that contains
> > > destination, no of sources and pointer to the array of source
> > > ranges. Each range_entry contains start and length of source
> > > ranges (in bytes).
> > >
> > > Introduce REQ_OP_COPY, a no-merge copy offload operation. Create
> > > bio with control information as payload and submit to the device.
> > > REQ_OP_COPY(19) is a write op and takes zone_write_lock when submitted
> > > to zoned device.
> > >
> > > If the device doesn't support copy or copy offload is disabled, then
> > > copy is emulated by allocating memory of total copy size. The source
> > > ranges are read into memory by chaining bio for each source ranges and
> > > submitting them async and the last bio waits for completion. After data
> > > is read, it is written to the destination.
> > >
> > > bio_map_kern() is used to allocate bio and add pages of copy buffer to
> > > bio. As bio->bi_private and bio->bi_end_io is needed for chaining the
> > > bio and over written, invalidate_kernel_vmap_range() for read is called
> > > in the caller.
> > >
> > > Introduce queue limits for simple copy and other helper functions.
> > > Add device limits as sysfs entries.
> > > - copy_offload
> > > - max_copy_sectors
> > > - max_copy_ranges_sectors
> > > - max_copy_nr_ranges
> > >
> > > copy_offload(= 0) is disabled by default.
> > > max_copy_sectors = 0 indicates the device doesn't support native copy.
> > >
> > > Native copy offload is not supported for stacked devices and is done via
> > > copy emulation.
> > >
> > > Signed-off-by: SelvaKumar S <selvakuma.s1@xxxxxxxxxxx>
> > > Signed-off-by: Kanchan Joshi <joshi.k@xxxxxxxxxxx>
> > > Signed-off-by: Nitesh Shetty <nj.shetty@xxxxxxxxxxx>
> > > Signed-off-by: Javier González <javier.gonz@xxxxxxxxxxx>
> > > ---
> > > block/blk-core.c | 94 ++++++++++++++--
> > > block/blk-lib.c | 223 ++++++++++++++++++++++++++++++++++++++
> > > block/blk-merge.c | 2 +
> > > block/blk-settings.c | 10 ++
> > > block/blk-sysfs.c | 50 +++++++++
> > > block/blk-zoned.c | 1 +
> > > block/bounce.c | 1 +
> > > block/ioctl.c | 43 ++++++++
> > > include/linux/bio.h | 1 +
> > > include/linux/blk_types.h | 15 +++
> > > include/linux/blkdev.h | 13 +++
> > > include/uapi/linux/fs.h | 13 +++
>
> This series should also be cc'd to linux-api since you're adding a new
> userspace api.
>

Sure. Will cc linux-api

>
> Alternately, save yourself the trouble of passing userspace API review
> by hooking this up to the existing copy_file_range call in the vfs. /me
> hopes you sent blktests to check the operation of this thing, since none
> of the original patches made it to this list.
>

As the initial version had only source bdev, copy_file_rage call was not
viable. With this version, we have two bdev for source and destination.
I'll relook at that. Sure. Will add a new blktests for simple copy.

>
> If you really /do/ need a new kernel call for this, then please send in
> a manpage documenting the fields of struct range_entry and copy_range,
> and how users are supposed to use this.
>

Sure. Will send a manpage documentation once the plumbing is concrete.

> <now jumping to the ioctl definition because Damien already reviewed the
> plumbing...>
>
> > > diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
> > > index f44eb0a04afd..5cadb176317a 100644
> > > --- a/include/uapi/linux/fs.h
> > > +++ b/include/uapi/linux/fs.h
> > > @@ -64,6 +64,18 @@ struct fstrim_range {
> > > __u64 minlen;
> > > };
> > >
> > > +struct range_entry {
> > > + __u64 src;
>
> Is this an offset? Or the fd of an open bdev?

This is the source offset.

>
> > > + __u64 len;
> > > +};
> > > +
> > > +struct copy_range {
> > > + __u64 dest;
> > > + __u64 nr_range;
> > > + __u64 range_list;
>
> Hm, I think this is a pointer? Why not just put the range_entry array
> at the end of struct copy_range?
>

As the size of the range_entry array can change dynamically depending on
nr_range, it was difficult to do copy_from_user() on copy_range structure in the
ioctl. So I decided to keep that as a pointer to range_entry array
instead of keeping
array at the end.

> > > + __u64 rsvd;
>
> Also needs a flags argument so we don't have to add BLKCOPY2 in like 3
> months.
>

'rsvd' field is kept to support future copies. Will rename it.

> --D
>
> > > +};
> > > +
> > > /* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */
> > > #define FILE_DEDUPE_RANGE_SAME 0
> > > #define FILE_DEDUPE_RANGE_DIFFERS 1
> > > @@ -184,6 +196,7 @@ struct fsxattr {
> > > #define BLKSECDISCARD _IO(0x12,125)
> > > #define BLKROTATIONAL _IO(0x12,126)
> > > #define BLKZEROOUT _IO(0x12,127)
> > > +#define BLKCOPY _IOWR(0x12, 128, struct copy_range)
> > > /*
> > > * A jump here: 130-131 are reserved for zoned block devices
> > > * (see uapi/linux/blkzoned.h)
> > >
> >
> >
> > --
> > Damien Le Moal
> > Western Digital Research
> >
> >
> >
> > --
> > dm-devel mailing list
> > dm-devel@xxxxxxxxxx
> > https://www.redhat.com/mailman/listinfo/dm-devel
> >

Thanks,
Selva