[PREPOST 15/17] src/xenxs:Refactor Vif formating code

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

 



From: Kiarie Kahurani <davidkiarie4@xxxxxxxxx>

Introduce the function
 xenFormatXMDomainNet(......)
I think this could be done in a cleaner way

signed-of-by: David Kiarie<davidkiarie4@xxxxxxxxx>
---
 src/xenxs/xen_xm.c | 49 +++++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index ee5dc19..8dd2823 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -1821,6 +1821,36 @@ static int xenFormatXMCharDev(virConfPtr conf, virDomainDefPtr def)
 cleanup:
     return -1;
 }
+static int xenFormatXMDomainNet(virConfPtr conf, virConnectPtr conn,
+                         virDomainDefPtr def, int xendConfigVersion)
+{
+   virConfValuePtr netVal = NULL;
+   size_t i;
+
+   int hvm = STREQ(def->os.type, "hvm");
+
+   if (VIR_ALLOC(netVal) < 0)
+        goto cleanup;
+    netVal->type = VIR_CONF_LIST;
+    netVal->list = NULL;
+
+    for (i = 0; i < def->nnets; i++) {
+        if (xenFormatXMNet(conn, netVal, def->nets[i],
+                           hvm, xendConfigVersion) < 0)
+           return -1;
+    }
+    if (netVal->list != NULL) {
+        int ret = virConfSetValue(conf, "vif", netVal);
+        netVal = NULL;
+        if (ret < 0)
+            return -1;
+    }
+    VIR_FREE(netVal);
+    return 0;
+ cleanup:
+    VIR_FREE(netVal);
+    return -1;
+}
 virConfPtr xenFormatXM(virConnectPtr conn,
                                    virDomainDefPtr def,
                                    int xendConfigVersion)
@@ -2124,25 +2154,8 @@ virConfPtr xenFormatXM(virConnectPtr conn,
             goto cleanup;
     }
     VIR_FREE(diskVal);
-
-    if (VIR_ALLOC(netVal) < 0)
+    if (xenFormatXMDomainNet(conf, conn, def, xendConfigVersion) < 0)
         goto cleanup;
-    netVal->type = VIR_CONF_LIST;
-    netVal->list = NULL;
-
-    for (i = 0; i < def->nnets; i++) {
-        if (xenFormatXMNet(conn, netVal, def->nets[i],
-                           hvm, xendConfigVersion) < 0)
-            goto cleanup;
-    }
-    if (netVal->list != NULL) {
-        int ret = virConfSetValue(conf, "vif", netVal);
-        netVal = NULL;
-        if (ret < 0)
-            goto cleanup;
-    }
-    VIR_FREE(netVal);
-
     if (xenFormatXMPCI(conf, def) < 0)
         goto cleanup;
 
-- 
1.8.4.5

--
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]