]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
remote: Pass 'mode' and 'socket' URI parameters to virt-ssh-helper
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 3 Feb 2023 14:22:18 +0000 (15:22 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 8 Feb 2023 15:50:45 +0000 (16:50 +0100)
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@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/remote/remote_driver.c

index cce9e7ddaf5be22bac3ee12e78bcfbe679d106f4..58cd0abe8c5bacce59c923bb82e6a3adff467f31 100644 (file)
@@ -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;