mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
network: convert networkNotifyActualDevice to virNetworkPortDef
Convert the virDomainNetDef object into a virNetworkPortDef object at the start of networkNotifyActualDevice. This largely decouples the method impl from the domain object type. Reviewed-by: Laine Stump <laine@laine.org> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
6cb0ec48bd
commit
116f87e98c
@ -4755,10 +4755,10 @@ networkNotifyActualDevice(virNetworkPtr net,
|
|||||||
virDomainNetDefPtr iface)
|
virDomainNetDefPtr iface)
|
||||||
{
|
{
|
||||||
virNetworkDriverStatePtr driver = networkGetDriver();
|
virNetworkDriverStatePtr driver = networkGetDriver();
|
||||||
virDomainNetType actualType = virDomainNetGetActualType(iface);
|
|
||||||
virNetworkObjPtr obj;
|
virNetworkObjPtr obj;
|
||||||
virNetworkDefPtr netdef;
|
virNetworkDefPtr netdef;
|
||||||
virNetworkForwardIfDefPtr dev = NULL;
|
virNetworkForwardIfDefPtr dev = NULL;
|
||||||
|
virNetworkPortDefPtr port = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -4785,40 +4785,35 @@ networkNotifyActualDevice(virNetworkPtr net,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iface->data.network.actual ||
|
if (!(port = virDomainNetDefActualToNetworkPort(dom, iface)))
|
||||||
(actualType != VIR_DOMAIN_NET_TYPE_DIRECT &&
|
goto cleanup;
|
||||||
actualType != VIR_DOMAIN_NET_TYPE_HOSTDEV)) {
|
|
||||||
VIR_DEBUG("Nothing to claim from network %s", iface->data.network.name);
|
|
||||||
goto success;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (networkCreateInterfacePool(netdef) < 0)
|
switch (port->plugtype) {
|
||||||
|
case VIR_NETWORK_PORT_PLUG_TYPE_NONE:
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("Unexpectedly got a network port without a plug"));
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (netdef->forward.nifs == 0) {
|
case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK:
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE:
|
||||||
_("network '%s' uses a direct or hostdev mode, "
|
/* see if we're connected to the correct bridge */
|
||||||
"but has no forward dev and no interface pool"),
|
if (!netdef->bridge) {
|
||||||
netdef->name);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
|
||||||
const char *actualDev;
|
|
||||||
|
|
||||||
actualDev = virDomainNetGetActualDirectDev(iface);
|
|
||||||
if (!actualDev) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("the interface uses a direct mode, "
|
_("Unexpectedly got a network port without a network bridge"));
|
||||||
"but has no source dev"));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT:
|
||||||
|
if (networkCreateInterfacePool(netdef) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
/* find the matching interface and increment its connections */
|
/* find the matching interface and increment its connections */
|
||||||
for (i = 0; i < netdef->forward.nifs; i++) {
|
for (i = 0; i < netdef->forward.nifs; i++) {
|
||||||
if (netdef->forward.ifs[i].type
|
if (netdef->forward.ifs[i].type
|
||||||
== VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV &&
|
== VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV &&
|
||||||
STREQ(actualDev, netdef->forward.ifs[i].device.dev)) {
|
STREQ(port->plug.direct.linkdev,
|
||||||
|
netdef->forward.ifs[i].device.dev)) {
|
||||||
dev = &netdef->forward.ifs[i];
|
dev = &netdef->forward.ifs[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -4827,8 +4822,9 @@ networkNotifyActualDevice(virNetworkPtr net,
|
|||||||
if (!dev) {
|
if (!dev) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("network '%s' doesn't have dev='%s' "
|
_("network '%s' doesn't have dev='%s' "
|
||||||
"in use by domain"),
|
"in use by network port '%s'"),
|
||||||
netdef->name, actualDev);
|
netdef->name, port->plug.direct.linkdev,
|
||||||
|
port->uuid);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4839,31 +4835,26 @@ networkNotifyActualDevice(virNetworkPtr net,
|
|||||||
if ((dev->connections > 0) &&
|
if ((dev->connections > 0) &&
|
||||||
((netdef->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH) ||
|
((netdef->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH) ||
|
||||||
((netdef->forward.type == VIR_NETWORK_FORWARD_PRIVATE) &&
|
((netdef->forward.type == VIR_NETWORK_FORWARD_PRIVATE) &&
|
||||||
iface->data.network.actual->virtPortProfile &&
|
port->virtPortProfile &&
|
||||||
(iface->data.network.actual->virtPortProfile->virtPortType
|
(port->virtPortProfile->virtPortType == VIR_NETDEV_VPORT_PROFILE_8021QBH)))) {
|
||||||
== VIR_NETDEV_VPORT_PROFILE_8021QBH)))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("network '%s' claims dev='%s' is already in "
|
_("network '%s' claims dev='%s' is already in "
|
||||||
"use by a different domain"),
|
"use by a different port"),
|
||||||
netdef->name, actualDev);
|
netdef->name, port->plug.direct.linkdev);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else /* if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) */ {
|
break;
|
||||||
virDomainHostdevDefPtr hostdev;
|
|
||||||
|
|
||||||
hostdev = virDomainNetGetActualHostdev(iface);
|
case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI:
|
||||||
if (!hostdev) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
if (networkCreateInterfacePool(netdef) < 0)
|
||||||
_("the interface uses a hostdev mode, "
|
|
||||||
"but has no hostdev"));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
/* find the matching interface and increment its connections */
|
/* find the matching interface and increment its connections */
|
||||||
for (i = 0; i < netdef->forward.nifs; i++) {
|
for (i = 0; i < netdef->forward.nifs; i++) {
|
||||||
if (netdef->forward.ifs[i].type
|
if (netdef->forward.ifs[i].type
|
||||||
== VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_PCI &&
|
== VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_PCI &&
|
||||||
virPCIDeviceAddressEqual(&hostdev->source.subsys.u.pci.addr,
|
virPCIDeviceAddressEqual(&port->plug.hostdevpci.addr,
|
||||||
&netdef->forward.ifs[i].device.pci)) {
|
&netdef->forward.ifs[i].device.pci)) {
|
||||||
dev = &netdef->forward.ifs[i];
|
dev = &netdef->forward.ifs[i];
|
||||||
break;
|
break;
|
||||||
@ -4873,12 +4864,12 @@ networkNotifyActualDevice(virNetworkPtr net,
|
|||||||
if (!dev) {
|
if (!dev) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("network '%s' doesn't have "
|
_("network '%s' doesn't have "
|
||||||
"PCI device %04x:%02x:%02x.%x in use by domain"),
|
"PCI device %04x:%02x:%02x.%x in use by network port"),
|
||||||
netdef->name,
|
netdef->name,
|
||||||
hostdev->source.subsys.u.pci.addr.domain,
|
port->plug.hostdevpci.addr.domain,
|
||||||
hostdev->source.subsys.u.pci.addr.bus,
|
port->plug.hostdevpci.addr.bus,
|
||||||
hostdev->source.subsys.u.pci.addr.slot,
|
port->plug.hostdevpci.addr.slot,
|
||||||
hostdev->source.subsys.u.pci.addr.function);
|
port->plug.hostdevpci.addr.function);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4891,15 +4882,21 @@ networkNotifyActualDevice(virNetworkPtr net,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("network '%s' claims the PCI device at "
|
_("network '%s' claims the PCI device at "
|
||||||
"domain=%d bus=%d slot=%d function=%d "
|
"domain=%d bus=%d slot=%d function=%d "
|
||||||
"is already in use by a different domain"),
|
"is already in use by a different network port"),
|
||||||
netdef->name,
|
netdef->name,
|
||||||
dev->device.pci.domain, dev->device.pci.bus,
|
dev->device.pci.domain, dev->device.pci.bus,
|
||||||
dev->device.pci.slot, dev->device.pci.function);
|
dev->device.pci.slot, dev->device.pci.function);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIR_NETWORK_PORT_PLUG_TYPE_LAST:
|
||||||
|
default:
|
||||||
|
virReportEnumRangeError(virNetworkPortPlugType, port->plugtype);
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
success:
|
|
||||||
netdef->connections++;
|
netdef->connections++;
|
||||||
if (dev)
|
if (dev)
|
||||||
dev->connections++;
|
dev->connections++;
|
||||||
@ -4917,6 +4914,7 @@ networkNotifyActualDevice(virNetworkPtr net,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virNetworkObjEndAPI(&obj);
|
virNetworkObjEndAPI(&obj);
|
||||||
|
virNetworkPortDefFree(port);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
Loading…
Reference in New Issue
Block a user