]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src/xenxs: Refactor code formating vif device config
authorJim Fehlig <jfehlig@suse.com>
Wed, 13 Aug 2014 20:46:16 +0000 (14:46 -0600)
committerJim Fehlig <jfehlig@suse.com>
Thu, 14 Aug 2014 17:49:53 +0000 (11:49 -0600)
Handle formating of VIF config in a new function xenFormatXMVif().

Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com>
src/xenxs/xen_xm.c

index 2f7918252c137d197e1f14a3ab126d6e085cdf80..292903e51423b50bccb1d58aaabfaf227c0fc971 100644 (file)
@@ -2308,6 +2308,43 @@ xenFormatXMInputDevs(virConfPtr conf, virDomainDefPtr def)
 }
 
 
+static int
+xenFormatXMVif(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)
+           goto cleanup;
+    }
+
+    if (netVal->list != NULL) {
+        int ret = virConfSetValue(conf, "vif", netVal);
+        netVal = NULL;
+        if (ret < 0)
+            goto cleanup;
+    }
+
+    VIR_FREE(netVal);
+    return 0;
+
+ cleanup:
+    virConfFreeValue(netVal);
+    return -1;
+}
+
+
 /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
    either 32, or 64 on a platform where long is big enough.  */
 verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT);
@@ -2318,9 +2355,6 @@ xenFormatXM(virConnectPtr conn,
             int xendConfigVersion)
 {
     virConfPtr conf = NULL;
-    int hvm = STREQ(def->os.type, "hvm") ? 1 : 0;
-    size_t i;
-    virConfValuePtr netVal = NULL;
 
     if (!(conf = virConfNew()))
         goto cleanup;
@@ -2361,23 +2395,8 @@ xenFormatXM(virConnectPtr conn,
     if (xenFormatXMDisks(conf, def, xendConfigVersion) < 0)
         goto cleanup;
 
-    if (VIR_ALLOC(netVal) < 0)
+    if (xenFormatXMVif(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;
@@ -2391,7 +2410,6 @@ xenFormatXM(virConnectPtr conn,
     return conf;
 
  cleanup:
-    virConfFreeValue(netVal);
     if (conf)
         virConfFree(conf);
     return NULL;