[PATCH v2 6/8] remote_driver: Move URI re-generation into a function

Michal Privoznik mprivozn at redhat.com
Wed Feb 8 15:19:12 UTC 2023


There's a piece of code in doRemoteOpen() that is going to be
called twice. Instead of duplicating the code, move it into a
function that will be called twice, later on.

Signee-off-by: Michal Privoznik <mprivozn at redhat.com>
Reviewed-by: Peter Krempa <pkrempa at redhat.com>
Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/remote/remote_driver.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 6a226999df..cce9e7ddaf 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -693,6 +693,24 @@ 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);
+}
+
+
 /* helper macro to ease extraction of arguments from the URI */
 #define EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \
     if (STRCASEEQ(var->name, ARG_NAME)) { \
@@ -833,16 +851,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



More information about the libvir-list mailing list