On Thu, Mar 21, 2019 at 06:28:45PM -0400, Laine Stump wrote:
There are separate Detach functions for PCI, USB, SCSI, Vhost, and
Mediated hostdevs, but the functions are all 100% the same code,
except that the PCI function checks for the guest side of the device
being a PCI Multifunction device, while the other 4 check that the
device's alias != NULL.
The check for multifunction PCI devices should be done for *all*
devices that are connected to the PCI bus in the guest, not just PCI
hostdevs, and qemuIsMultiFunctionDevice() conveniently returns false
if the queried device doesn't connect with PCI, so it is safe to make
this check for all hostdev devices. (It also needs to be done for many
other device types, but that will be addressed in a future patch).
Likewise, since all hostdevs are detached by calling
qemuDomainDeleteDevice(), which requires the device's alias, checking
for a valid alias is a reasonable thing for PCI hostdevs too (NB:
you'd think that we could rely on every device having a valid alias,
but unfortunately when you run virsh qemu-attach on a qemu process
that was started with some "old style" device args, they don't include
an "id" option on the commandline, so there is no alias in the device
object that's created).
Wrong.
As of
commit e3a52afcfcc3478b553dca38140394fd93f90a2c
qemu-attach: Assign device aliases
that is not true.
Although other than not crashing later, I'm not sure what the point of making
up aliases that don't match reality is.
Or what the point of qemu-attach is anymore - it does not seem to parse
-device arguments, nor is it able to get us a JSON monitor, so we would
not be able to detach the device anyway.
Signed-off-by: Laine Stump <laine(a)laine.org>
---
src/qemu/qemu_hotplug.c | 129 +++++++++-------------------------------
1 file changed, 28 insertions(+), 101 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 701458b2cd..389d16b090 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -5499,124 +5499,42 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver,
return ret;
}
-static int
-qemuDomainDetachHostPCIDevice(virDomainObjPtr vm,
- virDomainHostdevDefPtr detach,
- bool async)
-{
- virDomainHostdevSubsysPCIPtr pcisrc = &detach->source.subsys.u.pci;
-
- if (qemuIsMultiFunctionDevice(vm->def, detach->info)) {
- virReportError(VIR_ERR_OPERATION_FAILED,
- _("cannot hot unplug multifunction PCI device:
%.4x:%.2x:%.2x.%.1x"),
- pcisrc->addr.domain, pcisrc->addr.bus,
- pcisrc->addr.slot, pcisrc->addr.function);
- return -1;
- }
-
- if (!async)
- qemuDomainMarkDeviceForRemoval(vm, detach->info);
-
- return qemuDomainDeleteDevice(vm, detach->info->alias);
-}
static int
-qemuDomainDetachHostUSBDevice(virDomainObjPtr vm,
- virDomainHostdevDefPtr detach,
- bool async)
-{
- if (!detach->info->alias) {
- virReportError(VIR_ERR_OPERATION_FAILED,
- "%s", _("device cannot be detached without a device
alias"));
- return -1;
- }
-
- if (!async)
- qemuDomainMarkDeviceForRemoval(vm, detach->info);
-
- return qemuDomainDeleteDevice(vm, detach->info->alias);
-}
-
-static int
-qemuDomainDetachHostSCSIDevice(virDomainObjPtr vm,
+qemuDomainDetachThisHostDevice(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
virDomainHostdevDefPtr detach,
bool async)
{
- if (!detach->info->alias) {
- virReportError(VIR_ERR_OPERATION_FAILED,
- "%s", _("device cannot be detached without a device
alias"));
- return -1;
- }
-
- if (!async)
- qemuDomainMarkDeviceForRemoval(vm, detach->info);
+ int ret = -1;
- return qemuDomainDeleteDevice(vm, detach->info->alias);
-}
+ if (qemuAssignDeviceHostdevAlias(vm->def, &detach->info->alias, -1) <
0)
+ return -1;
Here you leave in the bogus alias assignment introduced by
9de26f27cfa6a32ce9a23e30a58991432bdcbee5
hotplug: Check for alias in hostdev detach
-static int
-qemuDomainDetachSCSIVHostDevice(virDomainObjPtr vm,
- virDomainHostdevDefPtr detach,
- bool async)
-{
- if (!detach->info->alias) {
+ if (qemuIsMultiFunctionDevice(vm->def, detach->info)) {
virReportError(VIR_ERR_OPERATION_FAILED,
- "%s", _("device cannot be detached without a device
alias"));
+ _("cannot hot unplug multifunction PCI device with guest
address: "
+ "%.4x:%.2x:%.2x.%.1x"),
+ detach->info->addr.pci.domain,
detach->info->addr.pci.bus,
+ detach->info->addr.pci.slot,
detach->info->addr.pci.function);
return -1;
}
- if (!async)
- qemuDomainMarkDeviceForRemoval(vm, detach->info);
-
- return qemuDomainDeleteDevice(vm, detach->info->alias);
-}
-
-
-static int
-qemuDomainDetachMediatedDevice(virDomainObjPtr vm,
- virDomainHostdevDefPtr detach,
- bool async)
-{
if (!detach->info->alias) {
- virReportError(VIR_ERR_OPERATION_FAILED, "%s",
- _("device cannot be detached without a device alias"));
+ virReportError(VIR_ERR_OPERATION_FAILED,
+ "%s", _("device cannot be detached without a device
alias"));
return -1;
}
which makes this check pointless.
- if (!async)
- qemuDomainMarkDeviceForRemoval(vm, detach->info);
-
- return qemuDomainDeleteDevice(vm, detach->info->alias);
-}
-
-
-static int
-qemuDomainDetachThisHostDevice(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainHostdevDefPtr detach,
- bool async)
-{
- int ret = -1;
-
- if (qemuAssignDeviceHostdevAlias(vm->def, &detach->info->alias, -1) <
0)
- return -1;
-
switch (detach->source.subsys.type) {
Unrelated to this patch, but it seems this could benefit from a typecast
and an EnumError.
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
- ret = qemuDomainDetachHostPCIDevice(vm, detach, async);
- break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
- ret = qemuDomainDetachHostUSBDevice(vm, detach, async);
- break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
- ret = qemuDomainDetachHostSCSIDevice(vm, detach, async);
- break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
- ret = qemuDomainDetachSCSIVHostDevice(vm, detach, async);
- break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
- ret = qemuDomainDetachMediatedDevice(vm, detach, async);
- break;
+ /* we support detach of all these types of hostdev */
+ break;
+
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("hot unplug is not supported for hostdev subsys type
'%s'"),
With the qemu-attach aliaslessness allegations retracted and the double
check for alias removed:
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano