thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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