From bbe2aa627f621e6749af374b22856184d1f351dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Thu, 26 Jul 2018 17:24:30 +0100 Subject: [PATCH] conf: simplify link from hostdev back to network device MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hostdevs have a link back to the original network device. This is fairly generic accepting any type of device, however, we don't intend to make use of this approach in future. It can thus be specialized to network devices. Reviewed-by: Cole Robinson Signed-off-by: Daniel P. Berrangé --- src/conf/domain_conf.c | 22 ++++++++++------------ src/conf/domain_conf.h | 8 +++++++- src/libxl/libxl_driver.c | 4 ++-- src/network/bridge_driver.c | 3 +-- src/qemu/qemu_command.c | 3 +-- src/qemu/qemu_domain_address.c | 4 ++-- src/qemu/qemu_hotplug.c | 6 ++---- src/util/virhostdev.c | 17 ++++++++--------- 8 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 025cc4a994..1ec6455d14 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2848,10 +2848,10 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def) * such resource is the virDomainDeviceInfo. */ - /* If there is a parent device object, it will handle freeing + /* If there is a parentnet device object, it will handle freeing * def->info. */ - if (def->parent.type == VIR_DOMAIN_DEVICE_NONE) + if (!def->parentnet) virDomainDeviceInfoFree(def->info); switch (def->mode) { @@ -2919,10 +2919,10 @@ void virDomainHostdevDefFree(virDomainHostdevDefPtr def) /* free all subordinate objects */ virDomainHostdevDefClear(def); - /* If there is a parent device object, it will handle freeing + /* If there is a parentnet device object, it will handle freeing * the memory. */ - if (def->parent.type == VIR_DOMAIN_DEVICE_NONE) + if (!def->parentnet) VIR_FREE(def); } @@ -5490,7 +5490,7 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTRIBUTE_UNUSED, return 0; if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && - dev->data.hostdev->parent.type != VIR_DOMAIN_DEVICE_NONE) { + dev->data.hostdev->parentnet) { /* This hostdev is a child of a higher level device * (e.g. interface), and thus already being counted on the * list for the other device type. @@ -6340,7 +6340,7 @@ virDomainDeviceDefValidateAliasesIterator(virDomainDefPtr def, return 0; if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && - dev->data.hostdev->parent.type == VIR_DOMAIN_DEVICE_NET) { + dev->data.hostdev->parentnet) { /* This hostdev is a copy of some previous interface. * Aliases are duplicated. */ return 0; @@ -11156,8 +11156,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node, } else if (actual->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) { virDomainHostdevDefPtr hostdev = &actual->data.hostdev.def; - hostdev->parent.type = VIR_DOMAIN_DEVICE_NET; - hostdev->parent.data.net = parent; + hostdev->parentnet = parent; hostdev->info = &parent->info; /* The helper function expects type to already be found and * passed in as a string, since it is in a different place in @@ -11809,8 +11808,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, case VIR_DOMAIN_NET_TYPE_HOSTDEV: hostdev = &def->data.hostdev.def; - hostdev->parent.type = VIR_DOMAIN_DEVICE_NET; - hostdev->parent.data.net = def; + hostdev->parentnet = def; hostdev->info = &def->info; /* The helper function expects type to already be found and * passed in as a string, since it is in a different place in @@ -28509,11 +28507,11 @@ virDomainDefFormatInternal(virDomainDefPtr def, } for (n = 0; n < def->nhostdevs; n++) { - /* If parent.type != NONE, this is just a pointer to the + /* If parentnet != NONE, this is just a pointer to the * hostdev in a higher-level device (e.g. virDomainNetDef), * and will have already been formatted there. */ - if (def->hostdevs[n]->parent.type == VIR_DOMAIN_DEVICE_NONE && + if (!def->hostdevs[n]->parentnet && virDomainHostdevDefFormat(buf, def->hostdevs[n], flags) < 0) { goto error; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8ef6d507b8..c1bdf42c10 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -331,7 +331,13 @@ struct _virDomainHostdevCaps { /* basic device for direct passthrough */ struct _virDomainHostdevDef { - virDomainDeviceDef parent; /* higher level Def containing this */ + /* If 'parentnet' is non-NULL it means this host dev was + * not originally present in the XML. It was copied from + * a network interface for convenience when handling + * hostdevs internally. This hostdev should never be + * visible to the user except as part of the interface + */ + virDomainNetDefPtr parentnet; int mode; /* enum virDomainHostdevMode */ int startupPolicy; /* enum virDomainStartupPolicy */ diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 506dcdfbeb..42221cb925 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3915,9 +3915,9 @@ libxlDomainDetachDeviceLive(libxlDriverPrivatePtr driver, /* If this is a network hostdev, we need to use the higher-level * detach function so that mac address / virtualport are reset */ - if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET) + if (hostdev->parentnet) ret = libxlDomainDetachNetDevice(driver, vm, - hostdev->parent.data.net); + hostdev->parentnet); else ret = libxlDomainDetachHostDevice(driver, vm, hostdev); break; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index a10013d6a1..eb9a00f5cf 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4509,8 +4509,7 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->name); goto error; } - iface->data.network.actual->data.hostdev.def.parent.type = VIR_DOMAIN_DEVICE_NET; - iface->data.network.actual->data.hostdev.def.parent.data.net = iface; + iface->data.network.actual->data.hostdev.def.parentnet = iface; iface->data.network.actual->data.hostdev.def.info = &iface->info; iface->data.network.actual->data.hostdev.def.mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS; iface->data.network.actual->data.hostdev.def.managed = netdef->forward.managed ? 1 : 0; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2acc0b56ea..df60a3653b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5739,8 +5739,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, /* bootNet will be non-0 if boot order was set and no other * net devices were encountered */ - if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET && - bootIndex == 0) { + if (hostdev->parentnet && bootIndex == 0) { bootIndex = *bootHostdevNet; *bootHostdevNet = 0; } diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 2ec21e65ac..e28f8394a7 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1503,7 +1503,7 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED, if (!virDeviceInfoPCIAddressIsPresent(info) || ((device->type == VIR_DOMAIN_DEVICE_HOSTDEV) && - (device->data.hostdev->parent.type != VIR_DOMAIN_DEVICE_NONE))) { + device->data.hostdev->parentnet)) { /* If a hostdev has a parent, its info will be a part of the * parent, and will have its address collected during the scan * of the parent's device type. @@ -1598,7 +1598,7 @@ qemuDomainCollectPCIAddressExtension(virDomainDefPtr def ATTRIBUTE_UNUSED, if (!virDeviceInfoPCIAddressExtensionIsPresent(info) || ((device->type == VIR_DOMAIN_DEVICE_HOSTDEV) && - (device->data.hostdev->parent.type != VIR_DOMAIN_DEVICE_NONE))) { + device->data.hostdev->parentnet)) { /* If a hostdev has a parent, its info will be a part of the * parent, and will have its address collected during the scan * of the parent's device type. diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 7275bc1938..228ce2a76f 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4713,11 +4713,9 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, goto cleanup; } - if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET) { - net = hostdev->parent.data.net; - + if (hostdev->parentnet) { for (i = 0; i < vm->def->nnets; i++) { - if (vm->def->nets[i] == net) { + if (vm->def->nets[i] == hostdev->parentnet) { virDomainNetRemove(vm->def, i); break; } diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 6be395cdda..19ae001971 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -333,8 +333,7 @@ virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev) { return 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; + hostdev->parentnet != NULL; } @@ -427,7 +426,7 @@ virHostdevSaveNetConfig(virDomainHostdevDefPtr hostdev, int vf = -1; if (!virHostdevIsPCINetDevice(hostdev) || - virDomainNetGetActualVirtPortProfile(hostdev->parent.data.net)) + virDomainNetGetActualVirtPortProfile(hostdev->parentnet)) return 0; if (virHostdevIsVirtualFunction(hostdev) != 1) { @@ -474,8 +473,8 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev, if (virHostdevNetDevice(hostdev, -1, &linkdev, &vf) < 0) return -1; - vlan = virDomainNetGetActualVlan(hostdev->parent.data.net); - virtPort = virDomainNetGetActualVirtPortProfile(hostdev->parent.data.net); + vlan = virDomainNetGetActualVlan(hostdev->parentnet); + virtPort = virDomainNetGetActualVirtPortProfile(hostdev->parentnet); if (virtPort) { if (vlan) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -485,11 +484,11 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev, return -1; } if (virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, - &hostdev->parent.data.net->mac, + &hostdev->parentnet->mac, uuid, port_profile_associate) < 0) return -1; } else { - if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent.data.net->mac, + if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parentnet->mac, vlan, NULL, true) < 0) return -1; } @@ -535,10 +534,10 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostdev, if (virHostdevNetDevice(hostdev, 0, &linkdev, &vf) < 0) return -1; - virtPort = virDomainNetGetActualVirtPortProfile(hostdev->parent.data.net); + virtPort = virDomainNetGetActualVirtPortProfile(hostdev->parentnet); if (virtPort) { return virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, - &hostdev->parent.data.net->mac, + &hostdev->parentnet->mac, NULL, port_profile_associate); } else { -- GitLab