From nobody Sun Feb 8 03:33:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1545663601721865.1988310455022; Mon, 24 Dec 2018 07:00:01 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00BA2D4030; Mon, 24 Dec 2018 14:59:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5F281057062; Mon, 24 Dec 2018 14:59:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 85A4C3F60B; Mon, 24 Dec 2018 14:59:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wBOExRAY000767 for ; Mon, 24 Dec 2018 09:59:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 547C960C6D; Mon, 24 Dec 2018 14:59:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-27.ams2.redhat.com [10.36.112.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5339260C66; Mon, 24 Dec 2018 14:59:26 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 24 Dec 2018 14:58:52 +0000 Message-Id: <20181224145915.8700-5-berrange@redhat.com> In-Reply-To: <20181224145915.8700-1-berrange@redhat.com> References: <20181224145915.8700-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/27] conf: simplify link from hostdev back to network device X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 24 Dec 2018 15:00:00 +0000 (UTC) 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_conf.c | 18 ++++++++---------- 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_driver.c | 2 +- src/qemu/qemu_hotplug.c | 14 ++++++-------- src/qemu/qemu_hotplug.h | 2 +- src/util/virhostdev.c | 17 ++++++++--------- 10 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3320a03572..2181940144 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2614,7 +2614,7 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr = def) /* If there is a parent device object, it will handle freeing * def->info. */ - if (def->parent.type =3D=3D VIR_DOMAIN_DEVICE_NONE) + if (!def->parent) virDomainDeviceInfoFree(def->info); =20 switch (def->mode) { @@ -2685,7 +2685,7 @@ void virDomainHostdevDefFree(virDomainHostdevDefPtr d= ef) /* If there is a parent device object, it will handle freeing * the memory. */ - if (def->parent.type =3D=3D VIR_DOMAIN_DEVICE_NONE) + if (!def->parent) VIR_FREE(def); } =20 @@ -5061,7 +5061,7 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTR= IBUTE_UNUSED, return 0; =20 if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV && - dev->data.hostdev->parent.type !=3D VIR_DOMAIN_DEVICE_NONE) { + dev->data.hostdev->parent) { /* 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. @@ -5902,7 +5902,7 @@ virDomainDeviceDefValidateAliasesIterator(virDomainDe= fPtr def, return 0; =20 if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV && - dev->data.hostdev->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET) { + dev->data.hostdev->parent) { /* This hostdev is a copy of some previous interface. * Aliases are duplicated. */ return 0; @@ -10842,8 +10842,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node, } else if (actual->type =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { virDomainHostdevDefPtr hostdev =3D &actual->data.hostdev.def; =20 - hostdev->parent.type =3D VIR_DOMAIN_DEVICE_NET; - hostdev->parent.data.net =3D parent; + hostdev->parent =3D parent; hostdev->info =3D &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 @@ -11499,8 +11498,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, =20 case VIR_DOMAIN_NET_TYPE_HOSTDEV: hostdev =3D &def->data.hostdev.def; - hostdev->parent.type =3D VIR_DOMAIN_DEVICE_NET; - hostdev->parent.data.net =3D def; + hostdev->parent =3D def; hostdev->info =3D &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 @@ -28656,11 +28654,11 @@ virDomainDefFormatInternal(virDomainDefPtr def, } =20 for (n =3D 0; n < def->nhostdevs; n++) { - /* If parent.type !=3D NONE, this is just a pointer to the + /* If parent !=3D 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 =3D=3D VIR_DOMAIN_DEVICE_NONE && + if (!def->hostdevs[n]->parent && virDomainHostdevDefFormat(buf, def->hostdevs[n], flags) < 0) { goto error; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e611457314..829d7cd83e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -444,7 +444,13 @@ struct _virDomainHostdevCaps { =20 /* basic device for direct passthrough */ struct _virDomainHostdevDef { - virDomainDeviceDef parent; /* higher level Def containing this */ + /* If 'parent' 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 parent; =20 int mode; /* enum virDomainHostdevMode */ int startupPolicy; /* enum virDomainStartupPolicy */ diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index faebb40d31..1690400db6 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3921,9 +3921,9 @@ libxlDomainDetachDeviceLive(libxlDriverPrivatePtr dri= ver, /* If this is a network hostdev, we need to use the higher-lev= el * detach function so that mac address / virtualport are reset */ - if (hostdev->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET) + if (hostdev->parent) ret =3D libxlDomainDetachNetDevice(driver, vm, - hostdev->parent.data.net); + hostdev->parent); else ret =3D libxlDomainDetachHostDevice(driver, vm, hostdev); break; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index f3cdf40bfb..b5aac9350b 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4570,8 +4570,7 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->name); goto error; } - iface->data.network.actual->data.hostdev.def.parent.type =3D VIR_D= OMAIN_DEVICE_NET; - iface->data.network.actual->data.hostdev.def.parent.data.net =3D i= face; + iface->data.network.actual->data.hostdev.def.parent =3D iface; iface->data.network.actual->data.hostdev.def.info =3D &iface->info; iface->data.network.actual->data.hostdev.def.mode =3D VIR_DOMAIN_H= OSTDEV_MODE_SUBSYS; iface->data.network.actual->data.hostdev.def.managed =3D netdef->f= orward.managed ? 1 : 0; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 66a4a35184..8bce416d83 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5466,8 +5466,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 =3D=3D VIR_DOMAIN_DEVICE_NET && - bootIndex =3D=3D 0) { + if (hostdev->parent && bootIndex =3D=3D 0) { bootIndex =3D *bootHostdevNet; *bootHostdevNet =3D 0; } diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index bd6c4031e0..73d53e08a9 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1436,7 +1436,7 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATTRI= BUTE_UNUSED, =20 if (!virDeviceInfoPCIAddressIsPresent(info) || ((device->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) && - (device->data.hostdev->parent.type !=3D VIR_DOMAIN_DEVICE_NONE)))= { + device->data.hostdev->parent)) { /* 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. @@ -1531,7 +1531,7 @@ qemuDomainCollectPCIAddressExtension(virDomainDefPtr = def ATTRIBUTE_UNUSED, =20 if (!virDeviceInfoPCIAddressExtensionIsPresent(info) || ((device->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) && - (device->data.hostdev->parent.type !=3D VIR_DOMAIN_DEVICE_NONE)))= { + device->data.hostdev->parent)) { /* 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_driver.c b/src/qemu/qemu_driver.c index ea316f61d1..b69db58a44 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8023,7 +8023,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, ret =3D qemuDomainDetachLease(driver, vm, dev->data.lease); break; case VIR_DOMAIN_DEVICE_NET: - ret =3D qemuDomainDetachNetDevice(driver, vm, dev, async); + ret =3D qemuDomainDetachNetDevice(driver, vm, dev->data.net, async= ); break; case VIR_DOMAIN_DEVICE_HOSTDEV: ret =3D qemuDomainDetachHostDevice(driver, vm, dev, async); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 575c5854d3..c7c26e7685 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4601,11 +4601,9 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, event =3D virDomainEventDeviceRemovedNewFromObj(vm, hostdev->info->ali= as); virObjectEventStateQueue(driver->domainEventState, event); =20 - if (hostdev->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET) { - net =3D hostdev->parent.data.net; - + if (hostdev->parent) { for (i =3D 0; i < vm->def->nnets; i++) { - if (vm->def->nets[i] =3D=3D net) { + if (vm->def->nets[i] =3D=3D hostdev->parent) { virDomainNetRemove(vm->def, i); break; } @@ -5797,8 +5795,8 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr drive= r, /* If this is a network hostdev, we need to use the higher-level detach * function so that mac address / virtualport are reset */ - if (detach->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET) - return qemuDomainDetachNetDevice(driver, vm, &detach->parent, asyn= c); + if (detach->parent) + return qemuDomainDetachNetDevice(driver, vm, detach->parent, async= ); else return qemuDomainDetachThisHostDevice(driver, vm, detach, async); } @@ -5978,14 +5976,14 @@ qemuDomainDetachRedirdevDevice(virQEMUDriverPtr dri= ver, int qemuDomainDetachNetDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainDeviceDefPtr dev, + virDomainNetDefPtr net, bool async) { int detachidx, ret =3D -1; virDomainNetDefPtr detach =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 - if ((detachidx =3D virDomainNetFindIdx(vm->def, dev->data.net)) < 0) + if ((detachidx =3D virDomainNetFindIdx(vm->def, net)) < 0) goto cleanup; =20 detach =3D vm->def->nets[detachidx]; diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 7ac03b7810..d3fa588aac 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -109,7 +109,7 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr d= river, bool async); int qemuDomainDetachNetDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainDeviceDefPtr dev, + virDomainNetDefPtr net, bool async); int qemuDomainDetachHostDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 41d4e8d936..4a1e760984 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -333,8 +333,7 @@ virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev) { return hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && - hostdev->parent.type =3D=3D VIR_DOMAIN_DEVICE_NET && - hostdev->parent.data.net; + hostdev->parent !=3D NULL; } =20 =20 @@ -427,7 +426,7 @@ virHostdevSaveNetConfig(virDomainHostdevDefPtr hostdev, int vf =3D -1; =20 if (!virHostdevIsPCINetDevice(hostdev) || - virDomainNetGetActualVirtPortProfile(hostdev->parent.data.net)) + virDomainNetGetActualVirtPortProfile(hostdev->parent)) return 0; =20 if (virHostdevIsVirtualFunction(hostdev) !=3D 1) { @@ -474,8 +473,8 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev, if (virHostdevNetDevice(hostdev, -1, &linkdev, &vf) < 0) return -1; =20 - vlan =3D virDomainNetGetActualVlan(hostdev->parent.data.net); - virtPort =3D virDomainNetGetActualVirtPortProfile(hostdev->parent.data= .net); + vlan =3D virDomainNetGetActualVlan(hostdev->parent); + virtPort =3D virDomainNetGetActualVirtPortProfile(hostdev->parent); 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->parent->mac, uuid, port_profile_associat= e) < 0) return -1; } else { - if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent.data.net->= mac, + if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent->mac, vlan, NULL, true) < 0) return -1; } @@ -535,10 +534,10 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hos= tdev, if (virHostdevNetDevice(hostdev, 0, &linkdev, &vf) < 0) return -1; =20 - virtPort =3D virDomainNetGetActualVirtPortProfile(hostdev->parent.data= .net); + virtPort =3D virDomainNetGetActualVirtPortProfile(hostdev->parent); if (virtPort) { return virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, - &hostdev->parent.data.ne= t->mac, + &hostdev->parent->mac, NULL, port_profile_associate); } else { --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list