|
|
9119d9 |
From 9957213b20eb24113a8cf1d939674e4bb3d6a3b7 Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <9957213b20eb24113a8cf1d939674e4bb3d6a3b7@dist-git>
|
|
|
9119d9 |
From: Laine Stump <laine@laine.org>
|
|
|
9119d9 |
Date: Sun, 14 Dec 2014 23:44:51 -0500
|
|
|
9119d9 |
Subject: [PATCH] qemu: add a qemuInterfaceStopDevices(), called when guest
|
|
|
9119d9 |
CPUs stop
|
|
|
9119d9 |
|
|
|
9119d9 |
This patch is a part of a more complete fix for:
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1081461
|
|
|
9119d9 |
|
|
|
9119d9 |
We now have a qemuInterfaceStartDevices() which does the final
|
|
|
9119d9 |
activation needed for the host-side tap/macvtap devices that are used
|
|
|
9119d9 |
for qemu network connections. It will soon make sense to have the
|
|
|
9119d9 |
converse qemuInterfaceStopDevices() which will undo whatever was done
|
|
|
9119d9 |
during qemuInterfaceStartDevices().
|
|
|
9119d9 |
|
|
|
9119d9 |
A function to "stop" a single device has also been added, and is
|
|
|
9119d9 |
called from the appropriate place in qemuDomainDetachNetDevice(),
|
|
|
9119d9 |
although this is currently unnecessary - the device is going to
|
|
|
9119d9 |
immediately be deleted anyway, so any extra "deactivation" will be for
|
|
|
9119d9 |
naught. The call is included for completeness, though, in anticipation
|
|
|
9119d9 |
that in the future there may be some required action that *isn't*
|
|
|
9119d9 |
nullified by deleting the device.
|
|
|
9119d9 |
|
|
|
9119d9 |
(cherry picked from commit c5a54917d5ae97653d29dbfe4995f2efcf5717d6)
|
|
|
9119d9 |
|
|
|
9119d9 |
Conflicts:
|
|
|
9119d9 |
src/qemu/qemu_hotplug.c
|
|
|
9119d9 |
- again context around chunk changed due to centralization of
|
|
|
9119d9 |
bandwidth setting upstream.
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
src/qemu/qemu_hotplug.c | 8 ++++++
|
|
|
9119d9 |
src/qemu/qemu_interface.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++-
|
|
|
9119d9 |
src/qemu/qemu_interface.h | 2 ++
|
|
|
9119d9 |
src/qemu/qemu_process.c | 3 ++
|
|
|
9119d9 |
4 files changed, 82 insertions(+), 1 deletion(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
|
|
|
9119d9 |
index aaa7e21..84d2218 100644
|
|
|
9119d9 |
--- a/src/qemu/qemu_hotplug.c
|
|
|
9119d9 |
+++ b/src/qemu/qemu_hotplug.c
|
|
|
9119d9 |
@@ -3551,6 +3551,14 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
+ /* deactivate the tap/macvtap device on the host (currently this
|
|
|
9119d9 |
+ * isn't necessary, as everything done in
|
|
|
9119d9 |
+ * qemuInterfaceStopDevice() is made meaningless when the device
|
|
|
9119d9 |
+ * is deleted anyway, but in the future it may be important, and
|
|
|
9119d9 |
+ * doesn't hurt anything for now)
|
|
|
9119d9 |
+ */
|
|
|
9119d9 |
+ ignore_value(qemuInterfaceStopDevice(detach));
|
|
|
9119d9 |
+
|
|
|
9119d9 |
qemuDomainMarkDeviceForRemoval(vm, &detach->info);
|
|
|
9119d9 |
|
|
|
9119d9 |
qemuDomainObjEnterMonitor(driver, vm);
|
|
|
9119d9 |
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
|
|
|
9119d9 |
index b0f0c5d..2d33075 100644
|
|
|
9119d9 |
--- a/src/qemu/qemu_interface.c
|
|
|
9119d9 |
+++ b/src/qemu/qemu_interface.c
|
|
|
9119d9 |
@@ -41,8 +41,9 @@ int
|
|
|
9119d9 |
qemuInterfaceStartDevice(virDomainNetDefPtr net)
|
|
|
9119d9 |
{
|
|
|
9119d9 |
int ret = -1;
|
|
|
9119d9 |
+ virDomainNetType actualType = virDomainNetGetActualType(net);
|
|
|
9119d9 |
|
|
|
9119d9 |
- switch (virDomainNetGetActualType(net)) {
|
|
|
9119d9 |
+ switch (actualType) {
|
|
|
9119d9 |
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
|
|
9119d9 |
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
|
|
9119d9 |
break;
|
|
|
9119d9 |
@@ -98,3 +99,70 @@ qemuInterfaceStartDevices(virDomainDefPtr def)
|
|
|
9119d9 |
}
|
|
|
9119d9 |
return 0;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+/**
|
|
|
9119d9 |
+ * qemuInterfaceStopDevice:
|
|
|
9119d9 |
+ * @net: net device to stop
|
|
|
9119d9 |
+ *
|
|
|
9119d9 |
+ * Based upon the type of device provided, perform the appropriate
|
|
|
9119d9 |
+ * work to deactivate the device so that packets aren't forwarded to
|
|
|
9119d9 |
+ * it from the rest of the network.
|
|
|
9119d9 |
+ */
|
|
|
9119d9 |
+int
|
|
|
9119d9 |
+qemuInterfaceStopDevice(virDomainNetDefPtr net)
|
|
|
9119d9 |
+{
|
|
|
9119d9 |
+ int ret = -1;
|
|
|
9119d9 |
+ virDomainNetType actualType = virDomainNetGetActualType(net);
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ switch (actualType) {
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_NETWORK:
|
|
|
9119d9 |
+ break;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_DIRECT:
|
|
|
9119d9 |
+ /* macvtap interfaces need to be marked !IFF_UP (ie "down") to
|
|
|
9119d9 |
+ * prevent any host-generated traffic sent from this interface
|
|
|
9119d9 |
+ * from putting bad info into the arp caches of other machines
|
|
|
9119d9 |
+ * on this network.
|
|
|
9119d9 |
+ */
|
|
|
9119d9 |
+ if (virNetDevSetOnline(net->ifname, false) < 0)
|
|
|
9119d9 |
+ goto cleanup;
|
|
|
9119d9 |
+ break;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_USER:
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_SERVER:
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_CLIENT:
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_MCAST:
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_INTERNAL:
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
|
|
9119d9 |
+ case VIR_DOMAIN_NET_TYPE_LAST:
|
|
|
9119d9 |
+ /* these types all require no action */
|
|
|
9119d9 |
+ break;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ ret = 0;
|
|
|
9119d9 |
+ cleanup:
|
|
|
9119d9 |
+ return ret;
|
|
|
9119d9 |
+}
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+/**
|
|
|
9119d9 |
+ * qemuInterfaceStopDevices:
|
|
|
9119d9 |
+ * @def: domain definition
|
|
|
9119d9 |
+ *
|
|
|
9119d9 |
+ * Make all interfaces associated with this domain inaccessible from
|
|
|
9119d9 |
+ * the rest of the network.
|
|
|
9119d9 |
+ */
|
|
|
9119d9 |
+int
|
|
|
9119d9 |
+qemuInterfaceStopDevices(virDomainDefPtr def)
|
|
|
9119d9 |
+{
|
|
|
9119d9 |
+ size_t i;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ for (i = 0; i < def->nnets; i++) {
|
|
|
9119d9 |
+ if (qemuInterfaceStopDevice(def->nets[i]) < 0)
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+ return 0;
|
|
|
9119d9 |
+}
|
|
|
9119d9 |
diff --git a/src/qemu/qemu_interface.h b/src/qemu/qemu_interface.h
|
|
|
9119d9 |
index d040f52..b4c1efc 100644
|
|
|
9119d9 |
--- a/src/qemu/qemu_interface.h
|
|
|
9119d9 |
+++ b/src/qemu/qemu_interface.h
|
|
|
9119d9 |
@@ -28,5 +28,7 @@
|
|
|
9119d9 |
|
|
|
9119d9 |
int qemuInterfaceStartDevice(virDomainNetDefPtr net);
|
|
|
9119d9 |
int qemuInterfaceStartDevices(virDomainDefPtr def);
|
|
|
9119d9 |
+int qemuInterfaceStopDevice(virDomainNetDefPtr net);
|
|
|
9119d9 |
+int qemuInterfaceStopDevices(virDomainDefPtr def);
|
|
|
9119d9 |
|
|
|
9119d9 |
#endif /* __QEMU_INTERFACE_H__ */
|
|
|
9119d9 |
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
|
|
|
9119d9 |
index 627755d..d7b2688 100644
|
|
|
9119d9 |
--- a/src/qemu/qemu_process.c
|
|
|
9119d9 |
+++ b/src/qemu/qemu_process.c
|
|
|
9119d9 |
@@ -3170,6 +3170,9 @@ int qemuProcessStopCPUs(virQEMUDriverPtr driver,
|
|
|
9119d9 |
if (ret < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
+ /* de-activate netdevs after stopping CPUs */
|
|
|
9119d9 |
+ ignore_value(qemuInterfaceStopDevices(vm->def));
|
|
|
9119d9 |
+
|
|
|
9119d9 |
if (priv->job.current)
|
|
|
9119d9 |
ignore_value(virTimeMillisNow(&priv->job.current->stopped));
|
|
|
9119d9 |
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.2.0
|
|
|
9119d9 |
|