Skip to content

Commit

Permalink
scst_vdisk: Add XCOPY support in blkdev handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ixhamza committed Jul 15, 2024
1 parent 0557e53 commit d602507
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions scst/src/dev_handlers/scst_vdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -6430,6 +6430,49 @@ static void vdisk_task_mgmt_fn_done(struct scst_mgmt_cmd *mcmd,
return;
}

static void vdisk_bio_ext_copy_remap(struct scst_cmd *cmd,
struct scst_ext_copy_seg_descr *seg)
{
struct block_device *in_bdev, *out_bdev;
loff_t pos_in, pos_out;
size_t len, ret;
struct scst_vdisk_dev *src_virt_dev = vdev_find(seg->src_tgt_dev->dev->virt_name);
struct scst_vdisk_dev *dst_virt_dev = vdev_find(seg->dst_tgt_dev->dev->virt_name);
uint64_t in_bdev_size, out_bdev_size;

if (!src_virt_dev || !dst_virt_dev || !seg) {
return;
}

in_bdev = src_virt_dev->bdev_desc.bdev;
out_bdev = dst_virt_dev->bdev_desc.bdev;
pos_in = seg->data_descr.src_lba << seg->src_tgt_dev->dev->block_shift;
pos_out = seg->data_descr.dst_lba << seg->dst_tgt_dev->dev->block_shift;
len = seg->data_descr.data_len;
in_bdev_size = bdev_nr_bytes(in_bdev);
out_bdev_size = bdev_nr_bytes(out_bdev);

if (len <= 4096 || (pos_in + len > in_bdev_size) ||
(pos_out + len > out_bdev_size)) {
return;
}

//TODO: Adjust size/offsets w.r.t block device block size
if (bdev_max_copy_sectors(in_bdev)) {
ret = blkdev_copy_offload(in_bdev, pos_in, pos_out, len,
NULL, NULL, GFP_KERNEL, out_bdev);
if (ret >= len) {
scst_ext_copy_remap_done(cmd, NULL, 0);
return;
}
}

/*
* Fallback to default SCST write path
*/
scst_ext_copy_remap_done(cmd, &seg->data_descr, 1);
}

#ifdef CONFIG_DEBUG_EXT_COPY_REMAP
static void vdev_ext_copy_remap(struct scst_cmd *cmd,
struct scst_ext_copy_seg_descr *seg)
Expand Down Expand Up @@ -9746,6 +9789,7 @@ static struct scst_dev_type vdisk_blk_devtype = {
.del_device = vdisk_del_device,
.dev_attrs = vdisk_blockio_attrs,
.add_device_parameters = blockio_add_dev_params,
.ext_copy_remap = vdisk_bio_ext_copy_remap,
#if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING)
.default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS,
.trace_flags = &trace_flag,
Expand Down

0 comments on commit d602507

Please sign in to comment.