From 823e31ecb90aeb3d3362d9ff22f689e062d0e28e Mon Sep 17 00:00:00 2001
Message-Id: <823e31ecb90aeb3d3362d9ff22f689e062d0e28e.1382534061.git.jdenemar@redhat.com>
From: Laine Stump <laine@laine.org>
Date: Mon, 21 Oct 2013 10:12:58 -0600
Subject: [PATCH] qemu: simplify calling qemuDomainHostdevNetConfigRestore
This is a prerequisite to the fix for
https://bugzilla.redhat.com/show_bug.cgi?id=1005682
This function was called in three places, and in each the call was
qualified by a slightly different conditional. In reality, this
function should only be called for a hostdev if all of the following
are true:
1) mode='subsystem'
2) type='pci'
3) there is a parent device definition which is an <interface>
(VIR_DOMAIN_DEVICE_NET)
We can simplify the callers and make them more consistent by checking
these conditions at the top ov qemuDomainHostdevNetConfigRestore and
returning 0 if one of them isn't satisfied.
The location of the call to qemuDomainHostdevNetConfigRestore() has
also been changed in the hot-plug case - it is moved into the caller
of its previous location (i.e. from qemuDomainRemovePCIHostDevice() to
qemuDomainRemoveHostDevice()). This was done to be more consistent
about which functions pay attention to whether or not this is one of
the special <interface> hostdevs or just a normal hostdev -
qemuDomainRemoveHostDevice() already contained a call to
networkReleaseActualDevice() and virDomainNetDefFree(), so it makes
sense for it to also handle the resetting of the device's MAC address
and vlan tag (which is what's done by
qemuDomainHostdevNetConfigRestore()).
(cherry picked from commit 7a600cf77fb649e3412d4bf4f9eefba046562880)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
src/qemu/qemu_hostdev.c | 33 ++++++++++++++-------------------
src/qemu/qemu_hotplug.c | 13 ++++---------
2 files changed, 18 insertions(+), 28 deletions(-)
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 43c03cc..ca26dde 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -466,6 +466,15 @@ qemuDomainHostdevNetConfigRestore(virDomainHostdevDefPtr hostdev,
bool port_profile_associate = false;
int isvf;
+ /* This is only needed for PCI devices that have been defined
+ * using <interface type='hostdev'>. For all others, it is a NOP.
+ */
+ if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+ hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI ||
+ hostdev->parent.type != VIR_DOMAIN_DEVICE_NET ||
+ !hostdev->parent.data.net)
+ return 0;
+
isvf = qemuDomainHostdevIsVirtualFunction(hostdev);
if (isvf <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -799,14 +808,9 @@ inactivedevs:
}
resetvfnetconfig:
- for (i = 0; last_processed_hostdev_vf != -1 &&
- i < last_processed_hostdev_vf; i++) {
- virDomainHostdevDefPtr hostdev = hostdevs[i];
- if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET &&
- hostdev->parent.data.net) {
- qemuDomainHostdevNetConfigRestore(hostdev, cfg->stateDir);
- }
- }
+ for (i = 0;
+ last_processed_hostdev_vf != -1 && i < last_processed_hostdev_vf; i++)
+ qemuDomainHostdevNetConfigRestore(hostdevs[i], cfg->stateDir);
reattachdevs:
for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
@@ -1270,17 +1274,8 @@ qemuDomainReAttachHostdevDevices(virQEMUDriverPtr driver,
* For SRIOV net host devices, unset mac and port profile before
* reset and reattach device
*/
- for (i = 0; i < nhostdevs; i++) {
- virDomainHostdevDefPtr hostdev = hostdevs[i];
- if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
- continue;
- if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
- continue;
- if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET &&
- hostdev->parent.data.net) {
- qemuDomainHostdevNetConfigRestore(hostdev, cfg->stateDir);
- }
- }
+ for (i = 0; i < nhostdevs; i++)
+ qemuDomainHostdevNetConfigRestore(hostdevs[i], cfg->stateDir);
for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index cdbafa7..dcee86c 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2397,18 +2397,10 @@ qemuDomainRemovePCIHostDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
{
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
virPCIDevicePtr pci;
virPCIDevicePtr activePci;
- /*
- * For SRIOV net host devices, unset mac and port profile before
- * reset and reattach device
- */
- if (hostdev->parent.data.net)
- qemuDomainHostdevNetConfigRestore(hostdev, cfg->stateDir);
-
virObjectLock(driver->activePciHostdevs);
virObjectLock(driver->inactivePciHostdevs);
pci = virPCIDeviceNew(subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
@@ -2429,7 +2421,6 @@ qemuDomainRemovePCIHostDevice(virQEMUDriverPtr driver,
virObjectUnlock(driver->inactivePciHostdevs);
qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL);
- virObjectUnref(cfg);
}
static void
@@ -2465,6 +2456,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
{
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virDomainNetDefPtr net = NULL;
virDomainEventPtr event;
size_t i;
@@ -2496,6 +2488,8 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
virDomainAuditHostdev(vm, hostdev, "detach", true);
+ qemuDomainHostdevNetConfigRestore(hostdev, cfg->stateDir);
+
switch ((enum virDomainHostdevSubsysType) hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
qemuDomainRemovePCIHostDevice(driver, vm, hostdev);
@@ -2524,6 +2518,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
networkReleaseActualDevice(net);
virDomainNetDefFree(net);
}
+ virObjectUnref(cfg);
}
--
1.8.4