On 4/26/22 12:12, Nitesh Shetty wrote:
Add new BLKCOPY ioctl that offloads copying of one or more sources ranges
to one or more destination in a device. COPY ioctl accepts a 'copy_range'
structure that contains no of range, a reserved field , followed by an
array of ranges. Each source range is represented by 'range_entry' that
contains source start offset, destination start offset and length of
source ranges (in bytes)

MAX_COPY_NR_RANGE, limits the number of entries for the IOCTL and
MAX_COPY_TOTAL_LENGTH limits the total copy length, IOCTL can handle.

Example code, to issue BLKCOPY:
/* Sample example to copy three entries with [dest,src,len],
* [32768, 0, 4096] [36864, 4096, 4096] [40960,8192,4096] on same device */

int main(void)
{
        int i, ret, fd;
        unsigned long src = 0, dst = 32768, len = 4096;
        struct copy_range *cr;
        cr = (struct copy_range *)malloc(sizeof(*cr)+
                                        (sizeof(struct range_entry)*3));
        cr->nr_range = 3;
        cr->reserved = 0;
        for (i = 0; i< cr->nr_range; i++, src += len, dst += len) {
                cr->range_list[i].dst = dst;
                cr->range_list[i].src = src;
                cr->range_list[i].len = len;
                cr->range_list[i].comp_len = 0;
        }
        fd = open("/dev/nvme0n1", O_RDWR);
        if (fd < 0) return 1;
        ret = ioctl(fd, BLKCOPY, cr);
        if (ret != 0)
               printf("copy failed, ret= %d\n", ret);
        for (i=0; i< cr->nr_range; i++)
                if (cr->range_list[i].len != cr->range_list[i].comp_len)
                        printf("Partial copy for entry %d: requested %llu, completed 
%llu\n",
                                                                i, 
cr->range_list[i].len,
                                                                
cr->range_list[i].comp_len);
        close(fd);
        free(cr);
        return ret;
}

Signed-off-by: Nitesh Shetty <[email protected]>
Signed-off-by: Javier González <[email protected]>
Signed-off-by: Arnav Dawn <[email protected]>
---
  block/ioctl.c           | 32 ++++++++++++++++++++++++++++++++
  include/uapi/linux/fs.h |  9 +++++++++
  2 files changed, 41 insertions(+)

Reviewed-by: Hannes Reinecke <[email protected]>

Cheers,

Hannes
--
Dr. Hannes Reinecke                        Kernel Storage Architect
[email protected]                                      +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

Reply via email to