mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
conf: reimplement virDomainNetResolveActualType in terms of public API
Now that we have the ability to easily open connections to secondary drivers, eg network:///system, it is possible to reimplement the virDomainNetResolveActualType method in terms of the public API. This avoids the need to have the network driver provide a callback for it. Reviewed-by: John Ferlan <jferlan@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
70854ea3bc
commit
0c63c117a2
@ -28926,7 +28926,6 @@ static virDomainNetNotifyActualDeviceImpl netNotify;
|
|||||||
static virDomainNetReleaseActualDeviceImpl netRelease;
|
static virDomainNetReleaseActualDeviceImpl netRelease;
|
||||||
static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed;
|
static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed;
|
||||||
static virDomainNetBandwidthUpdateImpl netBandwidthUpdate;
|
static virDomainNetBandwidthUpdateImpl netBandwidthUpdate;
|
||||||
static virDomainNetResolveActualTypeImpl netResolveActualType;
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -28934,15 +28933,13 @@ virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
|
|||||||
virDomainNetNotifyActualDeviceImpl notify,
|
virDomainNetNotifyActualDeviceImpl notify,
|
||||||
virDomainNetReleaseActualDeviceImpl release,
|
virDomainNetReleaseActualDeviceImpl release,
|
||||||
virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
|
virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
|
||||||
virDomainNetBandwidthUpdateImpl bandwidthUpdate,
|
virDomainNetBandwidthUpdateImpl bandwidthUpdate)
|
||||||
virDomainNetResolveActualTypeImpl resolveActualType)
|
|
||||||
{
|
{
|
||||||
netAllocate = allocate;
|
netAllocate = allocate;
|
||||||
netNotify = notify;
|
netNotify = notify;
|
||||||
netRelease = release;
|
netRelease = release;
|
||||||
netBandwidthChangeAllowed = bandwidthChangeAllowed;
|
netBandwidthChangeAllowed = bandwidthChangeAllowed;
|
||||||
netBandwidthUpdate = bandwidthUpdate;
|
netBandwidthUpdate = bandwidthUpdate;
|
||||||
netResolveActualType = resolveActualType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -29011,16 +29008,83 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
|
|||||||
return netBandwidthUpdate(iface, newBandwidth);
|
return netBandwidthUpdate(iface, newBandwidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* virDomainNetResolveActualType:
|
||||||
|
* @iface: the original NetDef from the domain
|
||||||
|
*
|
||||||
|
* Looks up the network reference by iface, and returns the actual
|
||||||
|
* type of the connection without allocating any resources.
|
||||||
|
*
|
||||||
|
* Returns 0 on success, -1 on failure.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
virDomainNetResolveActualType(virDomainNetDefPtr iface)
|
virDomainNetResolveActualType(virDomainNetDefPtr iface)
|
||||||
{
|
{
|
||||||
if (!netResolveActualType) {
|
virConnectPtr conn = NULL;
|
||||||
virReportError(VIR_ERR_NO_SUPPORT, "%s",
|
virNetworkPtr net = NULL;
|
||||||
_("Network device resolve type not available"));
|
char *xml = NULL;
|
||||||
|
virNetworkDefPtr def = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK)
|
||||||
|
return iface->type;
|
||||||
|
|
||||||
|
if (iface->data.network.actual)
|
||||||
|
return iface->data.network.actual->type;
|
||||||
|
|
||||||
|
if (!(conn = virGetConnectNetwork()))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (!(net = virNetworkLookupByName(conn, iface->data.network.name)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(xml = virNetworkGetXMLDesc(net, 0)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(def = virNetworkDefParseString(xml)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if ((def->forward.type == VIR_NETWORK_FORWARD_NONE) ||
|
||||||
|
(def->forward.type == VIR_NETWORK_FORWARD_NAT) ||
|
||||||
|
(def->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
|
||||||
|
(def->forward.type == VIR_NETWORK_FORWARD_OPEN)) {
|
||||||
|
/* for these forward types, the actual net type really *is*
|
||||||
|
* NETWORK; we just keep the info from the portgroup in
|
||||||
|
* iface->data.network.actual
|
||||||
|
*/
|
||||||
|
ret = VIR_DOMAIN_NET_TYPE_NETWORK;
|
||||||
|
|
||||||
|
} else if ((def->forward.type == VIR_NETWORK_FORWARD_BRIDGE) &&
|
||||||
|
def->bridge) {
|
||||||
|
|
||||||
|
/* <forward type='bridge'/> <bridge name='xxx'/>
|
||||||
|
* is VIR_DOMAIN_NET_TYPE_BRIDGE
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret = VIR_DOMAIN_NET_TYPE_BRIDGE;
|
||||||
|
|
||||||
|
} else if (def->forward.type == VIR_NETWORK_FORWARD_HOSTDEV) {
|
||||||
|
|
||||||
|
ret = VIR_DOMAIN_NET_TYPE_HOSTDEV;
|
||||||
|
|
||||||
|
} else if ((def->forward.type == VIR_NETWORK_FORWARD_BRIDGE) ||
|
||||||
|
(def->forward.type == VIR_NETWORK_FORWARD_PRIVATE) ||
|
||||||
|
(def->forward.type == VIR_NETWORK_FORWARD_VEPA) ||
|
||||||
|
(def->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) {
|
||||||
|
|
||||||
|
/* <forward type='bridge|private|vepa|passthrough'> are all
|
||||||
|
* VIR_DOMAIN_NET_TYPE_DIRECT.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret = VIR_DOMAIN_NET_TYPE_DIRECT;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return netResolveActualType(iface);
|
cleanup:
|
||||||
|
virNetworkDefFree(def);
|
||||||
|
VIR_FREE(xml);
|
||||||
|
virObjectUnref(conn);
|
||||||
|
virObjectUnref(net);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3474,17 +3474,13 @@ typedef int
|
|||||||
(*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface,
|
(*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface,
|
||||||
virNetDevBandwidthPtr newBandwidth);
|
virNetDevBandwidthPtr newBandwidth);
|
||||||
|
|
||||||
typedef int
|
|
||||||
(*virDomainNetResolveActualTypeImpl)(virDomainNetDefPtr iface);
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
|
virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
|
||||||
virDomainNetNotifyActualDeviceImpl notify,
|
virDomainNetNotifyActualDeviceImpl notify,
|
||||||
virDomainNetReleaseActualDeviceImpl release,
|
virDomainNetReleaseActualDeviceImpl release,
|
||||||
virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
|
virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
|
||||||
virDomainNetBandwidthUpdateImpl bandwidthUpdate,
|
virDomainNetBandwidthUpdateImpl bandwidthUpdate);
|
||||||
virDomainNetResolveActualTypeImpl resolveActualType);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virDomainNetAllocateActualDevice(virDomainDefPtr dom,
|
virDomainNetAllocateActualDevice(virDomainDefPtr dom,
|
||||||
@ -3511,11 +3507,6 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
|
|||||||
virNetDevBandwidthPtr newBandwidth)
|
virNetDevBandwidthPtr newBandwidth)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||||
|
|
||||||
/* XXX this is a nasty hack and should be removed. It should
|
|
||||||
* be by via public API by fetching XML and parsing it. Not
|
|
||||||
* easy right now as code paths in QEMU reying on this don't
|
|
||||||
* have a virConnectPtr handy.
|
|
||||||
*/
|
|
||||||
int
|
int
|
||||||
virDomainNetResolveActualType(virDomainNetDefPtr iface)
|
virDomainNetResolveActualType(virDomainNetDefPtr iface)
|
||||||
ATTRIBUTE_NONNULL(1);
|
ATTRIBUTE_NONNULL(1);
|
||||||
|
@ -5146,79 +5146,6 @@ networkReleaseActualDevice(virDomainDefPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* networkResolveActualType:
|
|
||||||
* @iface: the original NetDef from the domain
|
|
||||||
*
|
|
||||||
* Looks up the network reference by iface, and returns the actual
|
|
||||||
* type of the connection without allocating any resources.
|
|
||||||
*
|
|
||||||
* Returns 0 on success, -1 on failure.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
networkResolveActualType(virDomainNetDefPtr iface)
|
|
||||||
{
|
|
||||||
virNetworkDriverStatePtr driver = networkGetDriver();
|
|
||||||
virNetworkObjPtr obj = NULL;
|
|
||||||
virNetworkDefPtr netdef = NULL;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!driver || iface->type != VIR_DOMAIN_NET_TYPE_NETWORK)
|
|
||||||
return iface->type;
|
|
||||||
|
|
||||||
if (iface->data.network.actual)
|
|
||||||
return iface->data.network.actual->type;
|
|
||||||
|
|
||||||
obj = virNetworkObjFindByName(driver->networks, iface->data.network.name);
|
|
||||||
if (!obj) {
|
|
||||||
virReportError(VIR_ERR_NO_NETWORK,
|
|
||||||
_("no network with matching name '%s'"),
|
|
||||||
iface->data.network.name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
netdef = virNetworkObjGetDef(obj);
|
|
||||||
|
|
||||||
if ((netdef->forward.type == VIR_NETWORK_FORWARD_NONE) ||
|
|
||||||
(netdef->forward.type == VIR_NETWORK_FORWARD_NAT) ||
|
|
||||||
(netdef->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
|
|
||||||
(netdef->forward.type == VIR_NETWORK_FORWARD_OPEN)) {
|
|
||||||
/* for these forward types, the actual net type really *is*
|
|
||||||
* NETWORK; we just keep the info from the portgroup in
|
|
||||||
* iface->data.network.actual
|
|
||||||
*/
|
|
||||||
ret = VIR_DOMAIN_NET_TYPE_NETWORK;
|
|
||||||
|
|
||||||
} else if ((netdef->forward.type == VIR_NETWORK_FORWARD_BRIDGE) &&
|
|
||||||
netdef->bridge) {
|
|
||||||
|
|
||||||
/* <forward type='bridge'/> <bridge name='xxx'/>
|
|
||||||
* is VIR_DOMAIN_NET_TYPE_BRIDGE
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = VIR_DOMAIN_NET_TYPE_BRIDGE;
|
|
||||||
|
|
||||||
} else if (netdef->forward.type == VIR_NETWORK_FORWARD_HOSTDEV) {
|
|
||||||
|
|
||||||
ret = VIR_DOMAIN_NET_TYPE_HOSTDEV;
|
|
||||||
|
|
||||||
} else if ((netdef->forward.type == VIR_NETWORK_FORWARD_BRIDGE) ||
|
|
||||||
(netdef->forward.type == VIR_NETWORK_FORWARD_PRIVATE) ||
|
|
||||||
(netdef->forward.type == VIR_NETWORK_FORWARD_VEPA) ||
|
|
||||||
(netdef->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) {
|
|
||||||
|
|
||||||
/* <forward type='bridge|private|vepa|passthrough'> are all
|
|
||||||
* VIR_DOMAIN_NET_TYPE_DIRECT.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = VIR_DOMAIN_NET_TYPE_DIRECT;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
virNetworkObjEndAPI(&obj);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* networkCheckBandwidth:
|
* networkCheckBandwidth:
|
||||||
* @net: network QoS
|
* @net: network QoS
|
||||||
@ -5717,8 +5644,7 @@ networkRegister(void)
|
|||||||
networkNotifyActualDevice,
|
networkNotifyActualDevice,
|
||||||
networkReleaseActualDevice,
|
networkReleaseActualDevice,
|
||||||
networkBandwidthChangeAllowed,
|
networkBandwidthChangeAllowed,
|
||||||
networkBandwidthUpdate,
|
networkBandwidthUpdate);
|
||||||
networkResolveActualType);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,7 @@ test_libraries += virmocklibxl.la
|
|||||||
endif WITH_LIBXL
|
endif WITH_LIBXL
|
||||||
|
|
||||||
if WITH_QEMU
|
if WITH_QEMU
|
||||||
test_programs += qemuxml2xmltest \
|
test_programs += qemuxml2argvtest qemuxml2xmltest \
|
||||||
qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \
|
qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \
|
||||||
qemumonitortest qemumonitorjsontest qemuhotplugtest \
|
qemumonitortest qemumonitorjsontest qemuhotplugtest \
|
||||||
qemuagenttest qemucapabilitiestest qemucaps2xmltest \
|
qemuagenttest qemucapabilitiestest qemucaps2xmltest \
|
||||||
@ -288,11 +288,6 @@ test_programs += qemuxml2xmltest \
|
|||||||
qemucommandutiltest \
|
qemucommandutiltest \
|
||||||
qemublocktest \
|
qemublocktest \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
if WITH_NETWORK
|
|
||||||
# Dep on the network driver callback for resolving NIC
|
|
||||||
# actual type. XXX remove this dep.
|
|
||||||
test_programs += qemuxml2argvtest
|
|
||||||
endif WITH_NETWORK
|
|
||||||
test_helpers += qemucapsprobe
|
test_helpers += qemucapsprobe
|
||||||
test_libraries += libqemumonitortestutils.la \
|
test_libraries += libqemumonitortestutils.la \
|
||||||
libqemutestdriver.la \
|
libqemutestdriver.la \
|
||||||
|
Loading…
Reference in New Issue
Block a user