]> xenbits.xensource.com Git - libvirt.git/commitdiff
domain_conf: introduce virDomainGraphicsListenAppendAddress
authorPavel Hrdina <phrdina@redhat.com>
Wed, 23 Mar 2016 07:55:46 +0000 (08:55 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 13 Apr 2016 08:43:49 +0000 (10:43 +0200)
This effectively removes virDomainGraphicsListenSetAddress which was
used only to change the address of listen structure and possible change
the listen type.  The new function will auto-expand the listens array
and append a new listen.

The old function was used on pre-allocated array of listens and in most
cases it only "add" a new listen.  The two remaining uses can access the
listen structure directly.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/qemu/qemu_command.c
src/qemu/qemu_parse_command.c
src/qemu/qemu_process.c
src/vbox/vbox_common.c
src/vmx/vmx.c
src/xenconfig/xen_common.c
src/xenconfig/xen_sxpr.c
src/xenconfig/xen_xl.c

index 3dfc57ce5934bf4089dd3a9850f10b5fcc30a32c..297303079ba4dc1b1056df603236104d3db8b3b2 100644 (file)
@@ -10693,7 +10693,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
     /* There were no <listen> elements, so we can just
      * directly set listenAddr as listens[0]->address */
     if (listenAddr && def->nListens == 0 &&
-        virDomainGraphicsListenSetAddress(def, 0, listenAddr, -1, true) < 0)
+        virDomainGraphicsListenAppendAddress(def, listenAddr) < 0)
         goto error;
 
     ret = 0;
@@ -23779,31 +23779,26 @@ virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, size_t i)
 }
 
 
-/* Make a copy of up to len characters of address, and store it in
- * listens[i].address. If setType is true, set the listen's type
- * to 'address', otherwise leave type alone. */
 int
-virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def,
-                                  size_t i, const char *address,
-                                  int len, bool setType)
+virDomainGraphicsListenAppendAddress(virDomainGraphicsDefPtr def,
+                                     const char *address)
 {
-    virDomainGraphicsListenDefPtr listenInfo
-        = virDomainGraphicsGetListen(def, i, true);
+    virDomainGraphicsListenDef listen;
 
-    if (!listenInfo)
-        return -1;
+    memset(&listen, 0, sizeof(listen));
 
-    if (setType)
-        listenInfo->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
+    listen.type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
 
-    if (!address) {
-        VIR_FREE(listenInfo->address);
-        return 0;
-    }
+    if (VIR_STRDUP(listen.address, address) < 0)
+        goto error;
+
+    if (VIR_APPEND_ELEMENT_COPY(def->listens, def->nListens, listen) < 0)
+        goto error;
 
-    if (VIR_STRNDUP(listenInfo->address, address, len) < 0)
-        return -1;
     return 0;
+ error:
+    VIR_FREE(listen.address);
+    return -1;
 }
 
 
index 6f93def2658647a237c48f8188585275b711dd4e..68b581f504c9120e8b292da22353201658b229a5 100644 (file)
@@ -2819,9 +2819,8 @@ int virDomainGraphicsListenSetType(virDomainGraphicsDefPtr def, size_t i, int va
 const char *virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def,
                                               size_t i)
             ATTRIBUTE_NONNULL(1);
-int virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def,
-                                      size_t i, const char *address,
-                                      int len, bool setType)
+int virDomainGraphicsListenAppendAddress(virDomainGraphicsDefPtr def,
+                                         const char *address)
             ATTRIBUTE_NONNULL(1);
 const char *virDomainGraphicsListenGetNetwork(virDomainGraphicsDefPtr def,
                                               size_t i)
index a79d85e77778d3945c0adabbef0b7792f86bb430..1f26a2406cf9f48263acdb279ccfdd579da8adc0 100644 (file)
@@ -300,10 +300,10 @@ virDomainGetFilesystemForTarget;
 virDomainGraphicsAuthConnectedTypeFromString;
 virDomainGraphicsAuthConnectedTypeToString;
 virDomainGraphicsDefFree;
+virDomainGraphicsListenAppendAddress;
 virDomainGraphicsListenGetAddress;
 virDomainGraphicsListenGetNetwork;
 virDomainGraphicsListenGetType;
-virDomainGraphicsListenSetAddress;
 virDomainGraphicsListenSetNetwork;
 virDomainGraphicsListenSetType;
 virDomainGraphicsSpiceChannelModeTypeFromString;
index bd8268289336b904f132e93d46365be07e8abed9..217728fda8e3407545bb68672b2c2061574d778b 100644 (file)
@@ -7270,8 +7270,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
             listenAddr = netAddr;
             /* store the address we found in the <graphics> element so it
              * will show up in status. */
-            if (virDomainGraphicsListenSetAddress(graphics, 0,
-                                                  listenAddr, -1, false) < 0)
+            if (VIR_STRDUP(graphics->listens[0].address, listenAddr) < 0)
                 goto error;
             break;
         }
@@ -7425,8 +7424,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
             listenAddr = netAddr;
             /* store the address we found in the <graphics> element so it will
              * show up in status. */
-            if (virDomainGraphicsListenSetAddress(graphics, 0,
-                                                  listenAddr, -1, false) < 0)
+            if (VIR_STRDUP(graphics->listens[0].address, listenAddr) < 0)
                goto error;
             break;
         }
index 8b294a7df02a93ee219498ada51db61c3f3ac44d..6fbb702b5b45f4c1d11798c0cb1d7a0fbea1b426 100644 (file)
@@ -519,6 +519,7 @@ qemuParseCommandLineVnc(virDomainDefPtr def,
         char *opts;
         char *port;
         const char *sep = ":";
+        char *listenAddr = NULL;
         if (val[0] == '[')
             sep = "]:";
         tmp = strstr(val, sep);
@@ -536,7 +537,8 @@ qemuParseCommandLineVnc(virDomainDefPtr def,
         }
         if (val[0] == '[')
             val++;
-        if (virDomainGraphicsListenSetAddress(vnc, 0, val, tmp-val, true) < 0)
+        if (VIR_STRNDUP(listenAddr, val, tmp-val) < 0 ||
+            virDomainGraphicsListenAppendAddress(vnc, listenAddr) < 0)
             goto cleanup;
 
         if (*opts == ',') {
index 6c870f54f85b6f98efb78630e568de0da958c4f0..1e1d748eaf1662002a5e8c73bdc4e0192b4cfa77 100644 (file)
@@ -4291,15 +4291,14 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
         if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ||
             graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
             if (graphics->nListens == 0) {
-                if (VIR_EXPAND_N(graphics->listens, graphics->nListens, 1) < 0)
-                    goto cleanup;
-                graphics->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
-                if (VIR_STRDUP(graphics->listens[0].address,
-                               graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ?
-                               cfg->vncListen : cfg->spiceListen) < 0) {
-                    VIR_SHRINK_N(graphics->listens, graphics->nListens, 1);
+                const char *listenAddr
+                    = graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ?
+                    cfg->vncListen : cfg->spiceListen;
+
+                if (virDomainGraphicsListenAppendAddress(graphics,
+                                                         listenAddr) < 0)
                     goto cleanup;
-                }
+
                 graphics->listens[0].fromConfig = true;
             } else if (graphics->nListens > 1) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
index c305eb597c320e02e9e206041b1dbb26d8b4a624..dcb2c1e871d3085bc791244df4e9a6bf23b0c51c 100644 (file)
@@ -3386,8 +3386,7 @@ vboxDumpDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
         }
 
         if (STRNEQ_NULLABLE(netAddressUtf8, "") &&
-            virDomainGraphicsListenSetAddress(graphics, 0,
-                                              netAddressUtf8, -1, true) < 0)
+            virDomainGraphicsListenAppendAddress(graphics, netAddressUtf8) < 0)
             goto cleanup;
 
         gVBoxAPI.UIVRDxServer.GetAllowMultiConnection(VRDxServer, &allowMultiConnection);
index f77a7a4b1fd76265e8ba4256748fbc4d93555c46..abed862434b25b2b7b30cac8192dcadad8585360 100644 (file)
@@ -1875,7 +1875,7 @@ virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def)
     }
 
     if (listenAddr) {
-        if (virDomainGraphicsListenSetAddress(*def, 0, listenAddr, -1, true) < 0)
+        if (virDomainGraphicsListenAppendAddress(*def, listenAddr) < 0)
             goto failure;
         VIR_FREE(listenAddr);
     }
index 4dcd484e09a13bbcde15f29da0b011c7ba5cb931..d58b69c66101bed17d37abb713db61b529f22bdc 100644 (file)
@@ -595,12 +595,10 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def)
             if (xenConfigCopyStringOpt(conf, "vnclisten", &listenAddr) < 0)
                 goto cleanup;
             if (listenAddr &&
-                virDomainGraphicsListenSetAddress(graphics, 0, listenAddr,
-                                                  -1, true) < 0) {
-               goto cleanup;
-            }
-
+                virDomainGraphicsListenAppendAddress(graphics, listenAddr) < 0)
+                goto cleanup;
             VIR_FREE(listenAddr);
+
             if (xenConfigCopyStringOpt(conf, "vncpasswd", &graphics->data.vnc.auth.passwd) < 0)
                 goto cleanup;
             if (xenConfigCopyStringOpt(conf, "keymap", &graphics->data.vnc.keymap) < 0)
@@ -666,8 +664,8 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def)
                         if (STREQ(key + 10, "1"))
                             graphics->data.vnc.autoport = true;
                     } else if (STRPREFIX(key, "vnclisten=")) {
-                        if (virDomainGraphicsListenSetAddress(graphics, 0, key+10,
-                                                              -1, true) < 0)
+                        if (virDomainGraphicsListenAppendAddress(graphics,
+                                                                 key+10) < 0)
                             goto cleanup;
                     } else if (STRPREFIX(key, "vncpasswd=")) {
                         if (VIR_STRDUP(graphics->data.vnc.auth.passwd, key + 10) < 0)
index fdfec2b7d77ffb3fb529e6b996eb308258bc2c3e..20ad5c8664b6a8fee92ae68ac5237e01833bc46a 100644 (file)
@@ -868,7 +868,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def,
         graphics->data.vnc.port = port;
 
         if (listenAddr &&
-            virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, -1, true) < 0)
+            virDomainGraphicsListenAppendAddress(graphics, listenAddr) < 0)
             goto error;
 
         if (VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0)
@@ -987,7 +987,7 @@ xenParseSxprGraphicsNew(virDomainDefPtr def,
                 graphics->data.vnc.port = port;
 
                 if (listenAddr &&
-                    virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, -1, true) < 0)
+                    virDomainGraphicsListenAppendAddress(graphics, listenAddr) < 0)
                     goto error;
 
                 if (VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0)
index 98a7fa6a26e7b8265c8611b9a7d503897b0a1ef3..de5d047661872e5b0d59cd4f6d8ce9128fdfc8f0 100644 (file)
@@ -187,10 +187,8 @@ xenParseXLSpice(virConfPtr conf, virDomainDefPtr def)
             if (xenConfigCopyStringOpt(conf, "spicehost", &listenAddr) < 0)
                 goto cleanup;
             if (listenAddr &&
-                virDomainGraphicsListenSetAddress(graphics, 0, listenAddr,
-                                                  -1, true) < 0) {
+                virDomainGraphicsListenAppendAddress(graphics, listenAddr) < 0)
                 goto cleanup;
-            }
             VIR_FREE(listenAddr);
 
             if (xenConfigGetULong(conf, "spicetls_port", &port, 0) < 0)