[libvirt] [PATCH 0/3] qemu: Hotplug SCSI controllers/hostdevs

Today, hotplug of a SCSI hostdev relies on the presence of an existing SCSI controller, which can be defined in the initial domain XML. Hotplug of a SCSI controller relies on the presence of a PCI bus, which does not work in all environments. These patches correct this behavior, in order to allow hotplug (and unplug) work without incident. Reviewed-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com> Eric Farman (3): qemu: Rename controller hotplug functions to not be PCI-specific qemu: Separate calls based on controller bus type qemu: Auto-generate controller for hotplugged hostdev src/qemu/qemu_driver.c | 4 +-- src/qemu/qemu_hotplug.c | 62 ++++++++++++++++++++++++++++++++--------------- src/qemu/qemu_hotplug.h | 12 ++++----- 3 files changed, 50 insertions(+), 28 deletions(-) -- 1.7.9.5

For attach/detach of controller devices, we rename the functions to remove 'PCI' from their title. The actual separation of PCI-specific operations will be handled in the next patch. Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com> --- src/qemu/qemu_driver.c | 4 ++-- src/qemu/qemu_hotplug.c | 12 ++++++------ src/qemu/qemu_hotplug.h | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 346a8f9..4239fba 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6299,7 +6299,7 @@ qemuDomainAttachDeviceControllerLive(virQEMUDriverPtr driver, switch (cont->type) { case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: - ret = qemuDomainAttachPciControllerDevice(driver, vm, cont); + ret = qemuDomainAttachControllerDevice(driver, vm, cont); break; default: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, @@ -6391,7 +6391,7 @@ qemuDomainDetachDeviceControllerLive(virQEMUDriverPtr driver, switch (cont->type) { case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: - ret = qemuDomainDetachPciControllerDevice(driver, vm, dev); + ret = qemuDomainDetachControllerDevice(driver, vm, dev); break; default : virReportError(VIR_ERR_OPERATION_UNSUPPORTED, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 6cdee44..cb62101 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -348,9 +348,9 @@ error: } -int qemuDomainAttachPciControllerDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainControllerDefPtr controller) +int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainControllerDefPtr controller) { int ret = -1; const char* type = virDomainControllerTypeToString(controller->type); @@ -438,8 +438,8 @@ qemuDomainFindOrCreateSCSIDiskController(virQEMUDriverPtr driver, cont->model = -1; VIR_INFO("No SCSI controller present, hotplugging one"); - if (qemuDomainAttachPciControllerDevice(driver, - vm, cont) < 0) { + if (qemuDomainAttachControllerDevice(driver, + vm, cont) < 0) { VIR_FREE(cont); return NULL; } @@ -2989,7 +2989,7 @@ static bool qemuDomainControllerIsBusy(virDomainObjPtr vm, } } -int qemuDomainDetachPciControllerDevice(virQEMUDriverPtr driver, +int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev) { diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 355d809..75789d6 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -36,9 +36,9 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, int qemuDomainCheckEjectableMedia(virQEMUDriverPtr driver, virDomainObjPtr vm, enum qemuDomainAsyncJob asyncJob); -int qemuDomainAttachPciControllerDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainControllerDefPtr controller); +int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainControllerDefPtr controller); int qemuDomainAttachDeviceDiskLive(virConnectPtr conn, virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -78,9 +78,9 @@ int qemuDomainChangeNetLinkState(virQEMUDriverPtr driver, int qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev); -int qemuDomainDetachPciControllerDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev); +int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDeviceDefPtr dev); int qemuDomainDetachNetDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev); -- 1.7.9.5

For systems without a PCI bus, attaching a SCSI controller fails: [root@xxxxxxxx ~]# cat controller.xml <controller type='scsi' model='virtio-scsi' index='0' /> [root@xxxxxxxx ~]# virsh attach-device guest01 controller.xml error: Failed to attach device from controller.xml error: XML error: No PCI buses available A similar problem occurs with the detach of a controller: [root@xxxxxxxx ~]# virsh detach-device guest01 controller.xml error: Failed to detach device from controller.xml error: operation failed: controller scsi:0 not found The qemuDomainXXtachPciControllerDevice routines made assumptions that any caller had a PCI bus. These routines now selectively calls PCI functions where necessary, and assigns the device information type to one appropriate for the bus in use. Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com> --- src/qemu/qemu_hotplug.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index cb62101..779e1d9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -365,9 +365,23 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, return -1; } + if (!controller->info.type) { + if (STREQLEN(vm->def->os.machine, "s390-ccw", 8) && + virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW)) + controller->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW; + else if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_S390)) + controller->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390; + } + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { - if (qemuDomainPCIAddressEnsureAddr(priv->pciaddrs, &controller->info) < 0) - goto cleanup; + if (!controller->info.type || + controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { + if (qemuDomainPCIAddressEnsureAddr(priv->pciaddrs, &controller->info) < 0) + goto cleanup; + } else if (controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) { + if (qemuDomainCCWAddressAssign(&controller->info, priv->ccwaddrs, true) < 0) + goto cleanup; + } releaseaddr = true; if (qemuAssignDeviceControllerAlias(controller) < 0) goto cleanup; @@ -399,7 +413,8 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, qemuDomainObjExitMonitor(driver, vm); if (ret == 0) { - controller->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; + if (!controller->info.type) + controller->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; virDomainControllerInsertPreAlloced(vm->def, controller); } @@ -3009,18 +3024,20 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver, detach = vm->def->controllers[idx]; - if (!virDomainDeviceAddressIsValid(&detach->info, - VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("device cannot be detached without a PCI address")); - goto cleanup; - } + if (detach->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { + if (!virDomainDeviceAddressIsValid(&detach->info, + VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("device cannot be detached without a PCI address")); + goto cleanup; + } - if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("cannot hot unplug multifunction PCI device: %s"), - dev->data.disk->dst); - goto cleanup; + if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("cannot hot unplug multifunction PCI device: %s"), + dev->data.disk->dst); + goto cleanup; + } } if (qemuDomainControllerIsBusy(vm, detach)) { -- 1.7.9.5

If a SCSI hostdev is included in an initial domain XML, without a corresponding controller statement, one is created silently when the guest is booted. When hotplugging a SCSI hostdev, a presumption is that the controller is already present in the domain either from the original XML, or via an earlier hotplug. [root@xxxxxxxx ~]# cat disk.xml <hostdev mode='subsystem' type='scsi'> <source> <adapter name='scsi_host0'/> <address bus='0' target='3' unit='1088438288'/> </source> </hostdev> [root@xxxxxxxx ~]# virsh attach-device guest01 disk.xml error: Failed to attach device from disk.xml error: internal error: unable to execute QEMU command 'device_add': Bus 'scsi0.0' not found Since the infrastructure is in place, we can also create a controller silently for use by the hotplugged hostdev device. Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com> --- src/qemu/qemu_hotplug.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 779e1d9..ad80d94 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1485,6 +1485,7 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver, { int ret = -1; qemuDomainObjPrivatePtr priv = vm->privateData; + virDomainControllerDefPtr cont = NULL; char *devstr = NULL; char *drvstr = NULL; @@ -1496,6 +1497,10 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver, return -1; } + cont = qemuDomainFindOrCreateSCSIDiskController(driver, vm, hostdev->info->addr.drive.controller); + if (!cont) + return -1; + if (qemuPrepareHostdevSCSIDevices(driver, vm->def->name, &hostdev, 1)) { virReportError(VIR_ERR_INTERNAL_ERROR, -- 1.7.9.5
participants (1)
-
Eric Farman