[1] reported that we are removing network's backend too early. I didn't
really get the reproducer but libvirt behaves strangely when a guest
does not confirm the removal, e.g., it does not support PCI hotplug. In
such case, detaching a network device leaves its frontend in place but
removes the backend, which makes the device unusable for the guest.
Moreover attaching the same device again succeeds and both the guest and
libvirt will see two network interfaces attached but only one of them is
actually working.
I checked with Paolo Bonzini and he confirmed we should only remove a
backend after seeing DEVICE_DELETED event for a corresponding frontend.
[1]
https://www.redhat.com/archives/libvir-list/2014-March/msg01740.html
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_hotplug.c | 56 +++++++++++++++++++++++++------------------------
1 file changed, 29 insertions(+), 27 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index b209b04..fd1f002 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2636,8 +2636,10 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
virDomainNetDefPtr net)
{
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ qemuDomainObjPrivatePtr priv = vm->privateData;
virNetDevVPortProfilePtr vport;
virObjectEventPtr event;
+ char *hostnet_name = NULL;
size_t i;
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
@@ -2649,6 +2651,32 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
VIR_DEBUG("Removing network interface %s from domain %p %s",
net->info.alias, vm, vm->def->name);
+ if (virAsprintf(&hostnet_name, "host%s", net->info.alias) < 0)
+ goto cleanup;
+
+ qemuDomainObjEnterMonitor(driver, vm);
+ if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NETDEV) &&
+ virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
+ if (qemuMonitorRemoveNetdev(priv->mon, hostnet_name) < 0) {
+ qemuDomainObjExitMonitor(driver, vm);
+ virDomainAuditNet(vm, net, NULL, "detach", false);
+ goto cleanup;
+ }
+ } else {
+ int vlan;
+ if ((vlan = qemuDomainNetVLAN(net)) < 0 ||
+ qemuMonitorRemoveHostNetwork(priv->mon, vlan, hostnet_name) < 0) {
+ if (vlan < 0) {
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("unable to determine original VLAN"));
+ }
+ qemuDomainObjExitMonitor(driver, vm);
+ virDomainAuditNet(vm, net, NULL, "detach", false);
+ goto cleanup;
+ }
+ }
+ qemuDomainObjExitMonitor(driver, vm);
+
virDomainAuditNet(vm, net, NULL, "detach", true);
event = virDomainEventDeviceRemovedNewFromObj(vm, net->info.alias);
@@ -2692,6 +2720,7 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
cleanup:
virObjectUnref(cfg);
+ VIR_FREE(hostnet_name);
}
@@ -3379,8 +3408,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
int detachidx, ret = -1;
virDomainNetDefPtr detach = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
- int vlan;
- char *hostnet_name = NULL;
int rc;
if ((detachidx = virDomainNetFindIdx(vm->def, dev->data.net)) < 0)
@@ -3418,15 +3445,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
}
}
- if ((vlan = qemuDomainNetVLAN(detach)) < 0) {
- virReportError(VIR_ERR_OPERATION_FAILED,
- "%s", _("unable to determine original
VLAN"));
- goto cleanup;
- }
-
- if (virAsprintf(&hostnet_name, "host%s", detach->info.alias) <
0)
- goto cleanup;
-
qemuDomainMarkDeviceForRemoval(vm, &detach->info);
qemuDomainObjEnterMonitor(driver, vm);
@@ -3444,21 +3462,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
goto cleanup;
}
}
-
- if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NETDEV) &&
- virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
- if (qemuMonitorRemoveNetdev(priv->mon, hostnet_name) < 0) {
- qemuDomainObjExitMonitor(driver, vm);
- virDomainAuditNet(vm, detach, NULL, "detach", false);
- goto cleanup;
- }
- } else {
- if (qemuMonitorRemoveHostNetwork(priv->mon, vlan, hostnet_name) < 0) {
- qemuDomainObjExitMonitor(driver, vm);
- virDomainAuditNet(vm, detach, NULL, "detach", false);
- goto cleanup;
- }
- }
qemuDomainObjExitMonitor(driver, vm);
rc = qemuDomainWaitForDeviceRemoval(vm);
@@ -3469,7 +3472,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
cleanup:
qemuDomainResetDeviceRemoval(vm);
- VIR_FREE(hostnet_name);
return ret;
}
--
1.9.3