Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/locking/lock_driver_sanlock.c | 97 +++++++++++++--------------------------
1 file changed, 31 insertions(+), 66 deletions(-)
diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index 3069b82..579f696 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -70,7 +70,7 @@ typedef virLockManagerSanlockPrivate *virLockManagerSanlockPrivatePtr;
struct _virLockManagerSanlockDriver {
bool requireLeaseForDisks;
- int hostID;
+ unsigned int hostID;
bool autoDiskLease;
char *autoDiskLeasePath;
unsigned int io_timeout;
@@ -103,8 +103,9 @@ struct _virLockManagerSanlockPrivate {
static int virLockManagerSanlockLoadConfig(const char *configFile)
{
virConfPtr conf;
- virConfValuePtr p;
- char *tmp;
+ int ret = -1;
+ char *user = NULL;
+ char *group = NULL;
if (access(configFile, R_OK) == -1) {
if (errno != ENOENT) {
@@ -119,76 +120,40 @@ static int virLockManagerSanlockLoadConfig(const char *configFile)
if (!(conf = virConfReadFile(configFile, 0)))
return -1;
-#define CHECK_TYPE(name, typ) if (p && p->type != (typ)) { \
- virReportError(VIR_ERR_INTERNAL_ERROR, \
- "%s: %s: expected type " #typ, \
- configFile, (name)); \
- virConfFree(conf); \
- return -1; \
- }
+ if (virConfGetValueBool(conf, "auto_disk_leases",
&driver->autoDiskLease) < 0)
+ goto cleanup;
- p = virConfGetValue(conf, "auto_disk_leases");
- CHECK_TYPE("auto_disk_leases", VIR_CONF_ULONG);
- if (p) driver->autoDiskLease = p->l;
+ if (virConfGetValueString(conf, "disk_lease_dir",
&driver->autoDiskLeasePath) < 0)
+ goto cleanup;
- p = virConfGetValue(conf, "disk_lease_dir");
- CHECK_TYPE("disk_lease_dir", VIR_CONF_STRING);
- if (p && p->str) {
- VIR_FREE(driver->autoDiskLeasePath);
- if (VIR_STRDUP(driver->autoDiskLeasePath, p->str) < 0) {
- virConfFree(conf);
- return -1;
- }
- }
+ if (virConfGetValueUInt(conf, "host_id", &driver->hostID) < 0)
+ goto cleanup;
- p = virConfGetValue(conf, "host_id");
- CHECK_TYPE("host_id", VIR_CONF_ULONG);
- if (p) driver->hostID = p->l;
-
- p = virConfGetValue(conf, "require_lease_for_disks");
- CHECK_TYPE("require_lease_for_disks", VIR_CONF_ULONG);
- if (p)
- driver->requireLeaseForDisks = p->l;
- else
- driver->requireLeaseForDisks = !driver->autoDiskLease;
-
- p = virConfGetValue(conf, "io_timeout");
- CHECK_TYPE("io_timeout", VIR_CONF_ULONG);
- if (p) driver->io_timeout = p->l;
-
- p = virConfGetValue(conf, "user");
- CHECK_TYPE("user", VIR_CONF_STRING);
- if (p) {
- if (VIR_STRDUP(tmp, p->str) < 0) {
- virConfFree(conf);
- return -1;
- }
+ driver->requireLeaseForDisks = !driver->autoDiskLease;
+ if (virConfGetValueBool(conf, "require_lease_for_disks",
&driver->requireLeaseForDisks) < 0)
+ goto cleanup;
- if (virGetUserID(tmp, &driver->user) < 0) {
- VIR_FREE(tmp);
- virConfFree(conf);
- return -1;
- }
- VIR_FREE(tmp);
- }
+ if (virConfGetValueUInt(conf, "io_timeout", &driver->io_timeout)
< 0)
+ goto cleanup;
- p = virConfGetValue(conf, "group");
- CHECK_TYPE("group", VIR_CONF_STRING);
- if (p) {
- if (VIR_STRDUP(tmp, p->str) < 0) {
- virConfFree(conf);
- return -1;
- }
- if (virGetGroupID(tmp, &driver->group) < 0) {
- VIR_FREE(tmp);
- virConfFree(conf);
- return -1;
- }
- VIR_FREE(tmp);
- }
+ if (virConfGetValueString(conf, "user", &user) < 0)
+ goto cleanup;
+ if (user &&
+ virGetUserID(user, &driver->user) < 0)
+ goto cleanup;
+ if (virConfGetValueString(conf, "group", &group) < 0)
+ goto cleanup;
+ if (group &&
+ virGetGroupID(group, &driver->group) < 0)
+ goto cleanup;
+
+ ret = 0;
+ cleanup:
virConfFree(conf);
- return 0;
+ VIR_FREE(user);
+ VIR_FREE(group);
+ return ret;
}
/* How much ms sleep before retrying to add a lockspace? */
--
2.7.4