network: helper function to create interface pool from PF

Existing code that creates a list of forwardIfs from a single PF
was moved to the new utility function networkCreateInterfacePool.
No functional change.

Signed-off-by: Shradha Shah <sshah@solarflare.com>
This commit is contained in:
Shradha Shah 2012-08-16 16:41:24 +01:00 committed by Laine Stump
parent f9150c8158
commit 1494897bac

View File

@ -2771,6 +2771,55 @@ int networkRegister(void) {
* "backend" function table. * "backend" function table.
*/ */
/* networkCreateInterfacePool:
* @netdef: the original NetDef from the network
*
* Creates an implicit interface pool of VF's when a PF dev is given
*/
static int
networkCreateInterfacePool(virNetworkDefPtr netdef) {
unsigned int num_virt_fns = 0;
char **vfname = NULL;
int ret = -1, ii = 0;
if ((virNetDevGetVirtualFunctions(netdef->forwardPfs->dev,
&vfname, &num_virt_fns)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get Virtual functions on %s"),
netdef->forwardPfs->dev);
goto finish;
}
if (num_virt_fns == 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("No Vf's present on SRIOV PF %s"),
netdef->forwardPfs->dev);
goto finish;
}
if ((VIR_ALLOC_N(netdef->forwardIfs, num_virt_fns)) < 0) {
virReportOOMError();
goto finish;
}
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 finish;
}
}
ret = 0;
finish:
for (ii = 0; ii < num_virt_fns; ii++)
VIR_FREE(vfname[ii]);
VIR_FREE(vfname);
return ret;
}
/* networkAllocateActualDevice: /* networkAllocateActualDevice:
* @iface: the original NetDef from the domain * @iface: the original NetDef from the domain
* *
@ -2793,8 +2842,6 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
virNetDevVPortProfilePtr virtport = iface->virtPortProfile; virNetDevVPortProfilePtr virtport = iface->virtPortProfile;
virNetDevVlanPtr vlan = NULL; virNetDevVlanPtr vlan = NULL;
virNetworkForwardIfDefPtr dev = NULL; virNetworkForwardIfDefPtr dev = NULL;
unsigned int num_virt_fns = 0;
char **vfname = NULL;
int ii; int ii;
int ret = -1; int ret = -1;
@ -2969,35 +3016,9 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
*/ */
if (netdef->forwardType == VIR_NETWORK_FORWARD_PASSTHROUGH) { if (netdef->forwardType == VIR_NETWORK_FORWARD_PASSTHROUGH) {
if ((netdef->nForwardPfs > 0) && (netdef->nForwardIfs <= 0)) { if ((netdef->nForwardPfs > 0) && (netdef->nForwardIfs <= 0)) {
if ((virNetDevGetVirtualFunctions(netdef->forwardPfs->dev, if ((networkCreateInterfacePool(netdef)) < 0) {
&vfname, &num_virt_fns)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get Virtual functions on %s"),
netdef->forwardPfs->dev);
goto error; goto error;
} }
if (num_virt_fns == 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("No Vf's present on SRIOV PF %s"),
netdef->forwardPfs->dev);
goto error;
}
if ((VIR_ALLOC_N(netdef->forwardIfs, num_virt_fns)) < 0) {
virReportOOMError();
goto error;
}
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 error;
}
}
} }
/* pick first dev with 0 connections */ /* pick first dev with 0 connections */
@ -3105,9 +3126,6 @@ validate:
ret = 0; ret = 0;
cleanup: cleanup:
for (ii = 0; ii < num_virt_fns; ii++)
VIR_FREE(vfname[ii]);
VIR_FREE(vfname);
if (network) if (network)
virNetworkObjUnlock(network); virNetworkObjUnlock(network);
return ret; return ret;