Adapt to VIR_ALLOC and virAsprintf in src/locking/*

This commit is contained in:
Michal Privoznik 2013-07-04 12:11:02 +02:00
parent 23b861f52e
commit 35048f314a
5 changed files with 28 additions and 80 deletions

View File

@ -132,10 +132,8 @@ virLockDaemonNew(bool privileged)
{
virLockDaemonPtr lockd;
if (VIR_ALLOC(lockd) < 0) {
virReportOOMError();
if (VIR_ALLOC(lockd) < 0)
return NULL;
}
if (virMutexInit(&lockd->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -177,10 +175,8 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged)
size_t i;
int n;
if (VIR_ALLOC(lockd) < 0) {
virReportOOMError();
if (VIR_ALLOC(lockd) < 0)
return NULL;
}
if (virMutexInit(&lockd->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -388,7 +384,6 @@ virLockDaemonPidFilePath(bool privileged,
if (virAsprintf(pidfile, "%s/virtlockd.pid", rundir) < 0) {
VIR_FREE(rundir);
virReportOOMError();
goto error;
}
@ -425,7 +420,6 @@ virLockDaemonUnixSocketPaths(bool privileged,
if (virAsprintf(sockfile, "%s/virtlockd-sock", rundir) < 0) {
VIR_FREE(rundir);
virReportOOMError();
goto error;
}
@ -499,7 +493,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
char *tmp;
if (access("/run/systemd/journal/socket", W_OK) >= 0) {
if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0)
goto no_memory;
goto error;
virLogParseOutputs(tmp);
VIR_FREE(tmp);
}
@ -517,7 +511,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
if (virAsprintf(&tmp, "%d:file:%s/log/libvirt/virtlockd.log",
virLogGetDefaultPriority(),
LOCALSTATEDIR) == -1)
goto no_memory;
goto error;
} else {
char *logdir = virGetUserCacheDirectory();
mode_t old_umask;
@ -535,13 +529,13 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
if (virAsprintf(&tmp, "%d:file:%s/virtlockd.log",
virLogGetDefaultPriority(), logdir) == -1) {
VIR_FREE(logdir);
goto no_memory;
goto error;
}
VIR_FREE(logdir);
}
} else {
if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0)
goto no_memory;
goto error;
}
virLogParseOutputs(tmp);
VIR_FREE(tmp);
@ -555,8 +549,6 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
return 0;
no_memory:
virReportOOMError();
error:
return -1;
}
@ -784,14 +776,12 @@ virLockDaemonClientNew(virNetServerClientPtr client,
unsigned long long timestamp;
bool privileged = opaque != NULL;
if (VIR_ALLOC(priv) < 0) {
virReportOOMError();
if (VIR_ALLOC(priv) < 0)
return NULL;
}
if (virMutexInit(&priv->lock) < 0) {
VIR_FREE(priv);
virReportOOMError();
virReportSystemError(errno, "%s", _("unable to init mutex"));
return NULL;
}
@ -940,12 +930,7 @@ virLockDaemonGetExecRestartMagic(void)
{
char *ret;
if (virAsprintf(&ret, "%lld",
(long long int)getpid()) < 0) {
virReportOOMError();
return NULL;
}
ignore_value(virAsprintf(&ret, "%lld", (long long int)getpid()));
return ret;
}

View File

@ -93,15 +93,13 @@ virLockDaemonConfigFilePath(bool privileged, char **configfile)
if (virAsprintf(configfile, "%s/virtlockd.conf", configdir) < 0) {
VIR_FREE(configdir);
goto no_memory;
goto error;
}
VIR_FREE(configdir);
}
return 0;
no_memory:
virReportOOMError();
error:
return -1;
}
@ -112,10 +110,8 @@ virLockDaemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
{
virLockDaemonConfigPtr data;
if (VIR_ALLOC(data) < 0) {
virReportOOMError();
if (VIR_ALLOC(data) < 0)
return NULL;
}
data->log_buffer_size = 64;

View File

@ -181,7 +181,6 @@ static char *virLockManagerLockDaemonPath(bool privileged)
if (virAsprintf(&path, "%s/virtlockd-sock", rundir) < 0) {
VIR_FREE(rundir);
virReportOOMError();
return NULL;
}
@ -375,10 +374,8 @@ static int virLockManagerLockDaemonInit(unsigned int version,
if (driver)
return 0;
if (VIR_ALLOC(driver) < 0) {
virReportOOMError();
if (VIR_ALLOC(driver) < 0)
return -1;
}
driver->requireLeaseForDisks = true;
driver->autoDiskLease = true;
@ -451,10 +448,8 @@ static int virLockManagerLockDaemonNew(virLockManagerPtr lock,
virCheckFlags(VIR_LOCK_MANAGER_USES_STATE, -1);
if (VIR_ALLOC(priv) < 0) {
virReportOOMError();
if (VIR_ALLOC(priv) < 0)
return -1;
}
lock->privateData = priv;
switch (type) {
@ -525,10 +520,8 @@ static char *virLockManagerLockDaemonDiskLeaseName(const char *path)
return NULL;
}
if (VIR_ALLOC_N(ret, (SHA256_DIGEST_SIZE * 2) + 1) < 0) {
virReportOOMError();
if (VIR_ALLOC_N(ret, (SHA256_DIGEST_SIZE * 2) + 1) < 0)
return NULL;
}
for (i = 0; i < SHA256_DIGEST_SIZE; i++) {
ret[i*2] = hex[(buf[i] >> 4) & 0xf];
@ -613,7 +606,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0)
goto error;
if (!(newName = virLockManagerLockDaemonDiskLeaseName(name)))
goto no_memory;
goto error;
autoCreate = true;
VIR_DEBUG("Using indirect lease %s for %s", newName, name);
} else {
@ -653,10 +646,8 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
return -1;
}
if (virAsprintf(&newLockspace, "%s/%s",
path, lockspace) < 0) {
virReportOOMError();
path, lockspace) < 0)
return -1;
}
if (VIR_STRDUP(newName, name) < 0)
goto error;
@ -669,7 +660,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
}
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].name = newName;
@ -684,8 +675,6 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
return 0;
no_memory:
virReportOOMError();
error:
VIR_FREE(newLockspace);
VIR_FREE(newName);

View File

@ -198,10 +198,8 @@ static int virLockManagerSanlockSetupLockspace(void)
if (virAsprintf(&path, "%s/%s",
driver->autoDiskLeasePath,
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0) {
virReportOOMError();
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0)
goto error;
}
if (!virStrcpyStatic(ls.name,
VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE)) {
@ -395,10 +393,8 @@ static int virLockManagerSanlockInit(unsigned int version,
if (driver)
return 0;
if (VIR_ALLOC(driver) < 0) {
virReportOOMError();
if (VIR_ALLOC(driver) < 0)
return -1;
}
driver->requireLeaseForDisks = true;
driver->hostID = 0;
@ -467,10 +463,8 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock,
return -1;
}
if (VIR_ALLOC(priv) < 0) {
virReportOOMError();
if (VIR_ALLOC(priv) < 0)
return -1;
}
priv->flags = flags;
@ -559,10 +553,8 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
struct sanlk_resource *res = NULL;
int i;
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) {
virReportOOMError();
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0)
goto cleanup;
}
res->flags = shared ? SANLK_RES_SHARED : 0;
res->num_disks = 1;
@ -624,10 +616,8 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
return -1;
}
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) {
virReportOOMError();
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0)
goto cleanup;
}
res->flags = shared ? SANLK_RES_SHARED : 0;
res->num_disks = 1;
@ -635,10 +625,8 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
goto cleanup;
if (virAsprintf(&path, "%s/%s",
driver->autoDiskLeasePath, res->name) < 0) {
virReportOOMError();
driver->autoDiskLeasePath, res->name) < 0)
goto cleanup;
}
if (!virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Lease path '%s' exceeds %d characters"),
@ -918,10 +906,8 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
return -1;
}
if (VIR_ALLOC(opt) < 0) {
virReportOOMError();
if (VIR_ALLOC(opt) < 0)
return -1;
}
if (!virStrcpy(opt->owner_name, priv->vm_name, SANLK_NAME_LEN)) {
virReportError(VIR_ERR_INTERNAL_ERROR,

View File

@ -143,10 +143,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
name, driverName, configDir, flags);
if (virAsprintf(&configFile, "%s/%s-%s.conf",
configDir, driverName, name) < 0) {
virReportOOMError();
configDir, driverName, name) < 0)
return NULL;
}
if (STREQ(name, "nop")) {
driver = &virLockDriverNop;
@ -156,10 +154,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
VIR_DEBUG("Module load %s from %s", name, moddir);
if (virAsprintf(&modfile, "%s/%s.so", moddir, name) < 0) {
virReportOOMError();
if (virAsprintf(&modfile, "%s/%s.so", moddir, name) < 0)
goto cleanup;
}
if (access(modfile, R_OK) < 0) {
virReportSystemError(errno,
@ -186,10 +182,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
if (driver->drvInit(VIR_LOCK_MANAGER_VERSION, configFile, flags) < 0)
goto cleanup;
if (VIR_ALLOC(plugin) < 0) {
virReportOOMError();
if (VIR_ALLOC(plugin) < 0)
goto cleanup;
}
plugin->driver = driver;
plugin->handle = handle;
@ -321,10 +315,8 @@ virLockManagerPtr virLockManagerNew(virLockDriverPtr driver,
CHECK_DRIVER(drvNew, NULL);
if (VIR_ALLOC(lock) < 0) {
virReportOOMError();
if (VIR_ALLOC(lock) < 0)
return NULL;
}
lock->driver = driver;