Blame SOURCES/kvm-iscsi-Query-and-save-device-designator-when-opening.patch

1bdc94
From 20dcbb9776926fea51e6178298ed76f2c64a1d03 Mon Sep 17 00:00:00 2001
1bdc94
From: Fam Zheng <famz@redhat.com>
1bdc94
Date: Fri, 29 Jun 2018 06:11:46 +0200
1bdc94
Subject: [PATCH 42/57] iscsi: Query and save device designator when opening
1bdc94
1bdc94
RH-Author: Fam Zheng <famz@redhat.com>
1bdc94
Message-id: <20180629061153.12687-7-famz@redhat.com>
1bdc94
Patchwork-id: 81157
1bdc94
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH v2 06/13] iscsi: Query and save device designator when opening
1bdc94
Bugzilla: 1482537
1bdc94
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
RH-Acked-by: Max Reitz <mreitz@redhat.com>
1bdc94
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
1bdc94
The device designator data returned in INQUIRY command will be useful to
1bdc94
fill in source/target fields during copy offloading. Do this when
1bdc94
connecting to the target and save the data for later use.
1bdc94
1bdc94
Signed-off-by: Fam Zheng <famz@redhat.com>
1bdc94
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
Message-id: 20180601092648.24614-7-famz@redhat.com
1bdc94
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
(cherry picked from commit cc9743c236cce8a35449e3ef67140287b68bb705)
1bdc94
Signed-off-by: Fam Zheng <famz@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 block/iscsi.c | 41 +++++++++++++++++++++++++++++++++++++++++
1bdc94
 1 file changed, 41 insertions(+)
1bdc94
1bdc94
diff --git a/block/iscsi.c b/block/iscsi.c
1bdc94
index 1705187..a1a0044 100644
1bdc94
--- a/block/iscsi.c
1bdc94
+++ b/block/iscsi.c
1bdc94
@@ -69,6 +69,7 @@ typedef struct IscsiLun {
1bdc94
     QemuMutex mutex;
1bdc94
     struct scsi_inquiry_logical_block_provisioning lbp;
1bdc94
     struct scsi_inquiry_block_limits bl;
1bdc94
+    struct scsi_inquiry_device_designator *dd;
1bdc94
     unsigned char *zeroblock;
1bdc94
     /* The allocmap tracks which clusters (pages) on the iSCSI target are
1bdc94
      * allocated and which are not. In case a target returns zeros for
1bdc94
@@ -1737,6 +1738,30 @@ static QemuOptsList runtime_opts = {
1bdc94
     },
1bdc94
 };
1bdc94
 
1bdc94
+static void iscsi_save_designator(IscsiLun *lun,
1bdc94
+                                  struct scsi_inquiry_device_identification *inq_di)
1bdc94
+{
1bdc94
+    struct scsi_inquiry_device_designator *desig, *copy = NULL;
1bdc94
+
1bdc94
+    for (desig = inq_di->designators; desig; desig = desig->next) {
1bdc94
+        if (desig->association ||
1bdc94
+            desig->designator_type > SCSI_DESIGNATOR_TYPE_NAA) {
1bdc94
+            continue;
1bdc94
+        }
1bdc94
+        /* NAA works better than T10 vendor ID based designator. */
1bdc94
+        if (!copy || copy->designator_type < desig->designator_type) {
1bdc94
+            copy = desig;
1bdc94
+        }
1bdc94
+    }
1bdc94
+    if (copy) {
1bdc94
+        lun->dd = g_new(struct scsi_inquiry_device_designator, 1);
1bdc94
+        *lun->dd = *copy;
1bdc94
+        lun->dd->next = NULL;
1bdc94
+        lun->dd->designator = g_malloc(copy->designator_length);
1bdc94
+        memcpy(lun->dd->designator, copy->designator, copy->designator_length);
1bdc94
+    }
1bdc94
+}
1bdc94
+
1bdc94
 static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
1bdc94
                       Error **errp)
1bdc94
 {
1bdc94
@@ -1904,6 +1929,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
1bdc94
         struct scsi_task *inq_task;
1bdc94
         struct scsi_inquiry_logical_block_provisioning *inq_lbp;
1bdc94
         struct scsi_inquiry_block_limits *inq_bl;
1bdc94
+        struct scsi_inquiry_device_identification *inq_di;
1bdc94
         switch (inq_vpd->pages[i]) {
1bdc94
         case SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING:
1bdc94
             inq_task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
1bdc94
@@ -1929,6 +1955,17 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
1bdc94
                    sizeof(struct scsi_inquiry_block_limits));
1bdc94
             scsi_free_scsi_task(inq_task);
1bdc94
             break;
1bdc94
+        case SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION:
1bdc94
+            inq_task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
1bdc94
+                                    SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION,
1bdc94
+                                    (void **) &inq_di, errp);
1bdc94
+            if (inq_task == NULL) {
1bdc94
+                ret = -EINVAL;
1bdc94
+                goto out;
1bdc94
+            }
1bdc94
+            iscsi_save_designator(iscsilun, inq_di);
1bdc94
+            scsi_free_scsi_task(inq_task);
1bdc94
+            break;
1bdc94
         default:
1bdc94
             break;
1bdc94
         }
1bdc94
@@ -1985,6 +2022,10 @@ static void iscsi_close(BlockDriverState *bs)
1bdc94
         iscsi_logout_sync(iscsi);
1bdc94
     }
1bdc94
     iscsi_destroy_context(iscsi);
1bdc94
+    if (iscsilun->dd) {
1bdc94
+        g_free(iscsilun->dd->designator);
1bdc94
+        g_free(iscsilun->dd);
1bdc94
+    }
1bdc94
     g_free(iscsilun->zeroblock);
1bdc94
     iscsi_allocmap_free(iscsilun);
1bdc94
     qemu_mutex_destroy(&iscsilun->mutex);
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94