mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +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 {
|
struct _virLockManagerSanlockDriver {
|
||||||
bool requireLeaseForDisks;
|
bool requireLeaseForDisks;
|
||||||
int hostID;
|
unsigned int hostID;
|
||||||
bool autoDiskLease;
|
bool autoDiskLease;
|
||||||
char *autoDiskLeasePath;
|
char *autoDiskLeasePath;
|
||||||
unsigned int io_timeout;
|
unsigned int io_timeout;
|
||||||
@ -103,8 +103,9 @@ struct _virLockManagerSanlockPrivate {
|
|||||||
static int virLockManagerSanlockLoadConfig(const char *configFile)
|
static int virLockManagerSanlockLoadConfig(const char *configFile)
|
||||||
{
|
{
|
||||||
virConfPtr conf;
|
virConfPtr conf;
|
||||||
virConfValuePtr p;
|
int ret = -1;
|
||||||
char *tmp;
|
char *user = NULL;
|
||||||
|
char *group = NULL;
|
||||||
|
|
||||||
if (access(configFile, R_OK) == -1) {
|
if (access(configFile, R_OK) == -1) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
@ -119,76 +120,40 @@ static int virLockManagerSanlockLoadConfig(const char *configFile)
|
|||||||
if (!(conf = virConfReadFile(configFile, 0)))
|
if (!(conf = virConfReadFile(configFile, 0)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#define CHECK_TYPE(name, typ) if (p && p->type != (typ)) { \
|
if (virConfGetValueBool(conf, "auto_disk_leases", &driver->autoDiskLease) < 0)
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
goto cleanup;
|
||||||
"%s: %s: expected type " #typ, \
|
|
||||||
configFile, (name)); \
|
|
||||||
virConfFree(conf); \
|
|
||||||
return -1; \
|
|
||||||
}
|
|
||||||
|
|
||||||
p = virConfGetValue(conf, "auto_disk_leases");
|
if (virConfGetValueString(conf, "disk_lease_dir", &driver->autoDiskLeasePath) < 0)
|
||||||
CHECK_TYPE("auto_disk_leases", VIR_CONF_ULONG);
|
goto cleanup;
|
||||||
if (p) driver->autoDiskLease = p->l;
|
|
||||||
|
|
||||||
p = virConfGetValue(conf, "disk_lease_dir");
|
if (virConfGetValueUInt(conf, "host_id", &driver->hostID) < 0)
|
||||||
CHECK_TYPE("disk_lease_dir", VIR_CONF_STRING);
|
goto cleanup;
|
||||||
if (p && p->str) {
|
|
||||||
VIR_FREE(driver->autoDiskLeasePath);
|
|
||||||
if (VIR_STRDUP(driver->autoDiskLeasePath, p->str) < 0) {
|
|
||||||
virConfFree(conf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p = virConfGetValue(conf, "host_id");
|
driver->requireLeaseForDisks = !driver->autoDiskLease;
|
||||||
CHECK_TYPE("host_id", VIR_CONF_ULONG);
|
if (virConfGetValueBool(conf, "require_lease_for_disks", &driver->requireLeaseForDisks) < 0)
|
||||||
if (p) driver->hostID = p->l;
|
goto cleanup;
|
||||||
|
|
||||||
p = virConfGetValue(conf, "require_lease_for_disks");
|
if (virConfGetValueUInt(conf, "io_timeout", &driver->io_timeout) < 0)
|
||||||
CHECK_TYPE("require_lease_for_disks", VIR_CONF_ULONG);
|
goto cleanup;
|
||||||
if (p)
|
|
||||||
driver->requireLeaseForDisks = p->l;
|
|
||||||
else
|
|
||||||
driver->requireLeaseForDisks = !driver->autoDiskLease;
|
|
||||||
|
|
||||||
p = virConfGetValue(conf, "io_timeout");
|
if (virConfGetValueString(conf, "user", &user) < 0)
|
||||||
CHECK_TYPE("io_timeout", VIR_CONF_ULONG);
|
goto cleanup;
|
||||||
if (p) driver->io_timeout = p->l;
|
if (user &&
|
||||||
|
virGetUserID(user, &driver->user) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
p = virConfGetValue(conf, "user");
|
if (virConfGetValueString(conf, "group", &group) < 0)
|
||||||
CHECK_TYPE("user", VIR_CONF_STRING);
|
goto cleanup;
|
||||||
if (p) {
|
if (group &&
|
||||||
if (VIR_STRDUP(tmp, p->str) < 0) {
|
virGetGroupID(group, &driver->group) < 0)
|
||||||
virConfFree(conf);
|
goto cleanup;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virGetUserID(tmp, &driver->user) < 0) {
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
virConfFree(conf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
virConfFree(conf);
|
virConfFree(conf);
|
||||||
return 0;
|
VIR_FREE(user);
|
||||||
|
VIR_FREE(group);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* How much ms sleep before retrying to add a lockspace? */
|
/* How much ms sleep before retrying to add a lockspace? */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user