]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: add a qemuInterfaceStopDevices(), called when guest CPUs stop
authorLaine Stump <laine@laine.org>
Thu, 11 Dec 2014 20:11:10 +0000 (15:11 -0500)
committerLaine Stump <laine@laine.org>
Sun, 14 Dec 2014 03:20:28 +0000 (22:20 -0500)
We now have a qemuInterfaceStartDevices() which does the final
activation needed for the host-side tap/macvtap devices that are used
for qemu network connections. It will soon make sense to have the
converse qemuInterfaceStopDevices() which will undo whatever was done
during qemuInterfaceStartDevices().

A function to "stop" a single device has also been added, and is
called from the appropriate place in qemuDomainDetachNetDevice(),
although this is currently unnecessary - the device is going to
immediately be deleted anyway, so any extra "deactivation" will be for
naught. The call is included for completeness, though, in anticipation
that in the future there may be some required action that *isn't*
nullified by deleting the device.

This patch is a part of a more complete fix for:

  https://bugzilla.redhat.com/show_bug.cgi?id=1081461

src/qemu/qemu_hotplug.c
src/qemu/qemu_interface.c
src/qemu/qemu_interface.h
src/qemu/qemu_process.c

index 8c0642e4248d8c493474e6813a6e8f41f4215243..e56cffe2ea453b7a3ade030fc39eddc61bb3b147 100644 (file)
@@ -3513,6 +3513,14 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
         VIR_WARN("cannot clear bandwidth setting for device : %s",
                  detach->ifname);
 
+    /* deactivate the tap/macvtap device on the host (currently this
+     * isn't necessary, as everything done in
+     * qemuInterfaceStopDevice() is made meaningless when the device
+     * is deleted anyway, but in the future it may be important, and
+     * doesn't hurt anything for now)
+     */
+    ignore_value(qemuInterfaceStopDevice(detach));
+
     qemuDomainMarkDeviceForRemoval(vm, &detach->info);
 
     qemuDomainObjEnterMonitor(driver, vm);
index b0f0c5df9faa72a3f1ef97696447c86532465f24..2d33075f547902fb7b4b4cba2c9377ae8640138d 100644 (file)
@@ -41,8 +41,9 @@ int
 qemuInterfaceStartDevice(virDomainNetDefPtr net)
 {
     int ret = -1;
+    virDomainNetType actualType = virDomainNetGetActualType(net);
 
-    switch (virDomainNetGetActualType(net)) {
+    switch (actualType) {
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
     case VIR_DOMAIN_NET_TYPE_NETWORK:
         break;
@@ -98,3 +99,70 @@ qemuInterfaceStartDevices(virDomainDefPtr def)
     }
     return 0;
 }
+
+
+/**
+ * qemuInterfaceStopDevice:
+ * @net: net device to stop
+ *
+ * Based upon the type of device provided, perform the appropriate
+ * work to deactivate the device so that packets aren't forwarded to
+ * it from the rest of the network.
+ */
+int
+qemuInterfaceStopDevice(virDomainNetDefPtr net)
+{
+    int ret = -1;
+    virDomainNetType actualType = virDomainNetGetActualType(net);
+
+    switch (actualType) {
+    case VIR_DOMAIN_NET_TYPE_BRIDGE:
+    case VIR_DOMAIN_NET_TYPE_NETWORK:
+        break;
+
+    case VIR_DOMAIN_NET_TYPE_DIRECT:
+        /* macvtap interfaces need to be marked !IFF_UP (ie "down") to
+         * prevent any host-generated traffic sent from this interface
+         * from putting bad info into the arp caches of other machines
+         * on this network.
+         */
+        if (virNetDevSetOnline(net->ifname, false) < 0)
+            goto cleanup;
+        break;
+
+    case VIR_DOMAIN_NET_TYPE_USER:
+    case VIR_DOMAIN_NET_TYPE_ETHERNET:
+    case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
+    case VIR_DOMAIN_NET_TYPE_SERVER:
+    case VIR_DOMAIN_NET_TYPE_CLIENT:
+    case VIR_DOMAIN_NET_TYPE_MCAST:
+    case VIR_DOMAIN_NET_TYPE_INTERNAL:
+    case VIR_DOMAIN_NET_TYPE_HOSTDEV:
+    case VIR_DOMAIN_NET_TYPE_LAST:
+        /* these types all require no action */
+        break;
+    }
+
+    ret = 0;
+ cleanup:
+    return ret;
+}
+
+/**
+ * qemuInterfaceStopDevices:
+ * @def: domain definition
+ *
+ * Make all interfaces associated with this domain inaccessible from
+ * the rest of the network.
+ */
+int
+qemuInterfaceStopDevices(virDomainDefPtr def)
+{
+    size_t i;
+
+    for (i = 0; i < def->nnets; i++) {
+        if (qemuInterfaceStopDevice(def->nets[i]) < 0)
+            return -1;
+    }
+    return 0;
+}
index d040f52611815a0e5799a76e48baebdc10ba1294..b4c1efcb084c50643e51742aa1283fb49d291899 100644 (file)
@@ -28,5 +28,7 @@
 
 int qemuInterfaceStartDevice(virDomainNetDefPtr net);
 int qemuInterfaceStartDevices(virDomainDefPtr def);
+int qemuInterfaceStopDevice(virDomainNetDefPtr net);
+int qemuInterfaceStopDevices(virDomainDefPtr def);
 
 #endif /* __QEMU_INTERFACE_H__ */
index 0028283cdd68486dcfa108f9f3a47d81a53184a9..a19e71a8f0add7ef78e17d763820ff49d287b461 100644 (file)
@@ -3182,6 +3182,9 @@ int qemuProcessStopCPUs(virQEMUDriverPtr driver,
     if (ret < 0)
         goto cleanup;
 
+    /* de-activate netdevs after stopping CPUs */
+    ignore_value(qemuInterfaceStopDevices(vm->def));
+
     if (priv->job.current)
         ignore_value(virTimeMillisNow(&priv->job.current->stopped));