[PATCH 2/6 v3] Moved the code to create implicit interface pool from PF to a new function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just code movement no functional changes here. This makes the code reusable

Signed-off-by: Shradha Shah <sshah@xxxxxxxxxxxxxx>
---
 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 7e8de19..36afa1b 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2730,6 +2730,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
  *
@@ -2748,8 +2798,6 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
     virNetworkObjPtr network;
     virNetworkDefPtr netdef;
     virPortGroupDefPtr portgroup;
-    unsigned int num_virt_fns = 0;
-    char **vfname = NULL;
     int ii;
     int ret = -1;
 
@@ -2895,36 +2943,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 */
@@ -2976,9 +2999,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) {
-- 
1.7.4.4


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]