mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 10:52:22 +00:00
remote: parse the remote transport string earlier
We delay converting the remote transport string to enum form until fairly late. As a result we're doing string comparisons when we could be just doing enum comparisons. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
849de2b844
commit
3dfd0cbf25
@ -183,6 +183,7 @@
|
||||
@SRCDIR@src/remote/remote_daemon_dispatch.c
|
||||
@SRCDIR@src/remote/remote_daemon_stream.c
|
||||
@SRCDIR@src/remote/remote_driver.c
|
||||
@SRCDIR@src/remote/remote_sockets.c
|
||||
@SRCDIR@src/rpc/virkeepalive.c
|
||||
@SRCDIR@src/rpc/virnetclient.c
|
||||
@SRCDIR@src/rpc/virnetclientprogram.c
|
||||
|
@ -863,12 +863,11 @@ static int
|
||||
doRemoteOpen(virConnectPtr conn,
|
||||
struct private_data *priv,
|
||||
const char *driver_str,
|
||||
const char *transport_str,
|
||||
remoteDriverTransport transport,
|
||||
virConnectAuthPtr auth G_GNUC_UNUSED,
|
||||
virConfPtr conf,
|
||||
unsigned int flags)
|
||||
{
|
||||
int transport;
|
||||
#ifndef WIN32
|
||||
g_autofree char *daemonPath = NULL;
|
||||
#endif
|
||||
@ -904,34 +903,6 @@ doRemoteOpen(virConnectPtr conn,
|
||||
/* We handle *ALL* URIs here. The caller has rejected any
|
||||
* URIs we don't care about */
|
||||
|
||||
if (conn->uri) {
|
||||
if (!transport_str) {
|
||||
if (conn->uri->server)
|
||||
transport = REMOTE_DRIVER_TRANSPORT_TLS;
|
||||
else
|
||||
transport = REMOTE_DRIVER_TRANSPORT_UNIX;
|
||||
} else {
|
||||
if ((transport = remoteDriverTransportTypeFromString(transport_str)) < 0) {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("remote_open: transport in URL not recognised "
|
||||
"(should be tls|unix|ssh|ext|tcp|libssh2|libssh)"));
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
|
||||
if (transport == REMOTE_DRIVER_TRANSPORT_UNIX &&
|
||||
conn->uri->server) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("using unix socket and remote "
|
||||
"server '%s' is not supported."),
|
||||
conn->uri->server);
|
||||
return VIR_DRV_OPEN_ERROR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* No URI, then must be probing so use UNIX socket */
|
||||
transport = REMOTE_DRIVER_TRANSPORT_UNIX;
|
||||
}
|
||||
|
||||
/* Remote server defaults to "localhost" if not specified. */
|
||||
if (conn->uri && conn->uri->port != 0) {
|
||||
port = g_strdup_printf("%d", conn->uri->port);
|
||||
@ -1351,11 +1322,16 @@ remoteConnectOpen(virConnectPtr conn,
|
||||
int rflags = 0;
|
||||
const char *autostart = getenv("LIBVIRT_AUTOSTART");
|
||||
char *driver = NULL;
|
||||
char *transport = NULL;
|
||||
remoteDriverTransport transport;
|
||||
|
||||
if (conn->uri) {
|
||||
if (remoteSplitURIScheme(conn->uri, &driver, &transport) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
/* No URI, then must be probing so use UNIX socket */
|
||||
transport = REMOTE_DRIVER_TRANSPORT_UNIX;
|
||||
}
|
||||
|
||||
if (conn->uri &&
|
||||
remoteSplitURIScheme(conn->uri, &driver, &transport) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (inside_daemon) {
|
||||
if (!conn->uri) {
|
||||
@ -1401,12 +1377,12 @@ remoteConnectOpen(virConnectPtr conn,
|
||||
rflags |= VIR_DRV_OPEN_REMOTE_USER;
|
||||
|
||||
/*
|
||||
* Furthermore if no servername is given, and no +XXX
|
||||
* transport is listed, or transport is unix,
|
||||
* Furthermore if no servername is given,
|
||||
* and the transport is unix,
|
||||
* and uid is unprivileged then auto-spawn a daemon.
|
||||
*/
|
||||
if (!conn->uri->server &&
|
||||
(transport == NULL || STREQ(transport, "unix")) &&
|
||||
(transport == REMOTE_DRIVER_TRANSPORT_UNIX) &&
|
||||
(!autostart ||
|
||||
STRNEQ(autostart, "0"))) {
|
||||
VIR_DEBUG("Try daemon autostart");
|
||||
@ -1441,7 +1417,6 @@ remoteConnectOpen(virConnectPtr conn,
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(driver);
|
||||
VIR_FREE(transport);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,9 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "remote_sockets.h"
|
||||
#include "virerror.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_REMOTE
|
||||
|
||||
VIR_ENUM_IMPL(remoteDriverTransport,
|
||||
REMOTE_DRIVER_TRANSPORT_LAST,
|
||||
@ -42,25 +45,47 @@ VIR_ENUM_IMPL(remoteDriverMode,
|
||||
int
|
||||
remoteSplitURIScheme(virURIPtr uri,
|
||||
char **driver,
|
||||
char **transport)
|
||||
remoteDriverTransport *transport)
|
||||
{
|
||||
char *p = strchr(uri->scheme, '+');
|
||||
|
||||
*driver = *transport = NULL;
|
||||
|
||||
if (p)
|
||||
*driver = g_strndup(uri->scheme, p - uri->scheme);
|
||||
else
|
||||
*driver = g_strdup(uri->scheme);
|
||||
|
||||
if (p) {
|
||||
*transport = g_strdup(p + 1);
|
||||
g_autofree char *tmp = g_strdup(p + 1);
|
||||
int val;
|
||||
|
||||
p = *transport;
|
||||
p = tmp;
|
||||
while (*p) {
|
||||
*p = g_ascii_tolower(*p);
|
||||
p++;
|
||||
}
|
||||
|
||||
if ((val = remoteDriverTransportTypeFromString(tmp)) < 0) {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("remote_open: transport in URL not recognised "
|
||||
"(should be tls|unix|ssh|ext|tcp|libssh2|libssh)"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (val == REMOTE_DRIVER_TRANSPORT_UNIX &&
|
||||
uri->server) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("using unix socket and remote "
|
||||
"server '%s' is not supported."),
|
||||
uri->server);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*transport = val;
|
||||
} else {
|
||||
if (uri->server)
|
||||
*transport = REMOTE_DRIVER_TRANSPORT_TLS;
|
||||
else
|
||||
*transport = REMOTE_DRIVER_TRANSPORT_UNIX;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -53,4 +53,4 @@ VIR_ENUM_DECL(remoteDriverMode);
|
||||
int
|
||||
remoteSplitURIScheme(virURIPtr uri,
|
||||
char **driver,
|
||||
char **transport);
|
||||
remoteDriverTransport *transport);
|
||||
|
Loading…
x
Reference in New Issue
Block a user