]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Use same model when adding hostdev SCSI controller
authorJohn Ferlan <jferlan@redhat.com>
Mon, 4 Dec 2017 19:33:30 +0000 (14:33 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 4 Jan 2018 15:30:43 +0000 (10:30 -0500)
When qemuDomainFindOrCreateSCSIDiskController adds a controller,
let's use the same model as a currently found controller under the
assumption that the reason to add the controller in hotplug is
because virDomainHostdevAssignAddress determined that there were
too many devices on the existing controller, but only assigned a
new controller index and did not add a new controller and we
desire to use the same controller model as any existing controller
and not take a chance that qemuDomainSetSCSIControllerModel would
use a default that may be incompatible.

src/qemu/qemu_hotplug.c

index b7980730015382f3eed7ef7a8de1b626971d9145..385be80f2f4cddb2fe29ab5d69e7405a312b53ce 100644 (file)
@@ -587,6 +587,7 @@ qemuDomainFindOrCreateSCSIDiskController(virQEMUDriverPtr driver,
 {
     size_t i;
     virDomainControllerDefPtr cont;
+    int model = -1;
 
     for (i = 0; i < vm->def->ncontrollers; i++) {
         cont = vm->def->controllers[i];
@@ -596,6 +597,16 @@ qemuDomainFindOrCreateSCSIDiskController(virQEMUDriverPtr driver,
 
         if (cont->idx == controller)
             return cont;
+
+        /* Because virDomainHostdevAssignAddress called during
+         * virDomainHostdevDefPostParse cannot add a new controller
+         * it will assign a controller index to a controller that doesn't
+         * exist leaving this code to perform the magic of adding the
+         * controller. Because that code would be attempting to add a
+         * SCSI disk to an existing controller, let's save the model
+         * of the "last" SCSI controller we find so that if we end up
+         * creating a controller below it uses the same controller model. */
+        model = cont->model;
     }
 
     /* No SCSI controller present, for backward compatibility we
@@ -604,11 +615,11 @@ qemuDomainFindOrCreateSCSIDiskController(virQEMUDriverPtr driver,
         return NULL;
     cont->type = VIR_DOMAIN_CONTROLLER_TYPE_SCSI;
     cont->idx = controller;
-    cont->model = -1;
+    cont->model = model;
 
-    VIR_INFO("No SCSI controller present, hotplugging one");
-    if (qemuDomainAttachControllerDevice(driver,
-                                         vm, cont) < 0) {
+    VIR_INFO("No SCSI controller present, hotplugging one model=%s",
+             virDomainControllerModelSCSITypeToString(model));
+    if (qemuDomainAttachControllerDevice(driver, vm, cont) < 0) {
         VIR_FREE(cont);
         return NULL;
     }