mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-06 13:05:20 +00:00
libxlMakeNetworkDiskSrc: Refactor cleanup
Automatically unref the 'conn' object and remove the 'cleanup' section and 'ret' variable. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
014b71a3a7
commit
c655601d69
@ -1026,10 +1026,9 @@ libxlMakeNetworkDiskSrcStr(virStorageSource *src,
|
|||||||
static int
|
static int
|
||||||
libxlMakeNetworkDiskSrc(virStorageSource *src, char **srcstr)
|
libxlMakeNetworkDiskSrc(virStorageSource *src, char **srcstr)
|
||||||
{
|
{
|
||||||
virConnectPtr conn = NULL;
|
g_autoptr(virConnect) conn = NULL;
|
||||||
g_autofree char *base64secret = NULL;
|
g_autofree char *base64secret = NULL;
|
||||||
char *username = NULL;
|
char *username = NULL;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
*srcstr = NULL;
|
*srcstr = NULL;
|
||||||
if (src->auth && src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD) {
|
if (src->auth && src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD) {
|
||||||
@ -1038,16 +1037,16 @@ libxlMakeNetworkDiskSrc(virStorageSource *src, char **srcstr)
|
|||||||
VIR_IDENTITY_AUTORESTORE virIdentity *oldident = virIdentityElevateCurrent();
|
VIR_IDENTITY_AUTORESTORE virIdentity *oldident = virIdentityElevateCurrent();
|
||||||
|
|
||||||
if (!oldident)
|
if (!oldident)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
username = src->auth->username;
|
username = src->auth->username;
|
||||||
if (!(conn = virConnectOpen("xen:///system")))
|
if (!(conn = virConnectOpen("xen:///system")))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virSecretGetSecretString(conn, &src->auth->seclookupdef,
|
if (virSecretGetSecretString(conn, &src->auth->seclookupdef,
|
||||||
VIR_SECRET_USAGE_TYPE_CEPH,
|
VIR_SECRET_USAGE_TYPE_CEPH,
|
||||||
&secret, &secretlen) < 0)
|
&secret, &secretlen) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* RBD expects an encoded secret */
|
/* RBD expects an encoded secret */
|
||||||
base64secret = g_base64_encode(secret, secretlen);
|
base64secret = g_base64_encode(secret, secretlen);
|
||||||
@ -1058,13 +1057,9 @@ libxlMakeNetworkDiskSrc(virStorageSource *src, char **srcstr)
|
|||||||
virSecureEraseString(base64secret);
|
virSecureEraseString(base64secret);
|
||||||
|
|
||||||
if (!*srcstr)
|
if (!*srcstr)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnref(conn);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user