mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
domain_conf: introduce virDomainGraphicsListenAppendAddress
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>
This commit is contained in:
parent
edebc16607
commit
4b75237fe6
@ -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 (VIR_STRDUP(listen.address, address) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_APPEND_ELEMENT_COPY(def->listens, def->nListens, listen) < 0)
|
||||
goto error;
|
||||
|
||||
if (!address) {
|
||||
VIR_FREE(listenInfo->address);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (VIR_STRNDUP(listenInfo->address, address, len) < 0)
|
||||
error:
|
||||
VIR_FREE(listen.address);
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -300,10 +300,10 @@ virDomainGetFilesystemForTarget;
|
||||
virDomainGraphicsAuthConnectedTypeFromString;
|
||||
virDomainGraphicsAuthConnectedTypeToString;
|
||||
virDomainGraphicsDefFree;
|
||||
virDomainGraphicsListenAppendAddress;
|
||||
virDomainGraphicsListenGetAddress;
|
||||
virDomainGraphicsListenGetNetwork;
|
||||
virDomainGraphicsListenGetType;
|
||||
virDomainGraphicsListenSetAddress;
|
||||
virDomainGraphicsListenSetNetwork;
|
||||
virDomainGraphicsListenSetType;
|
||||
virDomainGraphicsSpiceChannelModeTypeFromString;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 == ',') {
|
||||
|
@ -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)
|
||||
const char *listenAddr
|
||||
= graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ?
|
||||
cfg->vncListen : cfg->spiceListen;
|
||||
|
||||
if (virDomainGraphicsListenAppendAddress(graphics,
|
||||
listenAddr) < 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);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
graphics->listens[0].fromConfig = true;
|
||||
} else if (graphics->nListens > 1) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user