提交 78a09aa0 编写于 作者: P Pavel Hrdina

graphics: resolve address for listen type network in qemu_process

Both VNC and SPICE requires the same code to resolve address for listen
type network.  Remove code duplication and create a new function that
will be used in qemuProcessSetupGraphics().
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 858d7b6c
...@@ -7358,10 +7358,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7358,10 +7358,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
{ {
virBuffer opt = VIR_BUFFER_INITIALIZER; virBuffer opt = VIR_BUFFER_INITIALIZER;
virDomainGraphicsListenDefPtr glisten = NULL; virDomainGraphicsListenDefPtr glisten = NULL;
const char *listenAddr = NULL;
char *netAddr = NULL;
bool escapeAddr; bool escapeAddr;
int ret;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNC)) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNC)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
...@@ -7369,6 +7366,8 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7369,6 +7366,8 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
goto error; goto error;
} }
glisten = virDomainGraphicsGetListen(graphics, 0);
if (graphics->data.vnc.socket || cfg->vncAutoUnixSocket) { if (graphics->data.vnc.socket || cfg->vncAutoUnixSocket) {
if (!graphics->data.vnc.socket) { if (!graphics->data.vnc.socket) {
if (virAsprintf(&graphics->data.vnc.socket, if (virAsprintf(&graphics->data.vnc.socket,
...@@ -7390,52 +7389,15 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7390,52 +7389,15 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
goto error; goto error;
} }
if ((glisten = virDomainGraphicsGetListen(graphics, 0))) { if (glisten && glisten->address) {
escapeAddr = strchr(glisten->address, ':') != NULL;
switch (glisten->type) { if (escapeAddr)
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: virBufferAsprintf(&opt, "[%s]", glisten->address);
listenAddr = glisten->address; else
break; virBufferAdd(&opt, glisten->address, -1);
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
if (!glisten->network)
break;
ret = networkGetNetworkAddress(glisten->network, &netAddr);
if (ret <= -2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("network-based listen not possible, "
"network driver not present"));
goto error;
}
if (ret < 0)
goto error;
listenAddr = netAddr;
/* store the address we found in the <graphics> element so it
* will show up in status. */
if (VIR_STRDUP(glisten->address, netAddr) < 0)
goto error;
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
}
} }
if (!listenAddr)
listenAddr = cfg->vncListen;
escapeAddr = strchr(listenAddr, ':') != NULL;
if (escapeAddr)
virBufferAsprintf(&opt, "[%s]", listenAddr);
else
virBufferAdd(&opt, listenAddr, -1);
virBufferAsprintf(&opt, ":%d", virBufferAsprintf(&opt, ":%d",
graphics->data.vnc.port - 5900); graphics->data.vnc.port - 5900);
VIR_FREE(netAddr);
} }
if (!graphics->data.vnc.socket && if (!graphics->data.vnc.socket &&
...@@ -7499,7 +7461,6 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7499,7 +7461,6 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
return 0; return 0;
error: error:
VIR_FREE(netAddr);
virBufferFreeAndReset(&opt); virBufferFreeAndReset(&opt);
return -1; return -1;
} }
...@@ -7513,9 +7474,6 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7513,9 +7474,6 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
{ {
virBuffer opt = VIR_BUFFER_INITIALIZER; virBuffer opt = VIR_BUFFER_INITIALIZER;
virDomainGraphicsListenDefPtr glisten = NULL; virDomainGraphicsListenDefPtr glisten = NULL;
const char *listenAddr = NULL;
char *netAddr = NULL;
int ret;
int defaultMode = graphics->data.spice.defaultMode; int defaultMode = graphics->data.spice.defaultMode;
int port = graphics->data.spice.port; int port = graphics->data.spice.port;
int tlsPort = graphics->data.spice.tlsPort; int tlsPort = graphics->data.spice.tlsPort;
...@@ -7527,6 +7485,8 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7527,6 +7485,8 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
goto error; goto error;
} }
glisten = virDomainGraphicsGetListen(graphics, 0);
if (port > 0) if (port > 0)
virBufferAsprintf(&opt, "port=%u,", port); virBufferAsprintf(&opt, "port=%u,", port);
...@@ -7541,46 +7501,8 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7541,46 +7501,8 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
} }
if (port > 0 || tlsPort > 0) { if (port > 0 || tlsPort > 0) {
if ((glisten = virDomainGraphicsGetListen(graphics, 0))) { if (glisten && glisten->address)
virBufferAsprintf(&opt, "addr=%s,", glisten->address);
switch (glisten->type) {
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
listenAddr = glisten->address;
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
if (!glisten->network)
break;
ret = networkGetNetworkAddress(glisten->network, &netAddr);
if (ret <= -2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("network-based listen not possible, "
"network driver not present"));
goto error;
}
if (ret < 0)
goto error;
listenAddr = netAddr;
/* store the address we found in the <graphics> element so it will
* show up in status. */
if (VIR_STRDUP(glisten->address, listenAddr) < 0)
goto error;
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
}
}
if (!listenAddr)
listenAddr = cfg->spiceListen;
if (listenAddr)
virBufferAsprintf(&opt, "addr=%s,", listenAddr);
VIR_FREE(netAddr);
} }
if (cfg->spiceSASL) { if (cfg->spiceSASL) {
...@@ -7749,7 +7671,6 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7749,7 +7671,6 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
return 0; return 0;
error: error:
VIR_FREE(netAddr);
virBufferFreeAndReset(&opt); virBufferFreeAndReset(&opt);
return -1; return -1;
} }
......
...@@ -3990,6 +3990,33 @@ qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver, ...@@ -3990,6 +3990,33 @@ qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
} }
static int
qemuProcessGraphicsSetupNetworkAddress(virDomainGraphicsListenDefPtr glisten,
const char *listenAddr)
{
int rc;
/* TODO: reject configuration without network specified for network listen */
if (!glisten->network) {
if (VIR_STRDUP(glisten->address, listenAddr) < 0)
return -1;
return 0;
}
rc = networkGetNetworkAddress(glisten->network, &glisten->address);
if (rc <= -2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("network-based listen isn't possible, "
"network driver isn't present"));
return -1;
}
if (rc < 0)
return -1;
return 0;
}
static int static int
qemuProcessSetupGraphics(virQEMUDriverPtr driver, qemuProcessSetupGraphics(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
...@@ -4032,12 +4059,29 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver, ...@@ -4032,12 +4059,29 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
for (j = 0; j < graphics->nListens; j++) { for (j = 0; j < graphics->nListens; j++) {
virDomainGraphicsListenDefPtr glisten = &graphics->listens[j]; virDomainGraphicsListenDefPtr glisten = &graphics->listens[j];
if (glisten->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS && switch (glisten->type) {
!glisten->address && listenAddr) { case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
if (glisten->address || !listenAddr)
continue;
if (VIR_STRDUP(glisten->address, listenAddr) < 0) if (VIR_STRDUP(glisten->address, listenAddr) < 0)
goto cleanup; goto cleanup;
glisten->fromConfig = true; glisten->fromConfig = true;
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
if (glisten->address || !listenAddr)
continue;
if (qemuProcessGraphicsSetupNetworkAddress(glisten,
listenAddr) < 0)
goto cleanup;
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册