mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 18:05:20 +00:00
Adapt to VIR_ALLOC and virAsprintf in src/locking/*
This commit is contained in:
parent
23b861f52e
commit
35048f314a
@ -132,10 +132,8 @@ virLockDaemonNew(bool privileged)
|
|||||||
{
|
{
|
||||||
virLockDaemonPtr lockd;
|
virLockDaemonPtr lockd;
|
||||||
|
|
||||||
if (VIR_ALLOC(lockd) < 0) {
|
if (VIR_ALLOC(lockd) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (virMutexInit(&lockd->lock) < 0) {
|
if (virMutexInit(&lockd->lock) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -177,10 +175,8 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged)
|
|||||||
size_t i;
|
size_t i;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (VIR_ALLOC(lockd) < 0) {
|
if (VIR_ALLOC(lockd) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (virMutexInit(&lockd->lock) < 0) {
|
if (virMutexInit(&lockd->lock) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -388,7 +384,6 @@ virLockDaemonPidFilePath(bool privileged,
|
|||||||
|
|
||||||
if (virAsprintf(pidfile, "%s/virtlockd.pid", rundir) < 0) {
|
if (virAsprintf(pidfile, "%s/virtlockd.pid", rundir) < 0) {
|
||||||
VIR_FREE(rundir);
|
VIR_FREE(rundir);
|
||||||
virReportOOMError();
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,7 +420,6 @@ virLockDaemonUnixSocketPaths(bool privileged,
|
|||||||
|
|
||||||
if (virAsprintf(sockfile, "%s/virtlockd-sock", rundir) < 0) {
|
if (virAsprintf(sockfile, "%s/virtlockd-sock", rundir) < 0) {
|
||||||
VIR_FREE(rundir);
|
VIR_FREE(rundir);
|
||||||
virReportOOMError();
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +493,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
|
|||||||
char *tmp;
|
char *tmp;
|
||||||
if (access("/run/systemd/journal/socket", W_OK) >= 0) {
|
if (access("/run/systemd/journal/socket", W_OK) >= 0) {
|
||||||
if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0)
|
if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0)
|
||||||
goto no_memory;
|
goto error;
|
||||||
virLogParseOutputs(tmp);
|
virLogParseOutputs(tmp);
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
}
|
}
|
||||||
@ -517,7 +511,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
|
|||||||
if (virAsprintf(&tmp, "%d:file:%s/log/libvirt/virtlockd.log",
|
if (virAsprintf(&tmp, "%d:file:%s/log/libvirt/virtlockd.log",
|
||||||
virLogGetDefaultPriority(),
|
virLogGetDefaultPriority(),
|
||||||
LOCALSTATEDIR) == -1)
|
LOCALSTATEDIR) == -1)
|
||||||
goto no_memory;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
char *logdir = virGetUserCacheDirectory();
|
char *logdir = virGetUserCacheDirectory();
|
||||||
mode_t old_umask;
|
mode_t old_umask;
|
||||||
@ -535,13 +529,13 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
|
|||||||
if (virAsprintf(&tmp, "%d:file:%s/virtlockd.log",
|
if (virAsprintf(&tmp, "%d:file:%s/virtlockd.log",
|
||||||
virLogGetDefaultPriority(), logdir) == -1) {
|
virLogGetDefaultPriority(), logdir) == -1) {
|
||||||
VIR_FREE(logdir);
|
VIR_FREE(logdir);
|
||||||
goto no_memory;
|
goto error;
|
||||||
}
|
}
|
||||||
VIR_FREE(logdir);
|
VIR_FREE(logdir);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0)
|
if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0)
|
||||||
goto no_memory;
|
goto error;
|
||||||
}
|
}
|
||||||
virLogParseOutputs(tmp);
|
virLogParseOutputs(tmp);
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
@ -555,8 +549,6 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
|
||||||
virReportOOMError();
|
|
||||||
error:
|
error:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -784,14 +776,12 @@ virLockDaemonClientNew(virNetServerClientPtr client,
|
|||||||
unsigned long long timestamp;
|
unsigned long long timestamp;
|
||||||
bool privileged = opaque != NULL;
|
bool privileged = opaque != NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(priv) < 0) {
|
if (VIR_ALLOC(priv) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (virMutexInit(&priv->lock) < 0) {
|
if (virMutexInit(&priv->lock) < 0) {
|
||||||
VIR_FREE(priv);
|
VIR_FREE(priv);
|
||||||
virReportOOMError();
|
virReportSystemError(errno, "%s", _("unable to init mutex"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -940,12 +930,7 @@ virLockDaemonGetExecRestartMagic(void)
|
|||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
if (virAsprintf(&ret, "%lld",
|
ignore_value(virAsprintf(&ret, "%lld", (long long int)getpid()));
|
||||||
(long long int)getpid()) < 0) {
|
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,15 +93,13 @@ virLockDaemonConfigFilePath(bool privileged, char **configfile)
|
|||||||
|
|
||||||
if (virAsprintf(configfile, "%s/virtlockd.conf", configdir) < 0) {
|
if (virAsprintf(configfile, "%s/virtlockd.conf", configdir) < 0) {
|
||||||
VIR_FREE(configdir);
|
VIR_FREE(configdir);
|
||||||
goto no_memory;
|
goto error;
|
||||||
}
|
}
|
||||||
VIR_FREE(configdir);
|
VIR_FREE(configdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
|
||||||
virReportOOMError();
|
|
||||||
error:
|
error:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -112,10 +110,8 @@ virLockDaemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
|
|||||||
{
|
{
|
||||||
virLockDaemonConfigPtr data;
|
virLockDaemonConfigPtr data;
|
||||||
|
|
||||||
if (VIR_ALLOC(data) < 0) {
|
if (VIR_ALLOC(data) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
data->log_buffer_size = 64;
|
data->log_buffer_size = 64;
|
||||||
|
|
||||||
|
@ -181,7 +181,6 @@ static char *virLockManagerLockDaemonPath(bool privileged)
|
|||||||
|
|
||||||
if (virAsprintf(&path, "%s/virtlockd-sock", rundir) < 0) {
|
if (virAsprintf(&path, "%s/virtlockd-sock", rundir) < 0) {
|
||||||
VIR_FREE(rundir);
|
VIR_FREE(rundir);
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,10 +374,8 @@ static int virLockManagerLockDaemonInit(unsigned int version,
|
|||||||
if (driver)
|
if (driver)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (VIR_ALLOC(driver) < 0) {
|
if (VIR_ALLOC(driver) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
driver->requireLeaseForDisks = true;
|
driver->requireLeaseForDisks = true;
|
||||||
driver->autoDiskLease = true;
|
driver->autoDiskLease = true;
|
||||||
@ -451,10 +448,8 @@ static int virLockManagerLockDaemonNew(virLockManagerPtr lock,
|
|||||||
|
|
||||||
virCheckFlags(VIR_LOCK_MANAGER_USES_STATE, -1);
|
virCheckFlags(VIR_LOCK_MANAGER_USES_STATE, -1);
|
||||||
|
|
||||||
if (VIR_ALLOC(priv) < 0) {
|
if (VIR_ALLOC(priv) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
lock->privateData = priv;
|
lock->privateData = priv;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -525,10 +520,8 @@ static char *virLockManagerLockDaemonDiskLeaseName(const char *path)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(ret, (SHA256_DIGEST_SIZE * 2) + 1) < 0) {
|
if (VIR_ALLOC_N(ret, (SHA256_DIGEST_SIZE * 2) + 1) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < SHA256_DIGEST_SIZE; i++) {
|
for (i = 0; i < SHA256_DIGEST_SIZE; i++) {
|
||||||
ret[i*2] = hex[(buf[i] >> 4) & 0xf];
|
ret[i*2] = hex[(buf[i] >> 4) & 0xf];
|
||||||
@ -613,7 +606,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
|||||||
if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0)
|
if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (!(newName = virLockManagerLockDaemonDiskLeaseName(name)))
|
if (!(newName = virLockManagerLockDaemonDiskLeaseName(name)))
|
||||||
goto no_memory;
|
goto error;
|
||||||
autoCreate = true;
|
autoCreate = true;
|
||||||
VIR_DEBUG("Using indirect lease %s for %s", newName, name);
|
VIR_DEBUG("Using indirect lease %s for %s", newName, name);
|
||||||
} else {
|
} else {
|
||||||
@ -653,10 +646,8 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (virAsprintf(&newLockspace, "%s/%s",
|
if (virAsprintf(&newLockspace, "%s/%s",
|
||||||
path, lockspace) < 0) {
|
path, lockspace) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
if (VIR_STRDUP(newName, name) < 0)
|
if (VIR_STRDUP(newName, name) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -669,7 +660,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_EXPAND_N(priv->resources, priv->nresources, 1) < 0)
|
if (VIR_EXPAND_N(priv->resources, priv->nresources, 1) < 0)
|
||||||
goto no_memory;
|
goto error;
|
||||||
|
|
||||||
priv->resources[priv->nresources-1].lockspace = newLockspace;
|
priv->resources[priv->nresources-1].lockspace = newLockspace;
|
||||||
priv->resources[priv->nresources-1].name = newName;
|
priv->resources[priv->nresources-1].name = newName;
|
||||||
@ -684,8 +675,6 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
|
||||||
virReportOOMError();
|
|
||||||
error:
|
error:
|
||||||
VIR_FREE(newLockspace);
|
VIR_FREE(newLockspace);
|
||||||
VIR_FREE(newName);
|
VIR_FREE(newName);
|
||||||
|
@ -198,10 +198,8 @@ static int virLockManagerSanlockSetupLockspace(void)
|
|||||||
|
|
||||||
if (virAsprintf(&path, "%s/%s",
|
if (virAsprintf(&path, "%s/%s",
|
||||||
driver->autoDiskLeasePath,
|
driver->autoDiskLeasePath,
|
||||||
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0) {
|
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
if (!virStrcpyStatic(ls.name,
|
if (!virStrcpyStatic(ls.name,
|
||||||
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE)) {
|
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE)) {
|
||||||
@ -395,10 +393,8 @@ static int virLockManagerSanlockInit(unsigned int version,
|
|||||||
if (driver)
|
if (driver)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (VIR_ALLOC(driver) < 0) {
|
if (VIR_ALLOC(driver) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
driver->requireLeaseForDisks = true;
|
driver->requireLeaseForDisks = true;
|
||||||
driver->hostID = 0;
|
driver->hostID = 0;
|
||||||
@ -467,10 +463,8 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(priv) < 0) {
|
if (VIR_ALLOC(priv) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
priv->flags = flags;
|
priv->flags = flags;
|
||||||
|
|
||||||
@ -559,10 +553,8 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
|||||||
struct sanlk_resource *res = NULL;
|
struct sanlk_resource *res = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) {
|
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
res->flags = shared ? SANLK_RES_SHARED : 0;
|
res->flags = shared ? SANLK_RES_SHARED : 0;
|
||||||
res->num_disks = 1;
|
res->num_disks = 1;
|
||||||
@ -624,10 +616,8 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) {
|
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
res->flags = shared ? SANLK_RES_SHARED : 0;
|
res->flags = shared ? SANLK_RES_SHARED : 0;
|
||||||
res->num_disks = 1;
|
res->num_disks = 1;
|
||||||
@ -635,10 +625,8 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virAsprintf(&path, "%s/%s",
|
if (virAsprintf(&path, "%s/%s",
|
||||||
driver->autoDiskLeasePath, res->name) < 0) {
|
driver->autoDiskLeasePath, res->name) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
if (!virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN)) {
|
if (!virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Lease path '%s' exceeds %d characters"),
|
_("Lease path '%s' exceeds %d characters"),
|
||||||
@ -918,10 +906,8 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(opt) < 0) {
|
if (VIR_ALLOC(opt) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (!virStrcpy(opt->owner_name, priv->vm_name, SANLK_NAME_LEN)) {
|
if (!virStrcpy(opt->owner_name, priv->vm_name, SANLK_NAME_LEN)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
@ -143,10 +143,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
|
|||||||
name, driverName, configDir, flags);
|
name, driverName, configDir, flags);
|
||||||
|
|
||||||
if (virAsprintf(&configFile, "%s/%s-%s.conf",
|
if (virAsprintf(&configFile, "%s/%s-%s.conf",
|
||||||
configDir, driverName, name) < 0) {
|
configDir, driverName, name) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (STREQ(name, "nop")) {
|
if (STREQ(name, "nop")) {
|
||||||
driver = &virLockDriverNop;
|
driver = &virLockDriverNop;
|
||||||
@ -156,10 +154,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
|
|||||||
|
|
||||||
VIR_DEBUG("Module load %s from %s", name, moddir);
|
VIR_DEBUG("Module load %s from %s", name, moddir);
|
||||||
|
|
||||||
if (virAsprintf(&modfile, "%s/%s.so", moddir, name) < 0) {
|
if (virAsprintf(&modfile, "%s/%s.so", moddir, name) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (access(modfile, R_OK) < 0) {
|
if (access(modfile, R_OK) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
@ -186,10 +182,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
|
|||||||
if (driver->drvInit(VIR_LOCK_MANAGER_VERSION, configFile, flags) < 0)
|
if (driver->drvInit(VIR_LOCK_MANAGER_VERSION, configFile, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_ALLOC(plugin) < 0) {
|
if (VIR_ALLOC(plugin) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
plugin->driver = driver;
|
plugin->driver = driver;
|
||||||
plugin->handle = handle;
|
plugin->handle = handle;
|
||||||
@ -321,10 +315,8 @@ virLockManagerPtr virLockManagerNew(virLockDriverPtr driver,
|
|||||||
|
|
||||||
CHECK_DRIVER(drvNew, NULL);
|
CHECK_DRIVER(drvNew, NULL);
|
||||||
|
|
||||||
if (VIR_ALLOC(lock) < 0) {
|
if (VIR_ALLOC(lock) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
lock->driver = driver;
|
lock->driver = driver;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user