|
|
ae23c9 |
From d1046c844b369fb9cebc8f4f64274a9642152526 Mon Sep 17 00:00:00 2001
|
|
|
ae23c9 |
From: Fam Zheng <famz@redhat.com>
|
|
|
ae23c9 |
Date: Fri, 29 Jun 2018 06:11:48 +0200
|
|
|
ae23c9 |
Subject: [PATCH 174/268] iscsi: Implement copy offloading
|
|
|
ae23c9 |
|
|
|
ae23c9 |
RH-Author: Fam Zheng <famz@redhat.com>
|
|
|
ae23c9 |
Message-id: <20180629061153.12687-9-famz@redhat.com>
|
|
|
ae23c9 |
Patchwork-id: 81159
|
|
|
ae23c9 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH v2 08/13] iscsi: Implement copy offloading
|
|
|
ae23c9 |
Bugzilla: 1482537
|
|
|
ae23c9 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Issue EXTENDED COPY (LID1) command to implement the copy_range API.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
The parameter data construction code is modified from libiscsi's
|
|
|
ae23c9 |
iscsi-dd.c.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
ae23c9 |
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ae23c9 |
Message-id: 20180601092648.24614-9-famz@redhat.com
|
|
|
ae23c9 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ae23c9 |
(cherry picked from commit 604dfaaa3270081da689991afe83d94d3e8231df)
|
|
|
ae23c9 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
ae23c9 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
ae23c9 |
---
|
|
|
ae23c9 |
block/iscsi.c | 219 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
ae23c9 |
include/scsi/constants.h | 4 +
|
|
|
ae23c9 |
2 files changed, 223 insertions(+)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
diff --git a/block/iscsi.c b/block/iscsi.c
|
|
|
ae23c9 |
index 338f3dd..fbcd5bb 100644
|
|
|
ae23c9 |
--- a/block/iscsi.c
|
|
|
ae23c9 |
+++ b/block/iscsi.c
|
|
|
ae23c9 |
@@ -2187,6 +2187,221 @@ static void coroutine_fn iscsi_co_invalidate_cache(BlockDriverState *bs,
|
|
|
ae23c9 |
iscsi_allocmap_invalidate(iscsilun);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
+static int coroutine_fn iscsi_co_copy_range_from(BlockDriverState *bs,
|
|
|
ae23c9 |
+ BdrvChild *src,
|
|
|
ae23c9 |
+ uint64_t src_offset,
|
|
|
ae23c9 |
+ BdrvChild *dst,
|
|
|
ae23c9 |
+ uint64_t dst_offset,
|
|
|
ae23c9 |
+ uint64_t bytes,
|
|
|
ae23c9 |
+ BdrvRequestFlags flags)
|
|
|
ae23c9 |
+{
|
|
|
ae23c9 |
+ return bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, flags);
|
|
|
ae23c9 |
+}
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+static struct scsi_task *iscsi_xcopy_task(int param_len)
|
|
|
ae23c9 |
+{
|
|
|
ae23c9 |
+ struct scsi_task *task;
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ task = g_new0(struct scsi_task, 1);
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ task->cdb[0] = EXTENDED_COPY;
|
|
|
ae23c9 |
+ task->cdb[10] = (param_len >> 24) & 0xFF;
|
|
|
ae23c9 |
+ task->cdb[11] = (param_len >> 16) & 0xFF;
|
|
|
ae23c9 |
+ task->cdb[12] = (param_len >> 8) & 0xFF;
|
|
|
ae23c9 |
+ task->cdb[13] = param_len & 0xFF;
|
|
|
ae23c9 |
+ task->cdb_size = 16;
|
|
|
ae23c9 |
+ task->xfer_dir = SCSI_XFER_WRITE;
|
|
|
ae23c9 |
+ task->expxferlen = param_len;
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ return task;
|
|
|
ae23c9 |
+}
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+static void iscsi_populate_target_desc(unsigned char *desc, IscsiLun *lun)
|
|
|
ae23c9 |
+{
|
|
|
ae23c9 |
+ struct scsi_inquiry_device_designator *dd = lun->dd;
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ memset(desc, 0, 32);
|
|
|
ae23c9 |
+ desc[0] = 0xE4; /* IDENT_DESCR_TGT_DESCR */
|
|
|
ae23c9 |
+ desc[4] = dd->code_set;
|
|
|
ae23c9 |
+ desc[5] = (dd->designator_type & 0xF)
|
|
|
ae23c9 |
+ | ((dd->association & 3) << 4);
|
|
|
ae23c9 |
+ desc[7] = dd->designator_length;
|
|
|
ae23c9 |
+ memcpy(desc + 8, dd->designator, dd->designator_length);
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ desc[28] = 0;
|
|
|
ae23c9 |
+ desc[29] = (lun->block_size >> 16) & 0xFF;
|
|
|
ae23c9 |
+ desc[30] = (lun->block_size >> 8) & 0xFF;
|
|
|
ae23c9 |
+ desc[31] = lun->block_size & 0xFF;
|
|
|
ae23c9 |
+}
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+static void iscsi_xcopy_desc_hdr(uint8_t *hdr, int dc, int cat, int src_index,
|
|
|
ae23c9 |
+ int dst_index)
|
|
|
ae23c9 |
+{
|
|
|
ae23c9 |
+ hdr[0] = 0x02; /* BLK_TO_BLK_SEG_DESCR */
|
|
|
ae23c9 |
+ hdr[1] = ((dc << 1) | cat) & 0xFF;
|
|
|
ae23c9 |
+ hdr[2] = (XCOPY_BLK2BLK_SEG_DESC_SIZE >> 8) & 0xFF;
|
|
|
ae23c9 |
+ /* don't account for the first 4 bytes in descriptor header*/
|
|
|
ae23c9 |
+ hdr[3] = (XCOPY_BLK2BLK_SEG_DESC_SIZE - 4 /* SEG_DESC_SRC_INDEX_OFFSET */) & 0xFF;
|
|
|
ae23c9 |
+ hdr[4] = (src_index >> 8) & 0xFF;
|
|
|
ae23c9 |
+ hdr[5] = src_index & 0xFF;
|
|
|
ae23c9 |
+ hdr[6] = (dst_index >> 8) & 0xFF;
|
|
|
ae23c9 |
+ hdr[7] = dst_index & 0xFF;
|
|
|
ae23c9 |
+}
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+static void iscsi_xcopy_populate_desc(uint8_t *desc, int dc, int cat,
|
|
|
ae23c9 |
+ int src_index, int dst_index, int num_blks,
|
|
|
ae23c9 |
+ uint64_t src_lba, uint64_t dst_lba)
|
|
|
ae23c9 |
+{
|
|
|
ae23c9 |
+ iscsi_xcopy_desc_hdr(desc, dc, cat, src_index, dst_index);
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ /* The caller should verify the request size */
|
|
|
ae23c9 |
+ assert(num_blks < 65536);
|
|
|
ae23c9 |
+ desc[10] = (num_blks >> 8) & 0xFF;
|
|
|
ae23c9 |
+ desc[11] = num_blks & 0xFF;
|
|
|
ae23c9 |
+ desc[12] = (src_lba >> 56) & 0xFF;
|
|
|
ae23c9 |
+ desc[13] = (src_lba >> 48) & 0xFF;
|
|
|
ae23c9 |
+ desc[14] = (src_lba >> 40) & 0xFF;
|
|
|
ae23c9 |
+ desc[15] = (src_lba >> 32) & 0xFF;
|
|
|
ae23c9 |
+ desc[16] = (src_lba >> 24) & 0xFF;
|
|
|
ae23c9 |
+ desc[17] = (src_lba >> 16) & 0xFF;
|
|
|
ae23c9 |
+ desc[18] = (src_lba >> 8) & 0xFF;
|
|
|
ae23c9 |
+ desc[19] = src_lba & 0xFF;
|
|
|
ae23c9 |
+ desc[20] = (dst_lba >> 56) & 0xFF;
|
|
|
ae23c9 |
+ desc[21] = (dst_lba >> 48) & 0xFF;
|
|
|
ae23c9 |
+ desc[22] = (dst_lba >> 40) & 0xFF;
|
|
|
ae23c9 |
+ desc[23] = (dst_lba >> 32) & 0xFF;
|
|
|
ae23c9 |
+ desc[24] = (dst_lba >> 24) & 0xFF;
|
|
|
ae23c9 |
+ desc[25] = (dst_lba >> 16) & 0xFF;
|
|
|
ae23c9 |
+ desc[26] = (dst_lba >> 8) & 0xFF;
|
|
|
ae23c9 |
+ desc[27] = dst_lba & 0xFF;
|
|
|
ae23c9 |
+}
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+static void iscsi_xcopy_populate_header(unsigned char *buf, int list_id, int str,
|
|
|
ae23c9 |
+ int list_id_usage, int prio,
|
|
|
ae23c9 |
+ int tgt_desc_len,
|
|
|
ae23c9 |
+ int seg_desc_len, int inline_data_len)
|
|
|
ae23c9 |
+{
|
|
|
ae23c9 |
+ buf[0] = list_id;
|
|
|
ae23c9 |
+ buf[1] = ((str & 1) << 5) | ((list_id_usage & 3) << 3) | (prio & 7);
|
|
|
ae23c9 |
+ buf[2] = (tgt_desc_len >> 8) & 0xFF;
|
|
|
ae23c9 |
+ buf[3] = tgt_desc_len & 0xFF;
|
|
|
ae23c9 |
+ buf[8] = (seg_desc_len >> 24) & 0xFF;
|
|
|
ae23c9 |
+ buf[9] = (seg_desc_len >> 16) & 0xFF;
|
|
|
ae23c9 |
+ buf[10] = (seg_desc_len >> 8) & 0xFF;
|
|
|
ae23c9 |
+ buf[11] = seg_desc_len & 0xFF;
|
|
|
ae23c9 |
+ buf[12] = (inline_data_len >> 24) & 0xFF;
|
|
|
ae23c9 |
+ buf[13] = (inline_data_len >> 16) & 0xFF;
|
|
|
ae23c9 |
+ buf[14] = (inline_data_len >> 8) & 0xFF;
|
|
|
ae23c9 |
+ buf[15] = inline_data_len & 0xFF;
|
|
|
ae23c9 |
+}
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+static void iscsi_xcopy_data(struct iscsi_data *data,
|
|
|
ae23c9 |
+ IscsiLun *src, int64_t src_lba,
|
|
|
ae23c9 |
+ IscsiLun *dst, int64_t dst_lba,
|
|
|
ae23c9 |
+ uint16_t num_blocks)
|
|
|
ae23c9 |
+{
|
|
|
ae23c9 |
+ uint8_t *buf;
|
|
|
ae23c9 |
+ const int src_offset = XCOPY_DESC_OFFSET;
|
|
|
ae23c9 |
+ const int dst_offset = XCOPY_DESC_OFFSET + IDENT_DESCR_TGT_DESCR_SIZE;
|
|
|
ae23c9 |
+ const int seg_offset = dst_offset + IDENT_DESCR_TGT_DESCR_SIZE;
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ data->size = XCOPY_DESC_OFFSET +
|
|
|
ae23c9 |
+ IDENT_DESCR_TGT_DESCR_SIZE * 2 +
|
|
|
ae23c9 |
+ XCOPY_BLK2BLK_SEG_DESC_SIZE;
|
|
|
ae23c9 |
+ data->data = g_malloc0(data->size);
|
|
|
ae23c9 |
+ buf = data->data;
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ /* Initialise the parameter list header */
|
|
|
ae23c9 |
+ iscsi_xcopy_populate_header(buf, 1, 0, 2 /* LIST_ID_USAGE_DISCARD */,
|
|
|
ae23c9 |
+ 0, 2 * IDENT_DESCR_TGT_DESCR_SIZE,
|
|
|
ae23c9 |
+ XCOPY_BLK2BLK_SEG_DESC_SIZE,
|
|
|
ae23c9 |
+ 0);
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ /* Initialise CSCD list with one src + one dst descriptor */
|
|
|
ae23c9 |
+ iscsi_populate_target_desc(&buf[src_offset], src);
|
|
|
ae23c9 |
+ iscsi_populate_target_desc(&buf[dst_offset], dst);
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ /* Initialise one segment descriptor */
|
|
|
ae23c9 |
+ iscsi_xcopy_populate_desc(&buf[seg_offset], 0, 0, 0, 1, num_blocks,
|
|
|
ae23c9 |
+ src_lba, dst_lba);
|
|
|
ae23c9 |
+}
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+static int coroutine_fn iscsi_co_copy_range_to(BlockDriverState *bs,
|
|
|
ae23c9 |
+ BdrvChild *src,
|
|
|
ae23c9 |
+ uint64_t src_offset,
|
|
|
ae23c9 |
+ BdrvChild *dst,
|
|
|
ae23c9 |
+ uint64_t dst_offset,
|
|
|
ae23c9 |
+ uint64_t bytes,
|
|
|
ae23c9 |
+ BdrvRequestFlags flags)
|
|
|
ae23c9 |
+{
|
|
|
ae23c9 |
+ IscsiLun *dst_lun = dst->bs->opaque;
|
|
|
ae23c9 |
+ IscsiLun *src_lun;
|
|
|
ae23c9 |
+ struct IscsiTask iscsi_task;
|
|
|
ae23c9 |
+ struct iscsi_data data;
|
|
|
ae23c9 |
+ int r = 0;
|
|
|
ae23c9 |
+ int block_size;
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ if (src->bs->drv->bdrv_co_copy_range_to != iscsi_co_copy_range_to) {
|
|
|
ae23c9 |
+ return -ENOTSUP;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+ src_lun = src->bs->opaque;
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ if (!src_lun->dd || !dst_lun->dd) {
|
|
|
ae23c9 |
+ return -ENOTSUP;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+ if (!is_byte_request_lun_aligned(dst_offset, bytes, dst_lun)) {
|
|
|
ae23c9 |
+ return -ENOTSUP;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+ if (!is_byte_request_lun_aligned(src_offset, bytes, src_lun)) {
|
|
|
ae23c9 |
+ return -ENOTSUP;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+ if (dst_lun->block_size != src_lun->block_size ||
|
|
|
ae23c9 |
+ !dst_lun->block_size) {
|
|
|
ae23c9 |
+ return -ENOTSUP;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ block_size = dst_lun->block_size;
|
|
|
ae23c9 |
+ if (bytes / block_size > 65535) {
|
|
|
ae23c9 |
+ return -ENOTSUP;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ iscsi_xcopy_data(&data,
|
|
|
ae23c9 |
+ src_lun, src_offset / block_size,
|
|
|
ae23c9 |
+ dst_lun, dst_offset / block_size,
|
|
|
ae23c9 |
+ bytes / block_size);
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ iscsi_co_init_iscsitask(dst_lun, &iscsi_task);
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ qemu_mutex_lock(&dst_lun->mutex);
|
|
|
ae23c9 |
+ iscsi_task.task = iscsi_xcopy_task(data.size);
|
|
|
ae23c9 |
+retry:
|
|
|
ae23c9 |
+ if (iscsi_scsi_command_async(dst_lun->iscsi, dst_lun->lun,
|
|
|
ae23c9 |
+ iscsi_task.task, iscsi_co_generic_cb,
|
|
|
ae23c9 |
+ &data,
|
|
|
ae23c9 |
+ &iscsi_task) != 0) {
|
|
|
ae23c9 |
+ r = -EIO;
|
|
|
ae23c9 |
+ goto out_unlock;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ iscsi_co_wait_for_task(&iscsi_task, dst_lun);
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ if (iscsi_task.do_retry) {
|
|
|
ae23c9 |
+ iscsi_task.complete = 0;
|
|
|
ae23c9 |
+ goto retry;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+ if (iscsi_task.status != SCSI_STATUS_GOOD) {
|
|
|
ae23c9 |
+ r = iscsi_task.err_code;
|
|
|
ae23c9 |
+ goto out_unlock;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+out_unlock:
|
|
|
ae23c9 |
+ g_free(iscsi_task.task);
|
|
|
ae23c9 |
+ qemu_mutex_unlock(&dst_lun->mutex);
|
|
|
ae23c9 |
+ g_free(iscsi_task.err_str);
|
|
|
ae23c9 |
+ return r;
|
|
|
ae23c9 |
+}
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
static QemuOptsList iscsi_create_opts = {
|
|
|
ae23c9 |
.name = "iscsi-create-opts",
|
|
|
ae23c9 |
.head = QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head),
|
|
|
ae23c9 |
@@ -2221,6 +2436,8 @@ static BlockDriver bdrv_iscsi = {
|
|
|
ae23c9 |
|
|
|
ae23c9 |
.bdrv_co_block_status = iscsi_co_block_status,
|
|
|
ae23c9 |
.bdrv_co_pdiscard = iscsi_co_pdiscard,
|
|
|
ae23c9 |
+ .bdrv_co_copy_range_from = iscsi_co_copy_range_from,
|
|
|
ae23c9 |
+ .bdrv_co_copy_range_to = iscsi_co_copy_range_to,
|
|
|
ae23c9 |
.bdrv_co_pwrite_zeroes = iscsi_co_pwrite_zeroes,
|
|
|
ae23c9 |
.bdrv_co_readv = iscsi_co_readv,
|
|
|
ae23c9 |
.bdrv_co_writev_flags = iscsi_co_writev_flags,
|
|
|
ae23c9 |
@@ -2256,6 +2473,8 @@ static BlockDriver bdrv_iser = {
|
|
|
ae23c9 |
|
|
|
ae23c9 |
.bdrv_co_block_status = iscsi_co_block_status,
|
|
|
ae23c9 |
.bdrv_co_pdiscard = iscsi_co_pdiscard,
|
|
|
ae23c9 |
+ .bdrv_co_copy_range_from = iscsi_co_copy_range_from,
|
|
|
ae23c9 |
+ .bdrv_co_copy_range_to = iscsi_co_copy_range_to,
|
|
|
ae23c9 |
.bdrv_co_pwrite_zeroes = iscsi_co_pwrite_zeroes,
|
|
|
ae23c9 |
.bdrv_co_readv = iscsi_co_readv,
|
|
|
ae23c9 |
.bdrv_co_writev_flags = iscsi_co_writev_flags,
|
|
|
ae23c9 |
diff --git a/include/scsi/constants.h b/include/scsi/constants.h
|
|
|
ae23c9 |
index a141dd7..083a8e8 100644
|
|
|
ae23c9 |
--- a/include/scsi/constants.h
|
|
|
ae23c9 |
+++ b/include/scsi/constants.h
|
|
|
ae23c9 |
@@ -311,4 +311,8 @@
|
|
|
ae23c9 |
#define MMC_PROFILE_HDDVD_RW_DL 0x005A
|
|
|
ae23c9 |
#define MMC_PROFILE_INVALID 0xFFFF
|
|
|
ae23c9 |
|
|
|
ae23c9 |
+#define XCOPY_DESC_OFFSET 16
|
|
|
ae23c9 |
+#define IDENT_DESCR_TGT_DESCR_SIZE 32
|
|
|
ae23c9 |
+#define XCOPY_BLK2BLK_SEG_DESC_SIZE 28
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
#endif
|
|
|
ae23c9 |
--
|
|
|
ae23c9 |
1.8.3.1
|
|
|
ae23c9 |
|