[PATCH 08/10] remote_driver: Move URI re-generation into a function

Michal Privoznik posted 10 patches 3 years ago
There is a newer version of this series
[PATCH 08/10] remote_driver: Move URI re-generation into a function
Posted by Michal Privoznik 3 years ago
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).

Now, this URI reconstruction is currently implemented in an else
branch. Move it into a separate function so that it can be
re-used.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/remote/remote_driver.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index c41d5b414f..7e1a31a5a0 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -693,6 +693,22 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr conn,
     return rc != -1 && ret.supported;
 }
 
+static char *
+remoteConnectFormatURI(virURI *uri,
+                       const char *driver_str)
+{
+    g_autofree char *query = NULL;
+    virURI tmpuri = {
+        .scheme = (char *)driver_str,
+        .path = uri->path,
+        .fragment = uri->fragment,
+    };
+
+    query = tmpuri.query = virURIFormatParams(uri);
+
+    return virURIFormat(&tmpuri);
+}
+
 /*
  * URIs that this driver needs to handle:
  *
@@ -809,16 +825,8 @@ doRemoteOpen(virConnectPtr conn,
                 /* Allow remote serve to probe */
                 name = g_strdup("");
             } else {
-                virURI tmpuri = {
-                    .scheme = (char *)driver_str,
-                    .query = virURIFormatParams(conn->uri),
-                    .path = conn->uri->path,
-                    .fragment = conn->uri->fragment,
-                };
+                name = remoteConnectFormatURI(conn->uri, driver_str);
 
-                name = virURIFormat(&tmpuri);
-
-                VIR_FREE(tmpuri.query);
             }
         }
     } else {
-- 
2.39.1
Re: [PATCH 08/10] remote_driver: Move URI re-generation into a function
Posted by Peter Krempa 3 years ago
On Mon, Feb 06, 2023 at 10:16:56 +0100, Michal Privoznik wrote:
> 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).

Did you mean to put all the explanation above into the patch that is
going to modify it? Here it doesn't make much sense as ....

> 
> Now, this URI reconstruction is currently implemented in an else
> branch. Move it into a separate function so that it can be
> re-used.

... this patch simply moves the code doing the URI construction, where
you can't se what's actually happening to the parameters into a new
helper.

> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/remote/remote_driver.c | 26 +++++++++++++++++---------
>  1 file changed, 17 insertions(+), 9 deletions(-)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>