[libvirt] [PATCH v2 19/25] src/xenxs:Refactor code formating Vfb config

David Kiarie davidkiarie4 at gmail.com
Sat Jul 26 09:40:05 UTC 2014


From: Kiarie Kahurani <davidkiarie4 at gmail.com>

introduce function
 xenFormatXMVfb(virConfPtr conf, ........);
which formats Vfb config instead

signed-off-by: David Kiarie<davidkiarie4 at gmail.com>
---
 src/xenxs/xen_xm.c | 218 +++++++++++++++++++++++++++++------------------------
 1 file changed, 119 insertions(+), 99 deletions(-)

diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 9a6a827..22552bd 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -1838,6 +1838,123 @@ int xenFormatXMVif(virConfPtr conf, virConnectPtr conn,
 }
 
 
+static
+int xenFormatXMVfb(virConfPtr conf, virDomainDefPtr def,
+                   int xendConfigVersion)
+{
+    int hvm = STREQ(def->os.type, "hvm");
+
+    if (def->ngraphics == 1) {
+        if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
+            if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
+                if (xenXMConfigSetInt(conf, "sdl", 1) < 0)
+                    return -1;
+
+                if (xenXMConfigSetInt(conf, "vnc", 0) < 0)
+                    return -1;
+
+                if (def->graphics[0]->data.sdl.display &&
+                    xenXMConfigSetString(conf, "display",
+                                     def->graphics[0]->data.sdl.display) < 0)
+                    return -1;
+
+                if (def->graphics[0]->data.sdl.xauth &&
+                    xenXMConfigSetString(conf, "xauthority",
+                                         def->graphics[0]->data.sdl.xauth) < 0)
+                    return -1;
+
+            } else {
+                const char *listenAddr;
+
+                if (xenXMConfigSetInt(conf, "sdl", 0) < 0)
+                    return -1;
+
+                if (xenXMConfigSetInt(conf, "vnc", 1) < 0)
+                    return -1;
+
+                if (xenXMConfigSetInt(conf, "vncunused",
+                              def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0)
+                    return -1;
+
+                if (!def->graphics[0]->data.vnc.autoport &&
+                    xenXMConfigSetInt(conf, "vncdisplay",
+                                  def->graphics[0]->data.vnc.port - 5900) < 0)
+                    return -1;
+
+                listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
+                if (listenAddr &&
+                    xenXMConfigSetString(conf, "vnclisten", listenAddr) < 0)
+                    return -1;
+
+                if (def->graphics[0]->data.vnc.auth.passwd &&
+                    xenXMConfigSetString(conf, "vncpasswd",
+                                        def->graphics[0]->data.vnc.auth.passwd) < 0)
+                    return -1;
+
+                if (def->graphics[0]->data.vnc.keymap &&
+                    xenXMConfigSetString(conf, "keymap",
+                                        def->graphics[0]->data.vnc.keymap) < 0)
+                    return -1;
+            }
+        } else {
+            virConfValuePtr vfb, disp;
+            char *vfbstr = NULL;
+            virBuffer buf = VIR_BUFFER_INITIALIZER;
+            if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
+                virBufferAddLit(&buf, "type=sdl");
+                if (def->graphics[0]->data.sdl.display)
+                    virBufferAsprintf(&buf, ",display=%s",
+                                      def->graphics[0]->data.sdl.display);
+                if (def->graphics[0]->data.sdl.xauth)
+                    virBufferAsprintf(&buf, ",xauthority=%s",
+                                      def->graphics[0]->data.sdl.xauth);
+            } else {
+                const char *listenAddr
+                    = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
+
+                virBufferAddLit(&buf, "type=vnc");
+                virBufferAsprintf(&buf, ",vncunused=%d",
+                                  def->graphics[0]->data.vnc.autoport ? 1 : 0);
+                if (!def->graphics[0]->data.vnc.autoport)
+                    virBufferAsprintf(&buf, ",vncdisplay=%d",
+                                      def->graphics[0]->data.vnc.port - 5900);
+                if (listenAddr)
+                    virBufferAsprintf(&buf, ",vnclisten=%s", listenAddr);
+                if (def->graphics[0]->data.vnc.auth.passwd)
+                    virBufferAsprintf(&buf, ",vncpasswd=%s",
+                                      def->graphics[0]->data.vnc.auth.passwd);
+                if (def->graphics[0]->data.vnc.keymap)
+                    virBufferAsprintf(&buf, ",keymap=%s",
+                                      def->graphics[0]->data.vnc.keymap);
+            }
+
+            if (virBufferCheckError(&buf) < 0)
+                return -1;
+
+            vfbstr = virBufferContentAndReset(&buf);
+            if (VIR_ALLOC(vfb) < 0) {
+                VIR_FREE(vfbstr);
+                return -1;
+            }
+
+            if (VIR_ALLOC(disp) < 0) {
+                VIR_FREE(vfb);
+                VIR_FREE(vfbstr);
+                return -1;
+            }
+
+            vfb->type = VIR_CONF_LIST;
+            vfb->list = disp;
+            disp->type = VIR_CONF_STRING;
+            disp->str = vfbstr;
+
+            if (virConfSetValue(conf, "vfb", vfb) < 0)
+                return -1;
+        }
+    }
+
+    return 0;
+}
 virConfPtr xenFormatXM(virConnectPtr conn, virDomainDefPtr def,
                        int xendConfigVersion)
 {
@@ -2008,105 +2125,8 @@ virConfPtr xenFormatXM(virConnectPtr conn, virDomainDefPtr def,
         }
     }
 
-    if (def->ngraphics == 1) {
-        if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
-            if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
-                if (xenXMConfigSetInt(conf, "sdl", 1) < 0)
-                    goto cleanup;
-                if (xenXMConfigSetInt(conf, "vnc", 0) < 0)
-                    goto cleanup;
-                if (def->graphics[0]->data.sdl.display &&
-                    xenXMConfigSetString(conf, "display",
-                                     def->graphics[0]->data.sdl.display) < 0)
-                    goto cleanup;
-                if (def->graphics[0]->data.sdl.xauth &&
-                    xenXMConfigSetString(conf, "xauthority",
-                                         def->graphics[0]->data.sdl.xauth) < 0)
-                    goto cleanup;
-            } else {
-                const char *listenAddr;
-
-                if (xenXMConfigSetInt(conf, "sdl", 0) < 0)
-                    goto cleanup;
-                if (xenXMConfigSetInt(conf, "vnc", 1) < 0)
-                    goto cleanup;
-                if (xenXMConfigSetInt(conf, "vncunused",
-                              def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0)
-                    goto cleanup;
-                if (!def->graphics[0]->data.vnc.autoport &&
-                    xenXMConfigSetInt(conf, "vncdisplay",
-                                  def->graphics[0]->data.vnc.port - 5900) < 0)
-                    goto cleanup;
-                listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
-                if (listenAddr &&
-                    xenXMConfigSetString(conf, "vnclisten", listenAddr) < 0)
-                    goto cleanup;
-                if (def->graphics[0]->data.vnc.auth.passwd &&
-                    xenXMConfigSetString(conf, "vncpasswd",
-                                        def->graphics[0]->data.vnc.auth.passwd) < 0)
-                    goto cleanup;
-                if (def->graphics[0]->data.vnc.keymap &&
-                    xenXMConfigSetString(conf, "keymap",
-                                        def->graphics[0]->data.vnc.keymap) < 0)
-                    goto cleanup;
-            }
-        } else {
-            virConfValuePtr vfb, disp;
-            char *vfbstr = NULL;
-            virBuffer buf = VIR_BUFFER_INITIALIZER;
-            if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
-                virBufferAddLit(&buf, "type=sdl");
-                if (def->graphics[0]->data.sdl.display)
-                    virBufferAsprintf(&buf, ",display=%s",
-                                      def->graphics[0]->data.sdl.display);
-                if (def->graphics[0]->data.sdl.xauth)
-                    virBufferAsprintf(&buf, ",xauthority=%s",
-                                      def->graphics[0]->data.sdl.xauth);
-            } else {
-                const char *listenAddr
-                    = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
-
-                virBufferAddLit(&buf, "type=vnc");
-                virBufferAsprintf(&buf, ",vncunused=%d",
-                                  def->graphics[0]->data.vnc.autoport ? 1 : 0);
-                if (!def->graphics[0]->data.vnc.autoport)
-                    virBufferAsprintf(&buf, ",vncdisplay=%d",
-                                      def->graphics[0]->data.vnc.port - 5900);
-                if (listenAddr)
-                    virBufferAsprintf(&buf, ",vnclisten=%s", listenAddr);
-                if (def->graphics[0]->data.vnc.auth.passwd)
-                    virBufferAsprintf(&buf, ",vncpasswd=%s",
-                                      def->graphics[0]->data.vnc.auth.passwd);
-                if (def->graphics[0]->data.vnc.keymap)
-                    virBufferAsprintf(&buf, ",keymap=%s",
-                                      def->graphics[0]->data.vnc.keymap);
-            }
-            if (virBufferCheckError(&buf) < 0)
-                goto cleanup;
-
-            vfbstr = virBufferContentAndReset(&buf);
-
-            if (VIR_ALLOC(vfb) < 0) {
-                VIR_FREE(vfbstr);
-                goto cleanup;
-            }
-
-            if (VIR_ALLOC(disp) < 0) {
-                VIR_FREE(vfb);
-                VIR_FREE(vfbstr);
-                goto cleanup;
-            }
-
-            vfb->type = VIR_CONF_LIST;
-            vfb->list = disp;
-            disp->type = VIR_CONF_STRING;
-            disp->str = vfbstr;
-
-            if (virConfSetValue(conf, "vfb", vfb) < 0)
-                goto cleanup;
-        }
-    }
-
+    if (xenFormatXMVfb(conf, def, xendConfigVersion) < 0)
+        goto cleanup;
     /* analyze of the devices */
     if (VIR_ALLOC(diskVal) < 0)
         goto cleanup;
-- 
1.8.4.5




More information about the libvir-list mailing list