Signed-off-by: Jiang Jiacheng <jiangjiacheng(a)huawei.com>
---
src/locking/lock_driver_lockd.c | 36 +++++++++---------------
src/locking/lock_driver_sanlock.c | 46 ++++++++++++-------------------
2 files changed, 31 insertions(+), 51 deletions(-)
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index e902b01463..4df12e0105 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -190,8 +190,8 @@ static virNetClient *virLockManagerLockDaemonConnectionNew(bool
privileged,
virNetClientProgram **prog)
{
virNetClient *client = NULL;
- char *lockdpath;
- char *daemonPath = NULL;
+ g_autofree char *lockdpath = NULL;
+ g_autofree char *daemonPath = NULL;
*prog = NULL;
@@ -220,14 +220,9 @@ static virNetClient *virLockManagerLockDaemonConnectionNew(bool
privileged,
if (virNetClientAddProgram(client, *prog) < 0)
goto error;
- VIR_FREE(daemonPath);
- VIR_FREE(lockdpath);
-
return client;
error:
- VIR_FREE(daemonPath);
- VIR_FREE(lockdpath);
virNetClientClose(client);
virObjectUnref(client);
virObjectUnref(*prog);
@@ -517,10 +512,9 @@ static int virLockManagerLockDaemonAddResource(virLockManager *lock,
unsigned int flags)
{
virLockManagerLockDaemonPrivate *priv = lock->privateData;
- char *newName = NULL;
- char *newLockspace = NULL;
+ g_autofree char *newName = NULL;
+ g_autofree char *newLockspace = NULL;
bool autoCreate = false;
- int ret = -1;
virCheckFlags(VIR_LOCK_MANAGER_RESOURCE_READONLY |
VIR_LOCK_MANAGER_RESOURCE_SHARED, -1);
@@ -533,7 +527,7 @@ static int virLockManagerLockDaemonAddResource(virLockManager *lock,
if (params || nparams) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unexpected parameters for disk resource"));
- goto cleanup;
+ return -1;
}
if (!driver->autoDiskLease) {
if (!(flags & (VIR_LOCK_MANAGER_RESOURCE_SHARED |
@@ -549,7 +543,7 @@ static int virLockManagerLockDaemonAddResource(virLockManager *lock,
driver->lvmLockSpaceDir) {
VIR_DEBUG("Trying to find an LVM UUID for %s", name);
if (virLockManagerGetLVMKey(name, &newName) < 0)
- goto cleanup;
+ return -1;
if (newName) {
VIR_DEBUG("Got an LVM UUID %s for %s", newName, name);
@@ -565,7 +559,7 @@ static int virLockManagerLockDaemonAddResource(virLockManager *lock,
driver->scsiLockSpaceDir) {
VIR_DEBUG("Trying to find an SCSI ID for %s", name);
if (virStorageFileGetSCSIKey(name, &newName, false) < 0)
- goto cleanup;
+ return -1;
if (newName) {
VIR_DEBUG("Got an SCSI ID %s for %s", newName, name);
@@ -580,7 +574,7 @@ static int virLockManagerLockDaemonAddResource(virLockManager *lock,
if (driver->fileLockSpaceDir) {
newLockspace = g_strdup(driver->fileLockSpaceDir);
if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &newName) < 0)
- goto cleanup;
+ return -1;
autoCreate = true;
VIR_DEBUG("Using indirect lease %s for %s", newName, name);
} else {
@@ -599,7 +593,7 @@ static int virLockManagerLockDaemonAddResource(virLockManager *lock,
if (params[i].value.ul != 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Offset must be zero for this lock
manager"));
- goto cleanup;
+ return -1;
}
} else if (STREQ(params[i].key, "lockspace")) {
lockspace = params[i].value.str;
@@ -609,13 +603,13 @@ static int virLockManagerLockDaemonAddResource(virLockManager
*lock,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected parameter %s for lease
resource"),
params[i].key);
- goto cleanup;
+ return -1;
}
}
if (!path || !lockspace) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing path or lockspace for lease resource"));
- goto cleanup;
+ return -1;
}
newLockspace = g_strdup_printf("%s/%s", path, lockspace);
newName = g_strdup(name);
@@ -625,7 +619,7 @@ static int virLockManagerLockDaemonAddResource(virLockManager *lock,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown lock manager object type %d"),
type);
- goto cleanup;
+ return -1;
}
VIR_EXPAND_N(priv->resources, priv->nresources, 1);
@@ -640,11 +634,7 @@ static int virLockManagerLockDaemonAddResource(virLockManager *lock,
priv->resources[priv->nresources-1].flags |=
VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE;
- ret = 0;
- cleanup:
- VIR_FREE(newLockspace);
- VIR_FREE(newName);
- return ret;
+ return 0;
}
diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index 2dceb1eefc..438779f926 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -118,9 +118,8 @@ virLockManagerSanlockLoadConfig(virLockManagerSanlockDriver *driver,
const char *configFile)
{
g_autoptr(virConf) conf = NULL;
- int ret = -1;
- char *user = NULL;
- char *group = NULL;
+ g_autofree char *user = NULL;
+ g_autofree char *group = NULL;
if (access(configFile, R_OK) == -1) {
if (errno != ENOENT) {
@@ -136,38 +135,34 @@ virLockManagerSanlockLoadConfig(virLockManagerSanlockDriver
*driver,
return -1;
if (virConfGetValueBool(conf, "auto_disk_leases",
&driver->autoDiskLease) < 0)
- goto cleanup;
+ return -1;
if (virConfGetValueString(conf, "disk_lease_dir",
&driver->autoDiskLeasePath) < 0)
- goto cleanup;
+ return -1;
if (virConfGetValueUInt(conf, "host_id", &driver->hostID) < 0)
- goto cleanup;
+ return -1;
driver->requireLeaseForDisks = !driver->autoDiskLease;
if (virConfGetValueBool(conf, "require_lease_for_disks",
&driver->requireLeaseForDisks) < 0)
- goto cleanup;
+ return -1;
if (virConfGetValueUInt(conf, "io_timeout", &driver->io_timeout)
< 0)
- goto cleanup;
+ return -1;
if (virConfGetValueString(conf, "user", &user) < 0)
- goto cleanup;
+ return -1;
if (user &&
virGetUserID(user, &driver->user) < 0)
- goto cleanup;
+ return -1;
if (virConfGetValueString(conf, "group", &group) < 0)
- goto cleanup;
+ return -1;
if (group &&
virGetGroupID(group, &driver->group) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- VIR_FREE(user);
- VIR_FREE(group);
- return ret;
+ return 0;
}
static int
@@ -778,8 +773,7 @@ virLockManagerSanlockRegisterKillscript(int sock,
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
char *path;
- char *args = NULL;
- int ret = -1;
+ g_autofree char *args = NULL;
int rv;
switch (action) {
@@ -796,7 +790,7 @@ virLockManagerSanlockRegisterKillscript(int sock,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Failure action %s is not supported by sanlock"),
virDomainLockFailureTypeToString(action));
- goto cleanup;
+ return -1;
}
virBufferEscape(&buf, '\\', "\\ ", "%s", vmuri);
@@ -820,14 +814,14 @@ virLockManagerSanlockRegisterKillscript(int sock,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Sanlock helper path is longer than %d:
'%s'"),
SANLK_HELPER_PATH_LEN - 1, path);
- goto cleanup;
+ return -1;
}
if (strlen(args) >= SANLK_HELPER_ARGS_LEN) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Sanlock helper arguments are longer than %d:"
" '%s'"),
SANLK_HELPER_ARGS_LEN - 1, args);
- goto cleanup;
+ return -1;
}
if ((rv = sanlock_killpath(sock, 0, path, args)) < 0) {
@@ -842,14 +836,10 @@ virLockManagerSanlockRegisterKillscript(int sock,
_("Failed to register lock failure"
" action"));
}
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- VIR_FREE(args);
- return ret;
+ return 0;
}
static int virLockManagerSanlockAcquire(virLockManager *lock,
--
2.33.0