mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06: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) {
|
if (conn->driver->connectSetIdentity != NULL) {
|
||||||
g_autoptr(virIdentity) ident = NULL;
|
g_autoptr(virIdentity) ident = NULL;
|
||||||
g_autoptr(virTypedParamList) paramlist = NULL;
|
g_autoptr(virTypedParamList) identparams = NULL;
|
||||||
virTypedParameterPtr identparams = NULL;
|
|
||||||
int nidentparams = 0;
|
|
||||||
|
|
||||||
VIR_DEBUG("Attempting to delegate current identity");
|
VIR_DEBUG("Attempting to delegate current identity");
|
||||||
if (!(ident = virIdentityGetCurrent()))
|
if (!(ident = virIdentityGetCurrent()))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virIdentityGetParameters(ident, &identparams, &nidentparams) < 0)
|
if (!(identparams = virIdentityGetParameters(ident)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
paramlist = virTypedParamListFromParams(&identparams, nidentparams);
|
if (virConnectSetIdentity(conn, identparams->par, identparams->npar, 0) < 0)
|
||||||
|
|
||||||
if (virConnectSetIdentity(conn, paramlist->par, paramlist->npar, 0) < 0)
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1793,8 +1793,7 @@ remoteOpenConn(const char *uri,
|
|||||||
bool preserveIdentity,
|
bool preserveIdentity,
|
||||||
virConnectPtr *conn)
|
virConnectPtr *conn)
|
||||||
{
|
{
|
||||||
virTypedParameterPtr params = NULL;
|
g_autoptr(virTypedParamList) identparams = NULL;
|
||||||
int nparams = 0;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
VIR_DEBUG("Getting secondary uri=%s readonly=%d preserveIdent=%d conn=%p",
|
VIR_DEBUG("Getting secondary uri=%s readonly=%d preserveIdent=%d conn=%p",
|
||||||
@ -1814,7 +1813,7 @@ remoteOpenConn(const char *uri,
|
|||||||
if (!(ident = virIdentityGetCurrent()))
|
if (!(ident = virIdentityGetCurrent()))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virIdentityGetParameters(ident, ¶ms, &nparams) < 0)
|
if (!(identparams = virIdentityGetParameters(ident)))
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1828,7 +1827,7 @@ remoteOpenConn(const char *uri,
|
|||||||
VIR_DEBUG("Opened driver %p", *conn);
|
VIR_DEBUG("Opened driver %p", *conn);
|
||||||
|
|
||||||
if (preserveIdentity) {
|
if (preserveIdentity) {
|
||||||
if (virConnectSetIdentity(*conn, params, nparams, 0) < 0)
|
if (virConnectSetIdentity(*conn, identparams->par, identparams->npar, 0) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
VIR_DEBUG("Forwarded current identity to secondary driver");
|
VIR_DEBUG("Forwarded current identity to secondary driver");
|
||||||
@ -1836,7 +1835,6 @@ remoteOpenConn(const char *uri,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virTypedParamsFree(params, nparams);
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -838,17 +838,12 @@ int virIdentitySetParameters(virIdentity *ident,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int virIdentityGetParameters(virIdentity *ident,
|
virTypedParamList *virIdentityGetParameters(virIdentity *ident)
|
||||||
virTypedParameterPtr *params,
|
|
||||||
int *nparams)
|
|
||||||
{
|
{
|
||||||
*params = NULL;
|
virTypedParameter *tmp = NULL;
|
||||||
*nparams = 0;
|
|
||||||
|
|
||||||
if (virTypedParamsCopy(params, ident->params, ident->nparams) < 0)
|
if (virTypedParamsCopy(&tmp, ident->params, ident->nparams) < 0)
|
||||||
return -1;
|
return NULL;
|
||||||
|
|
||||||
*nparams = ident->nparams;
|
return virTypedParamListFromParams(&tmp, ident->nparams);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
#include "virtypedparam.h"
|
||||||
|
|
||||||
#define VIR_TYPE_IDENTITY vir_identity_get_type()
|
#define VIR_TYPE_IDENTITY vir_identity_get_type()
|
||||||
G_DECLARE_FINAL_TYPE(virIdentity, vir_identity, VIR, IDENTITY, GObject);
|
G_DECLARE_FINAL_TYPE(virIdentity, vir_identity, VIR, IDENTITY, GObject);
|
||||||
@ -88,6 +89,4 @@ int virIdentitySetParameters(virIdentity *ident,
|
|||||||
virTypedParameterPtr params,
|
virTypedParameterPtr params,
|
||||||
int nparams);
|
int nparams);
|
||||||
|
|
||||||
int virIdentityGetParameters(virIdentity *ident,
|
virTypedParamList *virIdentityGetParameters(virIdentity *ident);
|
||||||
virTypedParameterPtr *params,
|
|
||||||
int *nparams);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user