On 2012年06月25日 19:35, Shradha Shah wrote:
Just code movement no functional changes here. This makes the code
reusable
Signed-off-by: Shradha Shah<sshah(a)solarflare.com>
---
src/network/bridge_driver.c | 84 ++++++++++++++++++++++++++----------------
1 files changed, 52 insertions(+), 32 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 79d3010..7d853c6 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2731,6 +2731,56 @@ 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) {
+ networkReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not get Virtual functions on %s"),
+ netdef->forwardPfs->dev);
+ goto finish;
+ }
+
+ if (num_virt_fns == 0) {
+ networkReportError(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;
+ }
+ netdef->forwardIfs[ii].usageCount = 0;
+ }
+
+ 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
*
@@ -2749,8 +2799,6 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
virNetworkObjPtr network;
virNetworkDefPtr netdef;
virPortGroupDefPtr portgroup;
- unsigned int num_virt_fns = 0;
- char **vfname = NULL;
int ii;
int ret = -1;
@@ -2896,36 +2944,11 @@ 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) {
+ if ((networkCreateInterfacePool(netdef))< 0) {
networkReportError(VIR_ERR_INTERNAL_ERROR,
- _("Could not get Virtual functions on
%s"),
- netdef->forwardPfs->dev);
+ _("Could not Interface Pool"));
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 */
@@ -2977,9 +3000,6 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
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) {
Just move existed codes outside, and Looks good, ACK.
Osier