mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
sanlock: convert to typesafe virConf accessors
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
b474952eb7
commit
544f087e41
@ -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;
|
||||
if (virConfGetValueBool(conf, "require_lease_for_disks", &driver->requireLeaseForDisks) < 0)
|
||||
goto cleanup;
|
||||
|
||||
p = virConfGetValue(conf, "io_timeout");
|
||||
CHECK_TYPE("io_timeout", VIR_CONF_ULONG);
|
||||
if (p) driver->io_timeout = p->l;
|
||||
if (virConfGetValueUInt(conf, "io_timeout", &driver->io_timeout) < 0)
|
||||
goto cleanup;
|
||||
|
||||
p = virConfGetValue(conf, "user");
|
||||
CHECK_TYPE("user", VIR_CONF_STRING);
|
||||
if (p) {
|
||||
if (VIR_STRDUP(tmp, p->str) < 0) {
|
||||
virConfFree(conf);
|
||||
return -1;
|
||||
}
|
||||
if (virConfGetValueString(conf, "user", &user) < 0)
|
||||
goto cleanup;
|
||||
if (user &&
|
||||
virGetUserID(user, &driver->user) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virGetUserID(tmp, &driver->user) < 0) {
|
||||
VIR_FREE(tmp);
|
||||
virConfFree(conf);
|
||||
return -1;
|
||||
}
|
||||
VIR_FREE(tmp);
|
||||
}
|
||||
if (virConfGetValueString(conf, "group", &group) < 0)
|
||||
goto cleanup;
|
||||
if (group &&
|
||||
virGetGroupID(group, &driver->group) < 0)
|
||||
goto cleanup;
|
||||
|
||||
p = virConfGetValue(conf, "group");
|
||||
CHECK_TYPE("group", VIR_CONF_STRING);
|
||||
if (p) {
|
||||
if (VIR_STRDUP(tmp, p->str) < 0) {
|
||||
ret = 0;
|
||||
cleanup:
|
||||
virConfFree(conf);
|
||||
return -1;
|
||||
}
|
||||
if (virGetGroupID(tmp, &driver->group) < 0) {
|
||||
VIR_FREE(tmp);
|
||||
virConfFree(conf);
|
||||
return -1;
|
||||
}
|
||||
VIR_FREE(tmp);
|
||||
}
|
||||
|
||||
virConfFree(conf);
|
||||
return 0;
|
||||
VIR_FREE(user);
|
||||
VIR_FREE(group);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* How much ms sleep before retrying to add a lockspace? */
|
||||
|
Loading…
x
Reference in New Issue
Block a user