[libvirt] [PATCH v2 14/14] qemu_hotplug: don't shutdown net device until the guest has released it

Laine Stump laine at laine.org
Mon Mar 25 17:24:36 UTC 2019


For [some unknown reason, possibly/probably pure chance], Net devices
have been taken offline and their bandwidth tc rules cleared as the
very first operation when detaching the device. This is contrary to
every other type of device, where all hostside teardown is delayed
until we receive the DEVICE_DELETED event back from qemu, indicating
that the guest has finished with the device.

This patch delays these two operations until receipt of
DEVICE_DELETED, which removes an ugly wart from
qemuDomainDetachDeviceLive(), and also seems to be a more correct
sequence of events.

Signed-off-by: Laine Stump <laine at laine.org>
---

NEW PATCH IN V2.

 src/qemu/qemu_hotplug.c | 49 +++++++++--------------------------------
 1 file changed, 11 insertions(+), 38 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 78890f4bbe..2e2e913b4e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4821,6 +4821,17 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
         !(charDevAlias = qemuAliasChardevFromDevAlias(net->info.alias)))
         goto cleanup;
 
+    if (virDomainNetGetActualBandwidth(net) &&
+        virNetDevSupportBandwidth(virDomainNetGetActualType(net)) &&
+        virNetDevBandwidthClear(net->ifname) < 0)
+        VIR_WARN("cannot clear bandwidth setting for device : %s",
+                 net->ifname);
+
+    /* deactivate the tap/macvtap device on the host, which could also
+     * affect the parent device (e.g. macvtap passthrough mode sets
+     * the parent device offline)
+     */
+    ignore_value(qemuInterfaceStopDevice(net));
 
     qemuDomainObjEnterMonitor(driver, vm);
     if (qemuMonitorRemoveNetdev(priv->mon, hostnet_name) < 0) {
@@ -5795,33 +5806,6 @@ qemuDomainDetachPrepNet(virDomainObjPtr vm,
 }
 
 
-static void
-qemuDomainDetachShutdownNet(virDomainNetDefPtr net)
-{
-/*
- * These operations are in a separate function from
- * qemuDomainDetachPrepNet() because they can't be done until after
- * we've validated that this device really can be removed - in
- * particular we need to check for multifunction PCI devices and
- * presence of a device alias, which isn't done until *after* the
- * return from qemuDomainDetachPrepNet(). Since we've already passed
- * the "point of no return", we ignore any errors, and trudge ahead
- * with shutting down and detaching the device even if there is an
- * error in one of these functions.
- */
-    if (virDomainNetGetActualBandwidth(net) &&
-        virNetDevSupportBandwidth(virDomainNetGetActualType(net)) &&
-        virNetDevBandwidthClear(net->ifname) < 0)
-        VIR_WARN("cannot clear bandwidth setting for device : %s",
-                 net->ifname);
-
-    /* deactivate the tap/macvtap device on the host, which could also
-     * affect the parent device (e.g. macvtap passthrough mode sets
-     * the parent device offline)
-     */
-    ignore_value(qemuInterfaceStopDevice(net));
-}
-
 static int
 qemuDomainDetachDeviceChr(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
@@ -6152,17 +6136,6 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
         return -1;
     }
 
-
-    /*
-     * Do any device-specific shutdown that should be
-     * done after all validation checks, but before issuing the qemu
-     * command to delete the device. For now, the only type of device
-     * that has such shutdown needs is the net device.
-     */
-    if (detach.type == VIR_DOMAIN_DEVICE_NET)
-        qemuDomainDetachShutdownNet(detach.data.net);
-
-
     /*
      * Issue the qemu monitor command to delete the device (based on
      * its alias), and optionally wait a short time in case the
-- 
2.20.1




More information about the libvir-list mailing list