mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
virLockManagerSanlockAddLease: Refactor cleanup
Use g_autofree and remove the 'cleanup' section and 'ret' variable. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
add18b06c7
commit
30a42dcddc
@ -528,12 +528,11 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
|||||||
bool shared)
|
bool shared)
|
||||||
{
|
{
|
||||||
virLockManagerSanlockPrivatePtr priv = lock->privateData;
|
virLockManagerSanlockPrivatePtr priv = lock->privateData;
|
||||||
int ret = -1;
|
g_autofree struct sanlk_resource *res = NULL;
|
||||||
struct sanlk_resource *res = NULL;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0)
|
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
res->flags = shared ? SANLK_RES_SHARED : 0;
|
res->flags = shared ? SANLK_RES_SHARED : 0;
|
||||||
res->num_disks = 1;
|
res->num_disks = 1;
|
||||||
@ -541,7 +540,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Resource name '%s' exceeds %d characters"),
|
_("Resource name '%s' exceeds %d characters"),
|
||||||
name, SANLK_NAME_LEN);
|
name, SANLK_NAME_LEN);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nparams; i++) {
|
for (i = 0; i < nparams; i++) {
|
||||||
@ -550,7 +549,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Lease path '%s' exceeds %d characters"),
|
_("Lease path '%s' exceeds %d characters"),
|
||||||
params[i].value.str, SANLK_PATH_LEN);
|
params[i].value.str, SANLK_PATH_LEN);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (STREQ(params[i].key, "offset")) {
|
} else if (STREQ(params[i].key, "offset")) {
|
||||||
res->disks[0].offset = params[i].value.ul;
|
res->disks[0].offset = params[i].value.ul;
|
||||||
@ -559,20 +558,15 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Resource lockspace '%s' exceeds %d characters"),
|
_("Resource lockspace '%s' exceeds %d characters"),
|
||||||
params[i].value.str, SANLK_NAME_LEN);
|
params[i].value.str, SANLK_NAME_LEN);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->res_args[priv->res_count] = res;
|
priv->res_args[priv->res_count] = g_steal_pointer(&res);
|
||||||
priv->res_count++;
|
priv->res_count++;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
if (ret == -1)
|
|
||||||
VIR_FREE(res);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user