diff options
author | Shradha Shah <sshah@solarflare.com> | 2012-08-16 16:41:24 +0100 |
---|---|---|
committer | Laine Stump <laine@laine.org> | 2012-08-17 15:43:25 -0400 |
commit | 1494897bac16d95dbb3dffe3c368cffe257fad7c (patch) | |
tree | 44deddf59955632901eeb0c9041640f4c1fd8308 /src/network | |
parent | conf: move DevicePCIAddress functions to separate file (diff) | |
download | libvirt-1494897bac16d95dbb3dffe3c368cffe257fad7c.tar.gz libvirt-1494897bac16d95dbb3dffe3c368cffe257fad7c.tar.bz2 libvirt-1494897bac16d95dbb3dffe3c368cffe257fad7c.zip |
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>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/bridge_driver.c | 82 |
1 files changed, 50 insertions, 32 deletions
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index a78e3b6eb..561964053 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2771,6 +2771,55 @@ int networkRegister(void) { * "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: * @iface: the original NetDef from the domain * @@ -2793,8 +2842,6 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) virNetDevVPortProfilePtr virtport = iface->virtPortProfile; virNetDevVlanPtr vlan = NULL; virNetworkForwardIfDefPtr dev = NULL; - unsigned int num_virt_fns = 0; - char **vfname = NULL; int ii; int ret = -1; @@ -2969,35 +3016,9 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) */ if (netdef->forwardType == VIR_NETWORK_FORWARD_PASSTHROUGH) { if ((netdef->nForwardPfs > 0) && (netdef->nForwardIfs <= 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 error; - } - - if (num_virt_fns == 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("No Vf's present on SRIOV PF %s"), - netdef->forwardPfs->dev); + if ((networkCreateInterfacePool(netdef)) < 0) { 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 */ @@ -3105,9 +3126,6 @@ validate: ret = 0; cleanup: - for (ii = 0; ii < num_virt_fns; ii++) - VIR_FREE(vfname[ii]); - VIR_FREE(vfname); if (network) virNetworkObjUnlock(network); return ret; |