]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: hot-plug: Fix broken SCSI disk hot-plug
authorMarc Hartmayer <mhartmay@linux.vnet.ibm.com>
Mon, 27 Jun 2016 14:43:46 +0000 (16:43 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 30 Jun 2016 11:36:50 +0000 (13:36 +0200)
The commit "qemu: hot-plug: Assume support for -device in
qemuDomainAttachSCSIDisk" dropped the code for the automatic SCSI
controller creation used in SCSI disk hot-plugging. If we are
hot-plugging a SCSI disk to a domain and there is no proper SCSI
controller defined, it results in an "error: internal error: Could not
find scsi controller with index X required for device" error.

For that reason reverting a hunk of the commit
d4d32005d6e8b2cc0a2f26b483ca1de10171db6d.

This patch also adds an extra comment to the code to clarify the
loop.

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 58d07db9b0c294e92e294cadd737eee8597bf747)

src/qemu/qemu_hotplug.c

index 66f1eda1ab9cb6413798809bea59f08efdfb1dd0..accfc77ced583bbb2adc364f824d966dcb0048f1 100644 (file)
@@ -547,6 +547,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
                          virDomainObjPtr vm,
                          virDomainDiskDefPtr disk)
 {
+    size_t i;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     char *drivestr = NULL;
     char *devstr = NULL;
@@ -564,6 +565,18 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
         goto error;
     }
 
+    /* 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 <= disk->info.addr.drive.controller; i++) {
+        if (!qemuDomainFindOrCreateSCSIDiskController(driver, vm, i))
+            goto error;
+    }
+
     if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
         goto error;