qemu: Use same model when adding hostdev SCSI controller

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.
This commit is contained in:
John Ferlan 2017-12-04 14:33:30 -05:00
parent fae22fced4
commit 07beea6ca2

View 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;
}