When handling virConnectOpen(), we parse given URI, specifically
all those parameters we know, like ?mode, ?socket, ?name, etc.
ignoring those we don't recognize yet. Then, we reconstruct the
URI back, but ignoring all parameters we've parsed. In other
words:
qemu:///system?mode=legacy&foo=bar
becomes:
qemu:///system?foo=bar
The reconstructed URI is then passed to the corresponding driver
(QEMU in our example) with intent of it parsing parameters
further (or just ignoring them). But for some transport modes,
where virt-ssh-helper is ran on the remote host (libssh, libssh2,
ssh) we need to pass ?mode and ?socket parameters, so that it can
do the right thing, e.g. for 'mode=legacy' start the monolithic
daemon, or for 'socket=' connect to the given socket.
Resolves:
https://gitlab.com/libvirt/libvirt/-/issues/433
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
Reviewed-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/remote/remote_driver.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index cce9e7ddaf..58cd0abe8c 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -696,18 +696,31 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr conn,
static char *
remoteConnectFormatURI(virURI *uri,
- const char *driver_str)
+ const char *driver_str,
+ bool unmask)
{
+ const char *names[] = {"mode", "socket", NULL};
g_autofree char *query = NULL;
+ char *ret = NULL;
virURI tmpuri = {
.scheme = (char *)driver_str,
.path = uri->path,
.fragment = uri->fragment,
};
+ if (unmask) {
+ virURIParamsSetIgnore(uri, false, names);
+ }
+
query = tmpuri.query = virURIFormatParams(uri);
- return virURIFormat(&tmpuri);
+ ret = virURIFormat(&tmpuri);
+
+ if (unmask) {
+ virURIParamsSetIgnore(uri, true, names);
+ }
+
+ return ret;
}
@@ -780,6 +793,7 @@ doRemoteOpen(virConnectPtr conn,
g_autofree char *mode_str = NULL;
g_autofree char *daemon_path = NULL;
g_autofree char *proxy_str = NULL;
+ g_autofree char *virtSshURI = NULL;
bool sanity = true;
bool verify = true;
#ifndef WIN32
@@ -851,7 +865,10 @@ doRemoteOpen(virConnectPtr conn,
/* Allow remote serve to probe */
name = g_strdup("");
} else {
- name = remoteConnectFormatURI(conn->uri, driver_str);
+ name = remoteConnectFormatURI(conn->uri, driver_str, false);
+
+ /* Preserve mode and socket parameters. */
+ virtSshURI = remoteConnectFormatURI(conn->uri, driver_str, true);
}
}
@@ -1006,7 +1023,7 @@ doRemoteOpen(virConnectPtr conn,
proxy,
netcat,
sockname,
- name,
+ virtSshURI ? virtSshURI : name,
flags & REMOTE_DRIVER_OPEN_RO,
auth,
conn->uri);
@@ -1030,7 +1047,7 @@ doRemoteOpen(virConnectPtr conn,
proxy,
netcat,
sockname,
- name,
+ virtSshURI ? virtSshURI : name,
flags & REMOTE_DRIVER_OPEN_RO,
auth,
conn->uri);
@@ -1063,7 +1080,7 @@ doRemoteOpen(virConnectPtr conn,
proxy,
netcat,
sockname,
- name,
+ virtSshURI ? virtSshURI : name,
flags & REMOTE_DRIVER_OPEN_RO)))
goto error;
--
2.39.1