]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: SCSI hostdev hot-plug: Fix automatic creation of SCSI controllers
authorMarc Hartmayer <mhartmay@linux.vnet.ibm.com>
Mon, 27 Jun 2016 14:43:47 +0000 (16:43 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 30 Jun 2016 11:36:55 +0000 (13:36 +0200)
Ensure that the given controller and all controllers with a smaller
index exist; there must not be any missing index in between.

Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
(cherry picked from commit 12ec22b68befce0ae8020635e7fd71d783b1d716)

 Conflicts:
src/qemu/qemu_hotplug.c: - context of the first hunk changed

src/qemu/qemu_hotplug.c

index accfc77ced583bbb2adc364f824d966dcb0048f1..0ee98b35326c08a1377c814461a6a4c67183d6f0 100644 (file)
@@ -1918,9 +1918,9 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
                                virDomainObjPtr vm,
                                virDomainHostdevDefPtr hostdev)
 {
+    size_t i;
     int ret = -1;
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    virDomainControllerDefPtr cont = NULL;
     char *devstr = NULL;
     char *drvstr = NULL;
     bool teardowncgroup = false;
@@ -1933,9 +1933,17 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
         return -1;
     }
 
-    cont = qemuDomainFindOrCreateSCSIDiskController(driver, vm, hostdev->info->addr.drive.controller);
-    if (!cont)
-        return -1;
+    /* Let's make sure the disk has a controller defined and loaded before
+     * trying to add it. The controller used by the disk must exist before a
+     * qemu command line string is generated.
+     *
+     * Ensure that the given controller and all controllers with a smaller index
+     * exist; there must not be any missing index in between.
+     */
+    for (i = 0; i <= hostdev->info->addr.drive.controller; i++) {
+        if (!qemuDomainFindOrCreateSCSIDiskController(driver, vm, i))
+            return -1;
+    }
 
     if (qemuHostdevPrepareSCSIDevices(driver, vm->def->name,
                                       &hostdev, 1)) {