e00e43
From 99a886eeddb5d208871d149e720b13365cc6d261 Mon Sep 17 00:00:00 2001
e00e43
Message-Id: <99a886eeddb5d208871d149e720b13365cc6d261@dist-git>
e00e43
From: Michal Privoznik <mprivozn@redhat.com>
e00e43
Date: Mon, 28 Oct 2019 14:02:23 +0100
e00e43
Subject: [PATCH] domain_conf: Relax SCSI addr used check
e00e43
MIME-Version: 1.0
e00e43
Content-Type: text/plain; charset=UTF-8
e00e43
Content-Transfer-Encoding: 8bit
e00e43
e00e43
In domain_conf.c we have virDomainSCSIDriveAddressIsUsed()
e00e43
function which returns true or false if given drive address is
e00e43
already in use for given domain config or not. However, it also
e00e43
takes a shortcut and returns true (meaning address in use) if the
e00e43
unit number equals 7. This is because for some controllers this
e00e43
is reserved address. The limitation comes mostly from vmware and
e00e43
applies to lsilogic, buslogic, spapr-vscsi and vmpvscsi models.
e00e43
On the other hand, we were not checking for the maximum unit
e00e43
number (aka LUN number) which is also relevant and differs from
e00e43
model to model.
e00e43
e00e43
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
e00e43
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
e00e43
(cherry picked from commit c8007fdc5d2ce43fec2753cda60fb4963f55abd5)
e00e43
e00e43
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1766086
e00e43
e00e43
I had to drop
e00e43
VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_TRANSITIONAL and
e00e43
VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_NON_TRANSITIONAL from
e00e43
virDomainSCSIDriveAddressIsUsed() because those don't exist in
e00e43
RHEL-7.7 branch.
e00e43
e00e43
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
e00e43
Message-Id: <1408596266780329bf02f2537aeb4eae3aa589cf.1572267657.git.mprivozn@redhat.com>
e00e43
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
e00e43
---
e00e43
 src/conf/domain_conf.c | 49 +++++++++++++++++++++++++++++++++++++-----
e00e43
 1 file changed, 44 insertions(+), 5 deletions(-)
e00e43
e00e43
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
e00e43
index 3bc603b48c..f0e948d80a 100644
e00e43
--- a/src/conf/domain_conf.c
e00e43
+++ b/src/conf/domain_conf.c
e00e43
@@ -4407,11 +4407,50 @@ bool
e00e43
 virDomainSCSIDriveAddressIsUsed(const virDomainDef *def,
e00e43
                                 const virDomainDeviceDriveAddress *addr)
e00e43
 {
e00e43
-    /* In current implementation, the maximum unit number of a controller
e00e43
-     * is either 16 or 7 (narrow SCSI bus), and if the maximum unit number
e00e43
-     * is 16, the controller itself is on unit 7 */
e00e43
-    if (addr->unit == 7)
e00e43
-        return true;
e00e43
+    const virDomainControllerDef *cont;
e00e43
+
e00e43
+    cont = virDomainDeviceFindSCSIController(def, addr);
e00e43
+    if (cont) {
e00e43
+        int max = -1;
e00e43
+        int reserved = -1;
e00e43
+
e00e43
+        /* Different controllers have different limits. These limits here are
e00e43
+         * taken from QEMU source code, but nevertheless they should apply to
e00e43
+         * other hypervisors too. */
e00e43
+        switch ((virDomainControllerModelSCSI) cont->model) {
e00e43
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI:
e00e43
+            max = 16383;
e00e43
+            break;
e00e43
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_IBMVSCSI:
e00e43
+            max = 31;
e00e43
+            reserved = 7;
e00e43
+            break;
e00e43
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSISAS1068:
e00e43
+            max = 1;
e00e43
+            break;
e00e43
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSISAS1078:
e00e43
+            max = 255;
e00e43
+            break;
e00e43
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC:
e00e43
+            reserved = 7;
e00e43
+            break;
e00e43
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VMPVSCSI:
e00e43
+            reserved = 7;
e00e43
+            break;
e00e43
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_BUSLOGIC:
e00e43
+            reserved = 7;
e00e43
+            break;
e00e43
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_DEFAULT:
e00e43
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_AUTO:
e00e43
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LAST:
e00e43
+            break;
e00e43
+        }
e00e43
+
e00e43
+        if (max != -1 && addr->unit >= max)
e00e43
+            return true;
e00e43
+        if (reserved != -1 && addr->unit == reserved)
e00e43
+            return true;
e00e43
+    }
e00e43
 
e00e43
     if (virDomainDriveAddressIsUsedByDisk(def, VIR_DOMAIN_DISK_BUS_SCSI,
e00e43
                                           addr) ||
e00e43
-- 
e00e43
2.23.0
e00e43