/*
* bridge_driver.c: core driver methods for managing network
*
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
virNetworkObjPtr network;
virNetworkDefPtr netdef;
virPortGroupDefPtr portgroup;
+ unsigned int num_virt_fns = 0;
+ char **vfname = NULL;
+ int ii;
int ret = -1;
if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK)
/* If there is only a single device, just return it (caller will detect
* any error if exclusive use is required but could not be acquired).
*/
- if (netdef->nForwardIfs == 0) {
+ if ((netdef->nForwardIfs <= 0) && (netdef->nForwardPfs <= 0)) {
networkReportError(VIR_ERR_INTERNAL_ERROR,
_("network '%s' uses a direct mode, but has no forward dev and no interface pool"),
netdef->name);
goto cleanup;
} else {
- int ii;
virNetworkForwardIfDefPtr dev = NULL;
/* pick an interface from the pool */
* 0. Other modes can share, so just search for the one with
* the lowest usageCount.
*/
- if ((netdef->forwardType == VIR_NETWORK_FORWARD_PASSTHROUGH) ||
- ((netdef->forwardType == VIR_NETWORK_FORWARD_PRIVATE) &&
- iface->data.network.actual->data.direct.virtPortProfile &&
- (iface->data.network.actual->data.direct.virtPortProfile->virtPortType
- == VIR_NETDEV_VPORT_PROFILE_8021QBH))) {
+ if (netdef->forwardType == VIR_NETWORK_FORWARD_PASSTHROUGH) {
+ if ((netdef->nForwardPfs > 0) && (netdef->nForwardIfs <= 0)) {
+ if ((virNetDevGetVirtualFunctions(netdef->forwardPfs->dev,
+ &vfname, &num_virt_fns)) < 0) {
+ networkReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not get Virtual functions on %s"),
+ netdef->forwardPfs->dev);
+ goto cleanup;
+ }
+
+ if (num_virt_fns == 0) {
+ networkReportError(VIR_ERR_INTERNAL_ERROR,
+ _("No Vf's present on SRIOV PF %s"),
+ netdef->forwardPfs->dev);
+ goto cleanup;
+ }
+
+ if ((VIR_ALLOC_N(netdef->forwardIfs, num_virt_fns)) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ netdef->nForwardIfs = num_virt_fns;
+
+ for (ii = 0; ii < netdef->nForwardIfs; ii++) {
+ netdef->forwardIfs[ii].dev = strdup(vfname[ii]);
+ if (!netdef->forwardIfs[ii].dev) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ netdef->forwardIfs[ii].usageCount = 0;
+ }
+ }
+
/* pick first dev with 0 usageCount */
+ for (ii = 0; ii < netdef->nForwardIfs; ii++) {
+ if (netdef->forwardIfs[ii].usageCount == 0) {
+ dev = &netdef->forwardIfs[ii];
+ break;
+ }
+ }
+ } else if ((netdef->forwardType == VIR_NETWORK_FORWARD_PRIVATE) &&
+ iface->data.network.actual->data.direct.virtPortProfile &&
+ (iface->data.network.actual->data.direct.virtPortProfile->virtPortType
+ == VIR_NETDEV_VPORT_PROFILE_8021QBH)) {
+
+ /* pick first dev with 0 usageCount */
for (ii = 0; ii < netdef->nForwardIfs; ii++) {
if (netdef->forwardIfs[ii].usageCount == 0) {
dev = &netdef->forwardIfs[ii];
if (!dev) {
networkReportError(VIR_ERR_INTERNAL_ERROR,
_("network '%s' requires exclusive access to interfaces, but none are available"),
- netdef->name);
+ netdef->name);
goto cleanup;
}
iface->data.network.actual->data.direct.linkdev = strdup(dev->dev);
ret = 0;
cleanup:
+ for (ii = 0; ii < num_virt_fns; ii++)
+ VIR_FREE(vfname[ii]);
+ VIR_FREE(vfname);
if (network)
virNetworkObjUnlock(network);
if (ret < 0) {