render / rpms / libvirt

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