virDomainNetAllocateActualDevice(virDomainDefPtr dom,
virDomainNetDefPtr iface)
{
- /* Just silently ignore if network driver isn't present. If something
- * has tried to use a NIC with type=network, other code will already
- * cause an error. This ensures type=bridge doesn't break when
- * network driver is compiled out.
- */
- if (!netAllocate)
- return 0;
+ if (!netAllocate) {
+ virReportError(VIR_ERR_NO_SUPPORT, "%s",
+ _("Virtual networking driver is not available"));
+ return -1;
+ }
return netAllocate(dom, iface);
}
virDomainNetBandwidthChangeAllowed(virDomainNetDefPtr iface,
virNetDevBandwidthPtr newBandwidth)
{
- if (!netBandwidthChangeAllowed)
- return 0;
+ if (!netBandwidthChangeAllowed) {
+ virReportError(VIR_ERR_NO_SUPPORT, "%s",
+ _("Virtual networking driver is not available"));
+ return -1;
+ }
return netBandwidthChangeAllowed(iface, newBandwidth);
}
virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
virNetDevBandwidthPtr newBandwidth)
{
- if (!netBandwidthUpdate)
- return 0;
+ if (!netBandwidthUpdate) {
+ virReportError(VIR_ERR_NO_SUPPORT, "%s",
+ _("Virtual networking driver is not available"));
+ return -1;
+ }
return netBandwidthUpdate(iface, newBandwidth);
}
/* cleanup actual device */
virDomainNetRemoveHostdev(vm->def, net);
- virDomainNetReleaseActualDevice(vm->def, net);
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(vm->def, net);
}
}
* network's pool of devices, or resolve bridge device name
* to the one defined in the network definition.
*/
- if (virDomainNetAllocateActualDevice(def, net) < 0)
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
+ virDomainNetAllocateActualDevice(def, net) < 0)
return -1;
actualType = virDomainNetGetActualType(net);
* network's pool of devices, or resolve bridge device name
* to the one defined in the network definition.
*/
- if (virDomainNetAllocateActualDevice(vm->def, net) < 0)
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
+ virDomainNetAllocateActualDevice(vm->def, net) < 0)
goto cleanup;
actualType = virDomainNetGetActualType(net);
vm->def->nets[vm->def->nnets++] = net;
} else {
virDomainNetRemoveHostdev(vm->def, net);
- virDomainNetReleaseActualDevice(vm->def, net);
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(vm->def, net);
}
virObjectUnref(cfg);
return ret;
cleanup:
libxl_device_nic_dispose(&nic);
if (!ret) {
- virDomainNetReleaseActualDevice(vm->def, detach);
+ if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(vm->def, detach);
virDomainNetRemove(vm->def, detachidx);
}
virObjectUnref(cfg);
* network's pool of devices, or resolve bridge device name
* to the one defined in the network definition.
*/
- if (virDomainNetAllocateActualDevice(vm->def, net) < 0)
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
+ virDomainNetAllocateActualDevice(vm->def, net) < 0)
return -1;
actualType = virDomainNetGetActualType(net);
ret = 0;
cleanup:
if (!ret) {
- virDomainNetReleaseActualDevice(vm->def, detach);
+ if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(vm->def, detach);
virDomainNetRemove(vm->def, detachidx);
virDomainNetDefFree(detach);
}
iface->ifname));
ignore_value(virNetDevVethDelete(iface->ifname));
}
- virDomainNetReleaseActualDevice(vm->def, iface);
+ if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(vm->def, iface);
}
virDomainConfVMNWFilterTeardown(vm);
if (virLXCProcessValidateInterface(net) < 0)
goto cleanup;
- if (virDomainNetAllocateActualDevice(def, net) < 0)
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
+ virDomainNetAllocateActualDevice(def, net) < 0)
goto cleanup;
type = virDomainNetGetActualType(net);
ignore_value(virNetDevOpenvswitchRemovePort(
virDomainNetGetActualBridgeName(iface),
iface->ifname));
- virDomainNetReleaseActualDevice(def, iface);
+ if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(def, iface);
}
}
return ret;
size_t i;
int ret = -1;
- if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK)
- goto validate;
+ if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Expected an interface for a virtual network"));
+ goto error;
+ }
virDomainActualNetDefFree(iface->data.network.actual);
iface->data.network.actual = NULL;
if (virNetDevVPortProfileCheckComplete(virtport, true) < 0)
goto error;
- validate:
/* make sure that everything now specified for the device is
* actually supported on this type of network. NB: network,
* netdev, and iface->data.network.actual may all be NULL.
(actualType == VIR_DOMAIN_NET_TYPE_BRIDGE &&
virtport && virtport->virtPortType
== VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH))) {
- if (netdef) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("an interface connecting to network '%s' "
- "is requesting a vlan tag, but that is not "
- "supported for this type of network"),
- netdef->name);
- } else {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("an interface of type '%s' "
- "is requesting a vlan tag, but that is not "
- "supported for this type of connection"),
- virDomainNetTypeToString(iface->type));
- }
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("an interface connecting to network '%s' "
+ "is requesting a vlan tag, but that is not "
+ "supported for this type of network"),
+ netdef->name);
goto error;
}
}
}
}
- if (netdef) {
- netdef->connections++;
+ netdef->connections++;
+ if (dev)
+ dev->connections++;
+ /* finally we can call the 'plugged' hook script if any */
+ if (networkRunHook(obj, dom, iface,
+ VIR_HOOK_NETWORK_OP_IFACE_PLUGGED,
+ VIR_HOOK_SUBOP_BEGIN) < 0) {
+ /* adjust for failure */
+ netdef->connections--;
if (dev)
- dev->connections++;
- /* finally we can call the 'plugged' hook script if any */
- if (networkRunHook(obj, dom, iface,
- VIR_HOOK_NETWORK_OP_IFACE_PLUGGED,
- VIR_HOOK_SUBOP_BEGIN) < 0) {
- /* adjust for failure */
- netdef->connections--;
- if (dev)
- dev->connections--;
- goto error;
- }
- networkLogAllocation(netdef, actualType, dev, iface, true);
+ dev->connections--;
+ goto error;
}
+ networkLogAllocation(netdef, actualType, dev, iface, true);
ret = 0;
size_t i;
char *master = NULL;
- if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK)
- return;
+ if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Expected an interface for a virtual network"));
+ goto error;
+ }
obj = virNetworkObjFindByName(driver->networks, iface->data.network.name);
if (!obj) {
size_t i;
int ret = -1;
- if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK)
- return 0;
+ if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Expected an interface for a virtual network"));
+ goto error;
+ }
obj = virNetworkObjFindByName(driver->networks, iface->data.network.name);
if (!obj) {
int plug_ret;
int ret = -1;
+ if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Expected an interface for a virtual network"));
+ return -1;
+ }
+
if (!networkBandwidthGenericChecks(iface, newBandwidth))
return 0;
sizeof(*newBandwidth->out));
}
- if (!virDomainNetBandwidthChangeAllowed(net, newBandwidth))
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
+ !virDomainNetBandwidthChangeAllowed(net, newBandwidth))
goto endjob;
if (virNetDevBandwidthSet(net->ifname, newBandwidth, false,
!virDomainNetTypeSharesHostView(net)) < 0 ||
- virDomainNetBandwidthUpdate(net, newBandwidth) < 0) {
+ (net->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
+ virDomainNetBandwidthUpdate(net, newBandwidth) < 0)) {
ignore_value(virNetDevBandwidthSet(net->ifname,
net->bandwidth,
false,
* network's pool of devices, or resolve bridge device name
* to the one defined in the network definition.
*/
- if (virDomainNetAllocateActualDevice(vm->def, net) < 0)
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
+ virDomainNetAllocateActualDevice(vm->def, net) < 0)
goto cleanup;
actualType = virDomainNetGetActualType(net);
virDomainNetRemoveHostdev(vm->def, net);
- virDomainNetReleaseActualDevice(vm->def, net);
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(vm->def, net);
}
VIR_FREE(nicstr);
/* this function doesn't work with HOSTDEV networks yet, thus
* no need to change the pointer in the hostdev structure */
- virDomainNetReleaseActualDevice(vm->def, olddev);
+ if (olddev->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(vm->def, olddev);
virDomainNetDefFree(olddev);
/* move newdev into the nets list, and NULL it out from the
* virDomainDeviceDef that we were given so that the caller
* that the changes were minor enough that we didn't need to
* replace the entire device object.
*/
- if (newdev)
+ if (newdev && newdev->type == VIR_DOMAIN_NET_TYPE_NETWORK)
virDomainNetReleaseActualDevice(vm->def, newdev);
return ret;
virDomainHostdevDefFree(hostdev);
if (net) {
- virDomainNetReleaseActualDevice(vm->def, net);
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(vm->def, net);
virDomainNetDefFree(net);
}
qemuDomainNetDeviceVportRemove(net);
- virDomainNetReleaseActualDevice(vm->def, net);
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(vm->def, net);
virDomainNetDefFree(net);
ret = 0;
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT)
ignore_value(virNetDevMacVLanReserveName(net->ifname, false));
- virDomainNetNotifyActualDevice(def, net);
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetNotifyActualDevice(def, net);
}
}
* network's pool of devices, or resolve bridge device name
* to the one defined in the network definition.
*/
- if (virDomainNetAllocateActualDevice(def, net) < 0)
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
+ virDomainNetAllocateActualDevice(def, net) < 0)
goto cleanup;
actualType = virDomainNetGetActualType(net);
/* kick the device out of the hostdev list too */
virDomainNetRemoveHostdev(def, net);
- virDomainNetReleaseActualDevice(vm->def, net);
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK)
+ virDomainNetReleaseActualDevice(vm->def, net);
}
retry: