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 add 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(a)redhat.com>
---
src/conf/domain_conf.c | 34 +++++++++++++++-------------------
src/conf/domain_conf.h | 6 +++---
src/libvirt_private.syms | 2 +-
src/qemu/qemu_command.c | 6 ++----
src/qemu/qemu_parse_command.c | 4 +++-
src/qemu/qemu_process.c | 15 +++++++--------
src/vbox/vbox_common.c | 3 +--
src/vmx/vmx.c | 2 +-
src/xenconfig/xen_common.c | 12 +++++-------
src/xenconfig/xen_sxpr.c | 4 ++--
src/xenconfig/xen_xl.c | 4 +---
11 files changed, 41 insertions(+), 51 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 42050b0..c79a432 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10741,7 +10741,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)
+ virDomainGraphicsListenAddAddress(def, 0, listenAddr) < 0)
goto error;
ret = 0;
@@ -23820,31 +23820,27 @@ 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)
+virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def,
+ int pos,
+ 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_INSERT_ELEMENT_COPY(def->listens, pos, 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;
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fe9faeb..ed3d818 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2818,9 +2818,9 @@ 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 virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def,
+ int pos,
+ const char *address)
ATTRIBUTE_NONNULL(1);
const char *virDomainGraphicsListenGetNetwork(virDomainGraphicsDefPtr def,
size_t i)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 684f06c..cc1c969 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -300,10 +300,10 @@ virDomainGetFilesystemForTarget;
virDomainGraphicsAuthConnectedTypeFromString;
virDomainGraphicsAuthConnectedTypeToString;
virDomainGraphicsDefFree;
+virDomainGraphicsListenAddAddress;
virDomainGraphicsListenGetAddress;
virDomainGraphicsListenGetNetwork;
virDomainGraphicsListenGetType;
-virDomainGraphicsListenSetAddress;
virDomainGraphicsListenSetNetwork;
virDomainGraphicsListenSetType;
virDomainGraphicsSpiceChannelModeTypeFromString;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2d0ca97..140bf98 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7274,8 +7274,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;
}
@@ -7429,8 +7428,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;
}
diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c
index 8b294a7..a556461 100644
--- a/src/qemu/qemu_parse_command.c
+++ b/src/qemu/qemu_parse_command.c
@@ -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 ||
+ virDomainGraphicsListenAddAddress(vnc, 0, listenAddr) < 0)
goto cleanup;
if (*opts == ',') {
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d9dca74..6a4fb8c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4286,15 +4286,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 (virDomainGraphicsListenAddAddress(graphics, 0,
+ listenAddr) < 0)
goto cleanup;
- }
+
graphics->listens[0].fromConfig = true;
} else if (graphics->nListens > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index c305eb5..ee3b9c5 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -3386,8 +3386,7 @@ vboxDumpDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine
*machine)
}
if (STRNEQ_NULLABLE(netAddressUtf8, "") &&
- virDomainGraphicsListenSetAddress(graphics, 0,
- netAddressUtf8, -1, true) < 0)
+ virDomainGraphicsListenAddAddress(graphics, 0, netAddressUtf8) < 0)
goto cleanup;
gVBoxAPI.UIVRDxServer.GetAllowMultiConnection(VRDxServer,
&allowMultiConnection);
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index f77a7a4..f6a4474 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1875,7 +1875,7 @@ virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def)
}
if (listenAddr) {
- if (virDomainGraphicsListenSetAddress(*def, 0, listenAddr, -1, true) < 0)
+ if (virDomainGraphicsListenAddAddress(*def, 0, listenAddr) < 0)
goto failure;
VIR_FREE(listenAddr);
}
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 4dcd484..db1e236 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -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;
- }
-
+ virDomainGraphicsListenAddAddress(graphics, 0, 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 (virDomainGraphicsListenAddAddress(graphics, 0,
+ key+10) < 0)
goto cleanup;
} else if (STRPREFIX(key, "vncpasswd=")) {
if (VIR_STRDUP(graphics->data.vnc.auth.passwd, key + 10) <
0)
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index fdfec2b..7d719b0 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -868,7 +868,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def,
graphics->data.vnc.port = port;
if (listenAddr &&
- virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, -1, true) < 0)
+ virDomainGraphicsListenAddAddress(graphics, 0, 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)
+ virDomainGraphicsListenAddAddress(graphics, 0, listenAddr) < 0)
goto error;
if (VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0)
diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
index 98a7fa6..5478d9c 100644
--- a/src/xenconfig/xen_xl.c
+++ b/src/xenconfig/xen_xl.c
@@ -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) {
+ virDomainGraphicsListenAddAddress(graphics, 0, listenAddr) < 0)
goto cleanup;
- }
VIR_FREE(listenAddr);
if (xenConfigGetULong(conf, "spicetls_port", &port, 0) < 0)
--
2.7.4