]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
doRemoteOpen: Move RPC talk to a separate function
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 4 Apr 2025 07:21:45 +0000 (09:21 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 7 Apr 2025 06:42:54 +0000 (08:42 +0200)
When opening a connection, the client does some RPC talk
(most notably REMOTE_PROC_CONNECT_OPEN, and in some cases
REMOTE_PROC_CONNECT_GET_URI even).

Now, calling RPC means that local variables must be created.
Having them in doRemoteOpen() increases its stack size which goes
against our effort in bringing the size down (see one of previous
commits).

Move that part of the code into a separate function.

This brings the stack size of doRemoteOpen() even further: from
1320 bytes to 1272.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
src/remote/remote_driver.c

index 681594e406d97488b09db926527e5abe0d53d1a5..3ecef7d73faa5eaaffc51804444a3d5d0d675d98 100644 (file)
@@ -742,6 +742,42 @@ remoteConnectFormatURI(virURI *uri,
 }
 
 
+static int
+remoteCallOpen(virConnectPtr conn,
+               struct private_data *priv,
+               const char *name,
+               unsigned int flags)
+{
+    remote_connect_open_args args = { (char**) &name, flags };
+
+    VIR_DEBUG("Trying to open URI '%s'", name);
+    if (call(conn, priv, 0, REMOTE_PROC_CONNECT_OPEN,
+             (xdrproc_t) xdr_remote_connect_open_args, (char *) &args,
+             (xdrproc_t) xdr_void, (char *) NULL) == -1)
+        return -1;
+
+    /* Now try and find out what URI the daemon used */
+    if (conn->uri == NULL) {
+        remote_connect_get_uri_ret uriret = { 0 };
+
+        VIR_DEBUG("Trying to query remote URI");
+        if (call(conn, priv, 0,
+                 REMOTE_PROC_CONNECT_GET_URI,
+                 (xdrproc_t) xdr_void, (char *) NULL,
+                 (xdrproc_t) xdr_remote_connect_get_uri_ret, (char *) &uriret) < 0)
+            return -1;
+
+        VIR_DEBUG("Auto-probed URI is %s", uriret.uri);
+        conn->uri = virURIParse(uriret.uri);
+        VIR_FREE(uriret.uri);
+        if (!conn->uri)
+            return -1;
+    }
+
+    return 0;
+}
+
+
 /* 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)) { \
@@ -1241,33 +1277,8 @@ doRemoteOpen(virConnectPtr conn,
     }
 
     /* Finally we can call the remote side's open function. */
-    {
-        remote_connect_open_args args = { &name, flags };
-
-        VIR_DEBUG("Trying to open URI '%s'", name);
-        if (call(conn, priv, 0, REMOTE_PROC_CONNECT_OPEN,
-                 (xdrproc_t) xdr_remote_connect_open_args, (char *) &args,
-                 (xdrproc_t) xdr_void, (char *) NULL) == -1)
-            goto error;
-    }
-
-    /* Now try and find out what URI the daemon used */
-    if (conn->uri == NULL) {
-        remote_connect_get_uri_ret uriret = { 0 };
-
-        VIR_DEBUG("Trying to query remote URI");
-        if (call(conn, priv, 0,
-                 REMOTE_PROC_CONNECT_GET_URI,
-                 (xdrproc_t) xdr_void, (char *) NULL,
-                 (xdrproc_t) xdr_remote_connect_get_uri_ret, (char *) &uriret) < 0)
-            goto error;
-
-        VIR_DEBUG("Auto-probed URI is %s", uriret.uri);
-        conn->uri = virURIParse(uriret.uri);
-        VIR_FREE(uriret.uri);
-        if (!conn->uri)
-            goto error;
-    }
+    if (remoteCallOpen(conn, priv, name, flags) < 0)
+        goto error;
 
     /* Set up events */
     if (!(priv->eventState = virObjectEventStateNew()))