提交 bbe2aa62 编写于 作者: D Daniel P. Berrangé

conf: simplify link from hostdev back to network device

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: NCole Robinson <crobinso@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 43c402aa
...@@ -2848,10 +2848,10 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def) ...@@ -2848,10 +2848,10 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
* such resource is the virDomainDeviceInfo. * 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. * def->info.
*/ */
if (def->parent.type == VIR_DOMAIN_DEVICE_NONE) if (!def->parentnet)
virDomainDeviceInfoFree(def->info); virDomainDeviceInfoFree(def->info);
switch (def->mode) { switch (def->mode) {
...@@ -2919,10 +2919,10 @@ void virDomainHostdevDefFree(virDomainHostdevDefPtr def) ...@@ -2919,10 +2919,10 @@ void virDomainHostdevDefFree(virDomainHostdevDefPtr def)
/* free all subordinate objects */ /* free all subordinate objects */
virDomainHostdevDefClear(def); 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. * the memory.
*/ */
if (def->parent.type == VIR_DOMAIN_DEVICE_NONE) if (!def->parentnet)
VIR_FREE(def); VIR_FREE(def);
} }
...@@ -5490,7 +5490,7 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTRIBUTE_UNUSED, ...@@ -5490,7 +5490,7 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTRIBUTE_UNUSED,
return 0; return 0;
if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && 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 /* This hostdev is a child of a higher level device
* (e.g. interface), and thus already being counted on the * (e.g. interface), and thus already being counted on the
* list for the other device type. * list for the other device type.
...@@ -6340,7 +6340,7 @@ virDomainDeviceDefValidateAliasesIterator(virDomainDefPtr def, ...@@ -6340,7 +6340,7 @@ virDomainDeviceDefValidateAliasesIterator(virDomainDefPtr def,
return 0; return 0;
if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV && 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. /* This hostdev is a copy of some previous interface.
* Aliases are duplicated. */ * Aliases are duplicated. */
return 0; return 0;
...@@ -11156,8 +11156,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node, ...@@ -11156,8 +11156,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
} else if (actual->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) { } else if (actual->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
virDomainHostdevDefPtr hostdev = &actual->data.hostdev.def; virDomainHostdevDefPtr hostdev = &actual->data.hostdev.def;
hostdev->parent.type = VIR_DOMAIN_DEVICE_NET; hostdev->parentnet = parent;
hostdev->parent.data.net = parent;
hostdev->info = &parent->info; hostdev->info = &parent->info;
/* The helper function expects type to already be found and /* The helper function expects type to already be found and
* passed in as a string, since it is in a different place in * passed in as a string, since it is in a different place in
...@@ -11809,8 +11808,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, ...@@ -11809,8 +11808,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
case VIR_DOMAIN_NET_TYPE_HOSTDEV: case VIR_DOMAIN_NET_TYPE_HOSTDEV:
hostdev = &def->data.hostdev.def; hostdev = &def->data.hostdev.def;
hostdev->parent.type = VIR_DOMAIN_DEVICE_NET; hostdev->parentnet = def;
hostdev->parent.data.net = def;
hostdev->info = &def->info; hostdev->info = &def->info;
/* The helper function expects type to already be found and /* The helper function expects type to already be found and
* passed in as a string, since it is in a different place in * passed in as a string, since it is in a different place in
...@@ -28509,11 +28507,11 @@ virDomainDefFormatInternal(virDomainDefPtr def, ...@@ -28509,11 +28507,11 @@ virDomainDefFormatInternal(virDomainDefPtr def,
} }
for (n = 0; n < def->nhostdevs; n++) { 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), * hostdev in a higher-level device (e.g. virDomainNetDef),
* and will have already been formatted there. * 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) { virDomainHostdevDefFormat(buf, def->hostdevs[n], flags) < 0) {
goto error; goto error;
} }
......
...@@ -331,7 +331,13 @@ struct _virDomainHostdevCaps { ...@@ -331,7 +331,13 @@ struct _virDomainHostdevCaps {
/* basic device for direct passthrough */ /* basic device for direct passthrough */
struct _virDomainHostdevDef { 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 mode; /* enum virDomainHostdevMode */
int startupPolicy; /* enum virDomainStartupPolicy */ int startupPolicy; /* enum virDomainStartupPolicy */
......
...@@ -3915,9 +3915,9 @@ libxlDomainDetachDeviceLive(libxlDriverPrivatePtr driver, ...@@ -3915,9 +3915,9 @@ libxlDomainDetachDeviceLive(libxlDriverPrivatePtr driver,
/* If this is a network hostdev, we need to use the higher-level /* If this is a network hostdev, we need to use the higher-level
* detach function so that mac address / virtualport are reset * detach function so that mac address / virtualport are reset
*/ */
if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET) if (hostdev->parentnet)
ret = libxlDomainDetachNetDevice(driver, vm, ret = libxlDomainDetachNetDevice(driver, vm,
hostdev->parent.data.net); hostdev->parentnet);
else else
ret = libxlDomainDetachHostDevice(driver, vm, hostdev); ret = libxlDomainDetachHostDevice(driver, vm, hostdev);
break; break;
......
...@@ -4509,8 +4509,7 @@ networkAllocateActualDevice(virNetworkPtr net, ...@@ -4509,8 +4509,7 @@ networkAllocateActualDevice(virNetworkPtr net,
netdef->name); netdef->name);
goto error; goto error;
} }
iface->data.network.actual->data.hostdev.def.parent.type = VIR_DOMAIN_DEVICE_NET; iface->data.network.actual->data.hostdev.def.parentnet = iface;
iface->data.network.actual->data.hostdev.def.parent.data.net = iface;
iface->data.network.actual->data.hostdev.def.info = &iface->info; 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.mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
iface->data.network.actual->data.hostdev.def.managed = netdef->forward.managed ? 1 : 0; iface->data.network.actual->data.hostdev.def.managed = netdef->forward.managed ? 1 : 0;
......
...@@ -5739,8 +5739,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, ...@@ -5739,8 +5739,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
/* bootNet will be non-0 if boot order was set and no other /* bootNet will be non-0 if boot order was set and no other
* net devices were encountered * net devices were encountered
*/ */
if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET && if (hostdev->parentnet && bootIndex == 0) {
bootIndex == 0) {
bootIndex = *bootHostdevNet; bootIndex = *bootHostdevNet;
*bootHostdevNet = 0; *bootHostdevNet = 0;
} }
......
...@@ -1503,7 +1503,7 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED, ...@@ -1503,7 +1503,7 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
if (!virDeviceInfoPCIAddressIsPresent(info) || if (!virDeviceInfoPCIAddressIsPresent(info) ||
((device->type == VIR_DOMAIN_DEVICE_HOSTDEV) && ((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 /* If a hostdev has a parent, its info will be a part of the
* parent, and will have its address collected during the scan * parent, and will have its address collected during the scan
* of the parent's device type. * of the parent's device type.
...@@ -1598,7 +1598,7 @@ qemuDomainCollectPCIAddressExtension(virDomainDefPtr def ATTRIBUTE_UNUSED, ...@@ -1598,7 +1598,7 @@ qemuDomainCollectPCIAddressExtension(virDomainDefPtr def ATTRIBUTE_UNUSED,
if (!virDeviceInfoPCIAddressExtensionIsPresent(info) || if (!virDeviceInfoPCIAddressExtensionIsPresent(info) ||
((device->type == VIR_DOMAIN_DEVICE_HOSTDEV) && ((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 /* If a hostdev has a parent, its info will be a part of the
* parent, and will have its address collected during the scan * parent, and will have its address collected during the scan
* of the parent's device type. * of the parent's device type.
......
...@@ -4713,11 +4713,9 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, ...@@ -4713,11 +4713,9 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET) { if (hostdev->parentnet) {
net = hostdev->parent.data.net;
for (i = 0; i < vm->def->nnets; i++) { 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); virDomainNetRemove(vm->def, i);
break; break;
} }
......
...@@ -333,8 +333,7 @@ virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev) ...@@ -333,8 +333,7 @@ virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev)
{ {
return hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && return hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI && hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
hostdev->parent.type == VIR_DOMAIN_DEVICE_NET && hostdev->parentnet != NULL;
hostdev->parent.data.net;
} }
...@@ -427,7 +426,7 @@ virHostdevSaveNetConfig(virDomainHostdevDefPtr hostdev, ...@@ -427,7 +426,7 @@ virHostdevSaveNetConfig(virDomainHostdevDefPtr hostdev,
int vf = -1; int vf = -1;
if (!virHostdevIsPCINetDevice(hostdev) || if (!virHostdevIsPCINetDevice(hostdev) ||
virDomainNetGetActualVirtPortProfile(hostdev->parent.data.net)) virDomainNetGetActualVirtPortProfile(hostdev->parentnet))
return 0; return 0;
if (virHostdevIsVirtualFunction(hostdev) != 1) { if (virHostdevIsVirtualFunction(hostdev) != 1) {
...@@ -474,8 +473,8 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev, ...@@ -474,8 +473,8 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev,
if (virHostdevNetDevice(hostdev, -1, &linkdev, &vf) < 0) if (virHostdevNetDevice(hostdev, -1, &linkdev, &vf) < 0)
return -1; return -1;
vlan = virDomainNetGetActualVlan(hostdev->parent.data.net); vlan = virDomainNetGetActualVlan(hostdev->parentnet);
virtPort = virDomainNetGetActualVirtPortProfile(hostdev->parent.data.net); virtPort = virDomainNetGetActualVirtPortProfile(hostdev->parentnet);
if (virtPort) { if (virtPort) {
if (vlan) { if (vlan) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
...@@ -485,11 +484,11 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev, ...@@ -485,11 +484,11 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev,
return -1; return -1;
} }
if (virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, if (virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort,
&hostdev->parent.data.net->mac, &hostdev->parentnet->mac,
uuid, port_profile_associate) < 0) uuid, port_profile_associate) < 0)
return -1; return -1;
} else { } else {
if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent.data.net->mac, if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parentnet->mac,
vlan, NULL, true) < 0) vlan, NULL, true) < 0)
return -1; return -1;
} }
...@@ -535,10 +534,10 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostdev, ...@@ -535,10 +534,10 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostdev,
if (virHostdevNetDevice(hostdev, 0, &linkdev, &vf) < 0) if (virHostdevNetDevice(hostdev, 0, &linkdev, &vf) < 0)
return -1; return -1;
virtPort = virDomainNetGetActualVirtPortProfile(hostdev->parent.data.net); virtPort = virDomainNetGetActualVirtPortProfile(hostdev->parentnet);
if (virtPort) { if (virtPort) {
return virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, return virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort,
&hostdev->parent.data.net->mac, &hostdev->parentnet->mac,
NULL, NULL,
port_profile_associate); port_profile_associate);
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册