mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
virIdentityGetParameters: Return 'virTypedParamList'
Refactor the code to use virTypedParamList which simplifies cleanup. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
decc03857f
commit
7f50557c08
10
src/driver.c
10
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;
|
||||
}
|
||||
}
|
||||
|
@ -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, ¶ms, &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:
|
||||
|
@ -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;
|
||||
if (virTypedParamsCopy(&tmp, ident->params, ident->nparams) < 0)
|
||||
return NULL;
|
||||
|
||||
*nparams = ident->nparams;
|
||||
|
||||
return 0;
|
||||
return virTypedParamListFromParams(&tmp, ident->nparams);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user