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

David Kiarie davidkiarie4 at gmail.com
Thu Jul 10 13:43:09 UTC 2014


From: Kiarie Kahurani <davidkiarie4 at gmail.com>

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

signed-of-by: David Kiarie<davidkiarie4 at gmail.com>
---
 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




More information about the libvir-list mailing list