[PATCH 3/4] virIdentityGetParameters: Return 'virTypedParamList'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Refactor the code to use virTypedParamList which simplifies cleanup.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/driver.c                        | 10 +++-------
 src/remote/remote_daemon_dispatch.c |  8 +++-----
 src/util/viridentity.c              | 15 +++++----------
 src/util/viridentity.h              |  5 ++---
 4 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/src/driver.c b/src/driver.c
index d4136c438f..cea74bdf95 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -160,20 +160,16 @@ virGetConnectGeneric(virThreadLocal *threadPtr, const char *name)

         if (conn->driver->connectSetIdentity != NULL) {
             g_autoptr(virIdentity) ident = NULL;
-            g_autoptr(virTypedParamList) paramlist = NULL;
-            virTypedParameterPtr identparams = NULL;
-            int nidentparams = 0;
+            g_autoptr(virTypedParamList) identparams = NULL;

             VIR_DEBUG("Attempting to delegate current identity");
             if (!(ident = virIdentityGetCurrent()))
                 goto error;

-            if (virIdentityGetParameters(ident, &identparams, &nidentparams) < 0)
+            if (!(identparams = virIdentityGetParameters(ident)))
                 goto error;

-            paramlist = virTypedParamListFromParams(&identparams, nidentparams);
-
-            if (virConnectSetIdentity(conn, paramlist->par, paramlist->npar, 0) < 0)
+            if (virConnectSetIdentity(conn, identparams->par, identparams->npar, 0) < 0)
                 goto error;
         }
     }
diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index 2463386e39..39953f46cf 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -1793,8 +1793,7 @@ remoteOpenConn(const char *uri,
                bool preserveIdentity,
                virConnectPtr *conn)
 {
-    virTypedParameterPtr params = NULL;
-    int nparams = 0;
+    g_autoptr(virTypedParamList) identparams = NULL;
     int ret = -1;

     VIR_DEBUG("Getting secondary uri=%s readonly=%d preserveIdent=%d conn=%p",
@@ -1814,7 +1813,7 @@ remoteOpenConn(const char *uri,
         if (!(ident = virIdentityGetCurrent()))
             return -1;

-        if (virIdentityGetParameters(ident, &params, &nparams) < 0)
+        if (!(identparams = virIdentityGetParameters(ident)))
             goto error;
     }

@@ -1828,7 +1827,7 @@ remoteOpenConn(const char *uri,
     VIR_DEBUG("Opened driver %p", *conn);

     if (preserveIdentity) {
-        if (virConnectSetIdentity(*conn, params, nparams, 0) < 0)
+        if (virConnectSetIdentity(*conn, identparams->par, identparams->npar, 0) < 0)
             goto error;

         VIR_DEBUG("Forwarded current identity to secondary driver");
@@ -1836,7 +1835,6 @@ remoteOpenConn(const char *uri,

     ret = 0;
  cleanup:
-    virTypedParamsFree(params, nparams);
     return ret;

  error:
diff --git a/src/util/viridentity.c b/src/util/viridentity.c
index 70843ecf9f..e3a9cbb661 100644
--- a/src/util/viridentity.c
+++ b/src/util/viridentity.c
@@ -838,17 +838,12 @@ int virIdentitySetParameters(virIdentity *ident,
 }


-int virIdentityGetParameters(virIdentity *ident,
-                             virTypedParameterPtr *params,
-                             int *nparams)
+virTypedParamList *virIdentityGetParameters(virIdentity *ident)
 {
-    *params = NULL;
-    *nparams = 0;
+    virTypedParameter *tmp = NULL;

-    if (virTypedParamsCopy(params, ident->params, ident->nparams) < 0)
-        return -1;
-
-    *nparams = ident->nparams;
+    if (virTypedParamsCopy(&tmp, ident->params, ident->nparams) < 0)
+        return NULL;

-    return 0;
+    return virTypedParamListFromParams(&tmp, ident->nparams);
 }
diff --git a/src/util/viridentity.h b/src/util/viridentity.h
index 6da6d0c557..5f87d7268b 100644
--- a/src/util/viridentity.h
+++ b/src/util/viridentity.h
@@ -23,6 +23,7 @@

 #include "internal.h"
 #include <glib-object.h>
+#include "virtypedparam.h"

 #define VIR_TYPE_IDENTITY vir_identity_get_type()
 G_DECLARE_FINAL_TYPE(virIdentity, vir_identity, VIR, IDENTITY, GObject);
@@ -88,6 +89,4 @@ int virIdentitySetParameters(virIdentity *ident,
                              virTypedParameterPtr params,
                              int nparams);

-int virIdentityGetParameters(virIdentity *ident,
-                             virTypedParameterPtr *params,
-                             int *nparams);
+virTypedParamList *virIdentityGetParameters(virIdentity *ident);
-- 
2.35.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux