Skip to content

Commit

Permalink
fs, block: copy_file_range for def_blk_ops for direct block device
Browse files Browse the repository at this point in the history
For direct block device opened with O_DIRECT, use blkdev_copy_offload to
issue device copy offload, or use splice_copy_file_range in case
device copy offload capability is absent or the device files are not open
with O_DIRECT.

Reviewed-by: Hannes Reinecke <[email protected]>
Signed-off-by: Anuj Gupta <[email protected]>
Signed-off-by: Nitesh Shetty <[email protected]>
  • Loading branch information
nj-shetty authored and ixhamza committed Jul 5, 2024
1 parent 1c6ab05 commit cb78d2e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions block/fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,28 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
return ret;
}

static ssize_t blkdev_copy_file_range(struct file *file_in, loff_t pos_in,
struct file *file_out, loff_t pos_out,
size_t len, unsigned int flags)
{
struct block_device *in_bdev = I_BDEV(bdev_file_inode(file_in));
struct block_device *out_bdev = I_BDEV(bdev_file_inode(file_out));
ssize_t copied = 0;

if ((in_bdev == out_bdev) && bdev_max_copy_sectors(in_bdev) &&
(file_in->f_iocb_flags & IOCB_DIRECT) &&
(file_out->f_iocb_flags & IOCB_DIRECT)) {
copied = blkdev_copy_offload(in_bdev, pos_in, pos_out, len,
NULL, NULL, GFP_KERNEL);
if (copied < 0)
copied = 0;
} else {
return -EOPNOTSUPP;
}

return copied;
}

#define BLKDEV_FALLOC_FL_SUPPORTED \
(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \
FALLOC_FL_ZERO_RANGE | FALLOC_FL_NO_HIDE_STALE)
Expand Down Expand Up @@ -839,6 +861,7 @@ const struct file_operations def_blk_fops = {
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
.fallocate = blkdev_fallocate,
.copy_file_range = blkdev_copy_file_range,
};

static __init int blkdev_init(void)
Expand Down

0 comments on commit cb78d2e

Please sign in to comment.