virReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"),
iface->data.network.name);
- goto cleanup;
+ goto error;
}
-
netdef = network->def;
/* portgroup can be present for any type of network, in particular
if (!iface->data.network.actual
&& (VIR_ALLOC(iface->data.network.actual) < 0)) {
virReportOOMError();
- goto cleanup;
+ goto error;
}
if (virNetDevBandwidthCopy(&iface->data.network.actual->bandwidth,
portgroup->bandwidth) < 0)
- goto cleanup;
+ goto error;
}
if ((netdef->forwardType == VIR_NETWORK_FORWARD_NONE) ||
if (!iface->data.network.actual
&& (VIR_ALLOC(iface->data.network.actual) < 0)) {
virReportOOMError();
- goto cleanup;
+ goto error;
}
iface->data.network.actual->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
iface->data.network.actual->data.bridge.brname = strdup(netdef->bridge);
if (!iface->data.network.actual->data.bridge.brname) {
virReportOOMError();
- goto cleanup;
+ goto error;
}
/* merge virtualports from interface, network, and portgroup to
netdef->virtPortProfile,
portgroup
? portgroup->virtPortProfile : NULL) < 0) {
- goto cleanup;
+ goto error;
}
virtport = iface->data.network.actual->virtPortProfile;
if (virtport) {
"'%s' which uses a bridge device"),
virNetDevVPortTypeToString(virtport->virtPortType),
netdef->name);
- goto cleanup;
+ goto error;
}
}
if (!iface->data.network.actual
&& (VIR_ALLOC(iface->data.network.actual) < 0)) {
virReportOOMError();
- goto cleanup;
+ goto error;
}
/* Set type=direct and appropriate <source mode='xxx'/> */
netdef->virtPortProfile,
portgroup
? portgroup->virtPortProfile : NULL) < 0) {
- goto cleanup;
+ goto error;
}
virtport = iface->data.network.actual->virtPortProfile;
if (virtport) {
"'%s' which uses a macvtap device"),
virNetDevVPortTypeToString(virtport->virtPortType),
netdef->name);
- goto cleanup;
+ goto error;
}
}
_("network '%s' uses a direct mode, but "
"has no forward dev and no interface pool"),
netdef->name);
- goto cleanup;
+ goto error;
} else {
/* pick an interface from the pool */
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get Virtual functions on %s"),
netdef->forwardPfs->dev);
- goto cleanup;
+ goto error;
}
if (num_virt_fns == 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("No Vf's present on SRIOV PF %s"),
netdef->forwardPfs->dev);
- goto cleanup;
+ goto error;
}
if ((VIR_ALLOC_N(netdef->forwardIfs, num_virt_fns)) < 0) {
virReportOOMError();
- goto cleanup;
+ goto error;
}
netdef->nForwardIfs = num_virt_fns;
netdef->forwardIfs[ii].dev = strdup(vfname[ii]);
if (!netdef->forwardIfs[ii].dev) {
virReportOOMError();
- goto cleanup;
+ goto error;
}
}
}
_("network '%s' requires exclusive access "
"to interfaces, but none are available"),
netdef->name);
- goto cleanup;
+ goto error;
}
iface->data.network.actual->data.direct.linkdev = strdup(dev->dev);
if (!iface->data.network.actual->data.direct.linkdev) {
virReportOOMError();
- goto cleanup;
+ goto error;
}
}
}
if (virNetDevVPortProfileCheckComplete(virtport, true) < 0)
- goto cleanup;
+ goto error;
if (dev) {
/* we are now assured of success, so mark the allocation */
VIR_FREE(vfname);
if (network)
virNetworkObjUnlock(network);
- if (ret < 0) {
+ return ret;
+
+error:
+ if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainActualNetDefFree(iface->data.network.actual);
iface->data.network.actual = NULL;
}
- return ret;
+ goto cleanup;
}
/* networkNotifyActualDevice:
if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK)
return 0;
- if (!iface->data.network.actual ||
- (virDomainNetGetActualType(iface) != VIR_DOMAIN_NET_TYPE_DIRECT)) {
- VIR_DEBUG("Nothing to claim from network %s", iface->data.network.name);
- return 0;
- }
-
networkDriverLock(driver);
network = virNetworkFindByName(&driver->networks, iface->data.network.name);
networkDriverUnlock(driver);
virReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"),
iface->data.network.name);
- goto cleanup;
+ goto error;
+ }
+ netdef = network->def;
+
+ if (!iface->data.network.actual ||
+ (virDomainNetGetActualType(iface) != VIR_DOMAIN_NET_TYPE_DIRECT)) {
+ VIR_DEBUG("Nothing to claim from network %s", iface->data.network.name);
+ goto success;
}
actualDev = virDomainNetGetActualDirectDev(iface);
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("the interface uses a direct "
"mode, but has no source dev"));
- goto cleanup;
+ goto error;
}
- netdef = network->def;
if (netdef->nForwardIfs == 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("network '%s' uses a direct mode, but "
"has no forward dev and no interface pool"),
netdef->name);
- goto cleanup;
+ goto error;
} else {
int ii;
virNetworkForwardIfDefPtr dev = NULL;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("network '%s' doesn't have dev='%s' in use by domain"),
netdef->name, actualDev);
- goto cleanup;
+ goto error;
}
/* PASSTHROUGH mode, and PRIVATE Mode + 802.1Qbh both require
virReportError(VIR_ERR_INTERNAL_ERROR,
_("network '%s' claims dev='%s' is already in use by a different domain"),
netdef->name, actualDev);
- goto cleanup;
+ goto error;
}
/* we are now assured of success, so mark the allocation */
dev->connections++;
dev->dev, dev->connections);
}
+success:
ret = 0;
cleanup:
if (network)
virNetworkObjUnlock(network);
return ret;
+
+error:
+ goto cleanup;
}
networkReleaseActualDevice(virDomainNetDefPtr iface)
{
struct network_driver *driver = driverState;
- virNetworkObjPtr network = NULL;
+ virNetworkObjPtr network;
virNetworkDefPtr netdef;
const char *actualDev;
int ret = -1;
if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK)
return 0;
- if (!iface->data.network.actual ||
- (virDomainNetGetActualType(iface) != VIR_DOMAIN_NET_TYPE_DIRECT)) {
- VIR_DEBUG("Nothing to release to network %s", iface->data.network.name);
- ret = 0;
- goto cleanup;
- }
-
networkDriverLock(driver);
network = virNetworkFindByName(&driver->networks, iface->data.network.name);
networkDriverUnlock(driver);
virReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"),
iface->data.network.name);
- goto cleanup;
+ goto error;
+ }
+ netdef = network->def;
+
+ if (!iface->data.network.actual ||
+ (virDomainNetGetActualType(iface) != VIR_DOMAIN_NET_TYPE_DIRECT)) {
+ VIR_DEBUG("Nothing to release to network %s", iface->data.network.name);
+ goto success;
}
actualDev = virDomainNetGetActualDirectDev(iface);
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("the interface uses a direct "
"mode, but has no source dev"));
- goto cleanup;
+ goto error;
}
- netdef = network->def;
if (netdef->nForwardIfs == 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("network '%s' uses a direct mode, but "
"has no forward dev and no interface pool"),
netdef->name);
- goto cleanup;
+ goto error;
} else {
int ii;
virNetworkForwardIfDefPtr dev = NULL;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("network '%s' doesn't have dev='%s' in use by domain"),
netdef->name, actualDev);
- goto cleanup;
+ goto error;
}
dev->connections--;
dev->dev, dev->connections);
}
+success:
ret = 0;
cleanup:
if (network)
virNetworkObjUnlock(network);
- virDomainActualNetDefFree(iface->data.network.actual);
- iface->data.network.actual = NULL;
+ if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
+ virDomainActualNetDefFree(iface->data.network.actual);
+ iface->data.network.actual = NULL;
+ }
return ret;
+
+error:
+ goto cleanup;
}
/*
{
int ret = -1;
struct network_driver *driver = driverState;
- virNetworkObjPtr network = NULL;
+ virNetworkObjPtr network;
virNetworkDefPtr netdef;
virNetworkIpDefPtr ipdef;
virSocketAddr addr;
virReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"),
netname);
- goto cleanup;
+ goto error;
}
netdef = network->def;
if (dev_name) {
if (virNetDevGetIPv4Address(dev_name, &addr) < 0)
- goto cleanup;
-
+ goto error;
addrptr = &addr;
}
- if (addrptr &&
- (*netaddr = virSocketAddrFormat(addrptr))) {
- ret = 0;
+ if (!(addrptr &&
+ (*netaddr = virSocketAddrFormat(addrptr)))) {
+ goto error;
}
+ ret = 0;
cleanup:
if (network)
virNetworkObjUnlock(network);
return ret;
+
+error:
+ goto cleanup;
}