Adapt to VIR_ALLOC and virAsprintf in src/storage/*

This commit is contained in:
Michal Privoznik 2013-07-04 12:16:29 +02:00
parent a72715e0a8
commit ca702bf53d
10 changed files with 60 additions and 184 deletions

View File

@ -161,13 +161,11 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol,
if (VIR_ALLOC_N(zerobuf, wbytes) < 0) { if (VIR_ALLOC_N(zerobuf, wbytes) < 0) {
ret = -errno; ret = -errno;
virReportOOMError();
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC_N(buf, rbytes) < 0) { if (VIR_ALLOC_N(buf, rbytes) < 0) {
ret = -errno; ret = -errno;
virReportOOMError();
goto cleanup; goto cleanup;
} }
@ -466,10 +464,8 @@ virStorageGenerateQcowEncryption(virConnectPtr conn,
} }
if (VIR_ALLOC(enc_secret) < 0 || VIR_REALLOC_N(enc->secrets, 1) < 0 || if (VIR_ALLOC(enc_secret) < 0 || VIR_REALLOC_N(enc->secrets, 1) < 0 ||
VIR_ALLOC(def) < 0) { VIR_ALLOC(def) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
def->ephemeral = false; def->ephemeral = false;
def->private = false; def->private = false;
@ -798,10 +794,8 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
*/ */
if ('/' != *(vol->backingStore.path) && if ('/' != *(vol->backingStore.path) &&
virAsprintf(&absolutePath, "%s/%s", pool->def->target.path, virAsprintf(&absolutePath, "%s/%s", pool->def->target.path,
vol->backingStore.path) < 0) { vol->backingStore.path) < 0)
virReportOOMError();
return NULL; return NULL;
}
accessRetCode = access(absolutePath ? absolutePath accessRetCode = access(absolutePath ? absolutePath
: vol->backingStore.path, R_OK); : vol->backingStore.path, R_OK);
VIR_FREE(absolutePath); VIR_FREE(absolutePath);
@ -986,10 +980,8 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
/* Size in MB - yes different units to qemu-img :-( */ /* Size in MB - yes different units to qemu-img :-( */
if (virAsprintf(&size, "%llu", if (virAsprintf(&size, "%llu",
VIR_DIV_UP(vol->capacity, (1024 * 1024))) < 0) { VIR_DIV_UP(vol->capacity, (1024 * 1024))) < 0)
virReportOOMError();
return -1; return -1;
}
cmd = virCommandNewArgList("qcow-create", size, vol->target.path, NULL); cmd = virCommandNewArgList("qcow-create", size, vol->target.path, NULL);
@ -1298,10 +1290,8 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
target->perms.uid = sb.st_uid; target->perms.uid = sb.st_uid;
target->perms.gid = sb.st_gid; target->perms.gid = sb.st_gid;
if (!target->timestamps && VIR_ALLOC(target->timestamps) < 0) { if (!target->timestamps && VIR_ALLOC(target->timestamps) < 0)
virReportOOMError();
return -1; return -1;
}
target->timestamps->atime = get_stat_atime(&sb); target->timestamps->atime = get_stat_atime(&sb);
target->timestamps->btime = get_stat_birthtime(&sb); target->timestamps->btime = get_stat_birthtime(&sb);
target->timestamps->ctime = get_stat_ctime(&sb); target->timestamps->ctime = get_stat_ctime(&sb);
@ -1485,7 +1475,6 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
if (virAsprintf(&stablepath, "%s/%s", if (virAsprintf(&stablepath, "%s/%s",
pool->def->target.path, pool->def->target.path,
dent->d_name) == -1) { dent->d_name) == -1) {
virReportOOMError();
closedir(dh); closedir(dh);
return NULL; return NULL;
} }
@ -1543,10 +1532,8 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
char **groups; char **groups;
/* Compile all regular expressions */ /* Compile all regular expressions */
if (VIR_ALLOC_N(reg, nregex) < 0) { if (VIR_ALLOC_N(reg, nregex) < 0)
virReportOOMError();
return -1; return -1;
}
for (i = 0; i < nregex; i++) { for (i = 0; i < nregex; i++) {
err = regcomp(&reg[i], regex[i], REG_EXTENDED); err = regcomp(&reg[i], regex[i], REG_EXTENDED);
@ -1568,14 +1555,10 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
} }
/* Storage for matched variables */ /* Storage for matched variables */
if (VIR_ALLOC_N(groups, totgroups) < 0) { if (VIR_ALLOC_N(groups, totgroups) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
} if (VIR_ALLOC_N(vars, maxvars+1) < 0)
if (VIR_ALLOC_N(vars, maxvars+1) < 0) {
virReportOOMError();
goto cleanup; goto cleanup;
}
virCommandSetOutputFD(cmd, &fd); virCommandSetOutputFD(cmd, &fd);
if (virCommandRunAsync(cmd, NULL) < 0) { if (virCommandRunAsync(cmd, NULL) < 0) {
@ -1679,10 +1662,8 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
if (n_columns == 0) if (n_columns == 0)
return -1; return -1;
if (VIR_ALLOC_N(v, n_columns) < 0) { if (VIR_ALLOC_N(v, n_columns) < 0)
virReportOOMError();
return -1; return -1;
}
for (i = 0; i < n_columns; i++) for (i = 0; i < n_columns; i++)
v[i] = NULL; v[i] = NULL;

View File

@ -50,14 +50,11 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
char *tmp, *devpath; char *tmp, *devpath;
if (vol == NULL) { if (vol == NULL) {
if (VIR_ALLOC(vol) < 0) { if (VIR_ALLOC(vol) < 0)
virReportOOMError();
return -1; return -1;
}
if (VIR_REALLOC_N(pool->volumes.objs, if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count+1) < 0) { pool->volumes.count+1) < 0) {
virReportOOMError();
virStorageVolDefFree(vol); virStorageVolDefFree(vol);
return -1; return -1;
} }
@ -94,10 +91,8 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
} }
if (vol->source.extents == NULL) { if (vol->source.extents == NULL) {
if (VIR_ALLOC(vol->source.extents) < 0) { if (VIR_ALLOC(vol->source.extents) < 0)
virReportOOMError();
return -1; return -1;
}
vol->source.nextent = 1; vol->source.nextent = 1;
if (virStrToLong_ull(groups[3], NULL, 10, if (virStrToLong_ull(groups[3], NULL, 10,
@ -487,10 +482,8 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
/* XXX Only support one extended partition */ /* XXX Only support one extended partition */
switch (virStorageBackendDiskPartTypeToCreate(pool)) { switch (virStorageBackendDiskPartTypeToCreate(pool)) {
case VIR_STORAGE_VOL_DISK_TYPE_PRIMARY: case VIR_STORAGE_VOL_DISK_TYPE_PRIMARY:
if (virAsprintf(partFormat, "primary %s", partedFormat) < 0) { if (virAsprintf(partFormat, "primary %s", partedFormat) < 0)
virReportOOMError();
return -1; return -1;
}
break; break;
case VIR_STORAGE_VOL_DISK_TYPE_LOGICAL: case VIR_STORAGE_VOL_DISK_TYPE_LOGICAL:
/* make sure we have a extended partition */ /* make sure we have a extended partition */
@ -498,10 +491,8 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
if (pool->volumes.objs[i]->target.format == if (pool->volumes.objs[i]->target.format ==
VIR_STORAGE_VOL_DISK_EXTENDED) { VIR_STORAGE_VOL_DISK_EXTENDED) {
if (virAsprintf(partFormat, "logical %s", if (virAsprintf(partFormat, "logical %s",
partedFormat) < 0) { partedFormat) < 0)
virReportOOMError();
return -1; return -1;
}
break; break;
} }
} }

View File

@ -129,10 +129,8 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target,
*capacity = meta->capacity; *capacity = meta->capacity;
if (encryption != NULL && meta->encrypted) { if (encryption != NULL && meta->encrypted) {
if (VIR_ALLOC(*encryption) < 0) { if (VIR_ALLOC(*encryption) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
switch (target->format) { switch (target->format) {
case VIR_STORAGE_FILE_QCOW: case VIR_STORAGE_FILE_QCOW:
@ -211,10 +209,8 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTR
if (!(src = virStoragePoolSourceListNewSource(&state->list))) if (!(src = virStoragePoolSourceListNewSource(&state->list)))
goto cleanup; goto cleanup;
if (VIR_ALLOC_N(src->hosts, 1) < 0) { if (VIR_ALLOC_N(src->hosts, 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
src->nhost = 1; src->nhost = 1;
if (VIR_STRDUP(src->hosts[0].name, state->host) < 0 || if (VIR_STRDUP(src->hosts[0].name, state->host) < 0 ||
@ -292,10 +288,8 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
goto cleanup; goto cleanup;
retval = virStoragePoolSourceListFormat(&state.list); retval = virStoragePoolSourceListFormat(&state.list);
if (retval == NULL) { if (retval == NULL)
virReportOOMError();
goto cleanup; goto cleanup;
}
cleanup: cleanup:
for (i = 0; i < state.list.nsources; i++) for (i = 0; i < state.list.nsources; i++)
@ -397,10 +391,8 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
if (pool->def->type == VIR_STORAGE_POOL_NETFS) { if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
if (virAsprintf(&src, "%s:%s", if (virAsprintf(&src, "%s:%s",
pool->def->source.hosts[0].name, pool->def->source.hosts[0].name,
pool->def->source.dir) == -1) { pool->def->source.dir) == -1)
virReportOOMError();
return -1; return -1;
}
} else { } else {
if (VIR_STRDUP(src, pool->def->source.devices[0].path) < 0) if (VIR_STRDUP(src, pool->def->source.devices[0].path) < 0)
@ -833,7 +825,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
int backingStoreFormat; int backingStoreFormat;
if (VIR_ALLOC(vol) < 0) if (VIR_ALLOC(vol) < 0)
goto no_memory; goto cleanup;
if (VIR_STRDUP(vol->name, ent->d_name) < 0) if (VIR_STRDUP(vol->name, ent->d_name) < 0)
goto cleanup; goto cleanup;
@ -843,7 +835,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
if (virAsprintf(&vol->target.path, "%s/%s", if (virAsprintf(&vol->target.path, "%s/%s",
pool->def->target.path, pool->def->target.path,
vol->name) == -1) vol->name) == -1)
goto no_memory; goto cleanup;
if (VIR_STRDUP(vol->key, vol->target.path) < 0) if (VIR_STRDUP(vol->key, vol->target.path) < 0)
goto cleanup; goto cleanup;
@ -897,7 +889,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
if (VIR_REALLOC_N(pool->volumes.objs, if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count+1) < 0) pool->volumes.count+1) < 0)
goto no_memory; goto cleanup;
pool->volumes.objs[pool->volumes.count++] = vol; pool->volumes.objs[pool->volumes.count++] = vol;
vol = NULL; vol = NULL;
} }
@ -918,10 +910,6 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
return 0; return 0;
no_memory:
virReportOOMError();
/* fallthrough */
cleanup: cleanup:
if (dir) if (dir)
closedir(dir); closedir(dir);
@ -1000,10 +988,8 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
VIR_FREE(vol->target.path); VIR_FREE(vol->target.path);
if (virAsprintf(&vol->target.path, "%s/%s", if (virAsprintf(&vol->target.path, "%s/%s",
pool->def->target.path, pool->def->target.path,
vol->name) == -1) { vol->name) == -1)
virReportOOMError();
return -1; return -1;
}
if (virFileExists(vol->target.path)) { if (virFileExists(vol->target.path)) {
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
@ -1194,7 +1180,6 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 || if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 ||
VIR_ALLOC(encsec) < 0) { VIR_ALLOC(encsec) < 0) {
VIR_FREE(vol->target.encryption->secrets); VIR_FREE(vol->target.encryption->secrets);
virReportOOMError();
virSecretFree(sec); virSecretFree(sec);
return -1; return -1;
} }

View File

@ -62,11 +62,9 @@ virStorageBackendISCSIPortal(virStoragePoolSourcePtr source)
port = source->hosts[0].port; port = source->hosts[0].port;
if (strchr(host, ':')) { if (strchr(host, ':')) {
if (virAsprintf(&portal, "[%s]:%d,1", host, port) < 0) ignore_value(virAsprintf(&portal, "[%s]:%d,1", host, port));
virReportOOMError();
} else { } else {
if (virAsprintf(&portal, "%s:%d,1", host, port) < 0) ignore_value(virAsprintf(&portal, "%s:%d,1", host, port));
virReportOOMError();
} }
return portal; return portal;
@ -234,10 +232,8 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn,
if (virAsprintf(&temp_ifacename, if (virAsprintf(&temp_ifacename,
"libvirt-iface-%08llx", "libvirt-iface-%08llx",
(unsigned long long)virRandomBits(30)) < 0) { (unsigned long long)virRandomBits(30)) < 0)
virReportOOMError();
return -1; return -1;
}
VIR_DEBUG("Attempting to create interface '%s' with IQN '%s'", VIR_DEBUG("Attempting to create interface '%s' with IQN '%s'",
temp_ifacename, initiatoriqn); temp_ifacename, initiatoriqn);
@ -396,10 +392,8 @@ virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool,
uint32_t host; uint32_t host;
if (virAsprintf(&sysfs_path, if (virAsprintf(&sysfs_path,
"/sys/class/iscsi_session/session%s/device", session) < 0) { "/sys/class/iscsi_session/session%s/device", session) < 0)
virReportOOMError();
return -1; return -1;
}
if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0) { if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
@ -452,7 +446,6 @@ virStorageBackendISCSIGetTargets(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
if (VIR_REALLOC_N(list->targets, list->ntargets + 1) < 0) { if (VIR_REALLOC_N(list->targets, list->ntargets + 1) < 0) {
VIR_FREE(target); VIR_FREE(target);
virReportOOMError();
return -1; return -1;
} }
@ -590,17 +583,13 @@ virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
&ntargets, &targets) < 0) &ntargets, &targets) < 0)
goto cleanup; goto cleanup;
if (VIR_ALLOC_N(list.sources, ntargets) < 0) { if (VIR_ALLOC_N(list.sources, ntargets) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < ntargets; i++) { for (i = 0; i < ntargets; i++) {
if (VIR_ALLOC_N(list.sources[i].devices, 1) < 0 || if (VIR_ALLOC_N(list.sources[i].devices, 1) < 0 ||
VIR_ALLOC_N(list.sources[i].hosts, 1) < 0) { VIR_ALLOC_N(list.sources[i].hosts, 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
list.sources[i].nhost = 1; list.sources[i].nhost = 1;
list.sources[i].hosts[0] = source->hosts[0]; list.sources[i].hosts[0] = source->hosts[0];
list.sources[i].initiator = source->initiator; list.sources[i].initiator = source->initiator;
@ -609,10 +598,8 @@ virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
list.nsources++; list.nsources++;
} }
if (!(ret = virStoragePoolSourceListFormat(&list))) { if (!(ret = virStoragePoolSourceListFormat(&list)))
virReportOOMError();
goto cleanup; goto cleanup;
}
cleanup: cleanup:
if (list.sources) { if (list.sources) {

View File

@ -97,10 +97,8 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
/* Or a completely new volume */ /* Or a completely new volume */
if (vol == NULL) { if (vol == NULL) {
if (VIR_ALLOC(vol) < 0) { if (VIR_ALLOC(vol) < 0)
virReportOOMError();
return -1; return -1;
}
is_new_vol = true; is_new_vol = true;
vol->type = VIR_STORAGE_VOL_BLOCK; vol->type = VIR_STORAGE_VOL_BLOCK;
@ -109,18 +107,14 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
goto cleanup; goto cleanup;
if (VIR_REALLOC_N(pool->volumes.objs, if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count + 1)) { pool->volumes.count + 1))
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
if (vol->target.path == NULL) { if (vol->target.path == NULL) {
if (virAsprintf(&vol->target.path, "%s/%s", if (virAsprintf(&vol->target.path, "%s/%s",
pool->def->target.path, vol->name) < 0) { pool->def->target.path, vol->name) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
/* Skips the backingStore of lv created with "--virtualsize", /* Skips the backingStore of lv created with "--virtualsize",
@ -132,10 +126,8 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
*/ */
if (groups[1] && !STREQ(groups[1], "") && (groups[1][0] != '[')) { if (groups[1] && !STREQ(groups[1], "") && (groups[1][0] != '[')) {
if (virAsprintf(&vol->backingStore.path, "%s/%s", if (virAsprintf(&vol->backingStore.path, "%s/%s",
pool->def->target.path, groups[1]) < 0) { pool->def->target.path, groups[1]) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
vol->backingStore.format = VIR_STORAGE_POOL_LOGICAL_LVM2; vol->backingStore.format = VIR_STORAGE_POOL_LOGICAL_LVM2;
} }
@ -157,10 +149,8 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
/* Finally fill in extents information */ /* Finally fill in extents information */
if (VIR_REALLOC_N(vol->source.extents, if (VIR_REALLOC_N(vol->source.extents,
vol->source.nextent + nextents) < 0) { vol->source.nextent + nextents) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virStrToLong_ull(groups[6], NULL, 10, &length) < 0) { if (virStrToLong_ull(groups[6], NULL, 10, &length) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -183,28 +173,22 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
goto cleanup; goto cleanup;
for (i = 1; i < nextents; i++) { for (i = 1; i < nextents; i++) {
if (VIR_REALLOC_N(regex, strlen(regex) + strlen(regex_unit) + 2) < 0) { if (VIR_REALLOC_N(regex, strlen(regex) + strlen(regex_unit) + 2) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
/* "," is the separator of "devices" field */ /* "," is the separator of "devices" field */
strcat(regex, ","); strcat(regex, ",");
strncat(regex, regex_unit, strlen(regex_unit)); strncat(regex, regex_unit, strlen(regex_unit));
} }
if (VIR_ALLOC(reg) < 0) { if (VIR_ALLOC(reg) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
/* Each extent has a "path:offset" pair, and vars[0] will /* Each extent has a "path:offset" pair, and vars[0] will
* be the whole matched string. * be the whole matched string.
*/ */
nvars = (nextents * 2) + 1; nvars = (nextents * 2) + 1;
if (VIR_ALLOC_N(vars, nvars) < 0) { if (VIR_ALLOC_N(vars, nvars) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
err = regcomp(reg, regex, REG_EXTENDED); err = regcomp(reg, regex, REG_EXTENDED);
if (err != 0) { if (err != 0) {
@ -380,10 +364,8 @@ virStorageBackendLogicalFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTRIBUTE_
else else
VIR_FREE(vgname); VIR_FREE(vgname);
if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) != 0) { if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) != 0)
virReportOOMError();
goto error; goto error;
}
dev = &thisSource->devices[thisSource->ndevice]; dev = &thisSource->devices[thisSource->ndevice];
thisSource->ndevice++; thisSource->ndevice++;
@ -473,10 +455,8 @@ virStorageBackendLogicalCheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
char *path; char *path;
*isActive = false; *isActive = false;
if (virAsprintf(&path, "/dev/%s", pool->def->source.name) < 0) { if (virAsprintf(&path, "/dev/%s", pool->def->source.name) < 0)
virReportOOMError();
return -1; return -1;
}
if (access(path, F_OK) == 0) if (access(path, F_OK) == 0)
*isActive = true; *isActive = true;
@ -719,10 +699,8 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
if (virAsprintf(&vol->target.path, "%s/%s", if (virAsprintf(&vol->target.path, "%s/%s",
pool->def->target.path, pool->def->target.path,
vol->name) == -1) { vol->name) == -1)
virReportOOMError();
return -1; return -1;
}
cmd = virCommandNewArgList(LVCREATE, cmd = virCommandNewArgList(LVCREATE,
"--name", vol->name, "--name", vol->name,
@ -822,10 +800,8 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virCheckFlags(0, -1); virCheckFlags(0, -1);
if (virAsprintf(&volpath, "%s/%s", if (virAsprintf(&volpath, "%s/%s",
pool->def->source.name, vol->name) < 0) { pool->def->source.name, vol->name) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
virFileWaitForDevices(); virFileWaitForDevices();

View File

@ -75,22 +75,16 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol; virStorageVolDefPtr vol;
int ret = -1; int ret = -1;
if (VIR_ALLOC(vol) < 0) { if (VIR_ALLOC(vol) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
vol->type = VIR_STORAGE_VOL_BLOCK; vol->type = VIR_STORAGE_VOL_BLOCK;
if (virAsprintf(&(vol->name), "dm-%u", devnum) < 0) { if (virAsprintf(&(vol->name), "dm-%u", devnum) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0) { if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virStorageBackendMpathUpdateVolTargetInfo(&vol->target, if (virStorageBackendMpathUpdateVolTargetInfo(&vol->target,
&vol->allocation, &vol->allocation,
@ -103,10 +97,8 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
goto cleanup; goto cleanup;
if (VIR_REALLOC_N(pool->volumes.objs, if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count + 1) < 0) { pool->volumes.count + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
pool->volumes.objs[pool->volumes.count++] = vol; pool->volumes.objs[pool->volumes.count++] = vol;
pool->def->capacity += vol->capacity; pool->def->capacity += vol->capacity;
pool->def->allocation += vol->allocation; pool->def->allocation += vol->allocation;
@ -220,10 +212,8 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool,
if (is_mpath == 1) { if (is_mpath == 1) {
if (virAsprintf(&map_device, "mapper/%s", names->name) < 0) { if (virAsprintf(&map_device, "mapper/%s", names->name) < 0)
virReportOOMError();
goto out; goto out;
}
if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) { if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,

View File

@ -238,18 +238,14 @@ static int volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
VIR_FREE(vol->target.path); VIR_FREE(vol->target.path);
if (virAsprintf(&vol->target.path, "%s/%s", if (virAsprintf(&vol->target.path, "%s/%s",
pool->def->source.name, pool->def->source.name,
vol->name) == -1) { vol->name) == -1)
virReportOOMError();
goto cleanup; goto cleanup;
}
VIR_FREE(vol->key); VIR_FREE(vol->key);
if (virAsprintf(&vol->key, "%s/%s", if (virAsprintf(&vol->key, "%s/%s",
pool->def->source.name, pool->def->source.name,
vol->name) == -1) { vol->name) == -1)
virReportOOMError();
goto cleanup; goto cleanup;
}
ret = 0; ret = 0;
@ -308,7 +304,7 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
while (true) { while (true) {
if (VIR_ALLOC_N(names, max_size) < 0) if (VIR_ALLOC_N(names, max_size) < 0)
goto out_of_memory; goto cleanup;
len = rbd_list(ptr.ioctx, names, &max_size); len = rbd_list(ptr.ioctx, names, &max_size);
if (len >= 0) if (len >= 0)
@ -325,14 +321,14 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) { if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) {
virStoragePoolObjClearVols(pool); virStoragePoolObjClearVols(pool);
goto out_of_memory; goto cleanup;
} }
if (STREQ(name, "")) if (STREQ(name, ""))
break; break;
if (VIR_ALLOC(vol) < 0) if (VIR_ALLOC(vol) < 0)
goto out_of_memory; goto cleanup;
if (VIR_STRDUP(vol->name, name) < 0) { if (VIR_STRDUP(vol->name, name) < 0) {
VIR_FREE(vol); VIR_FREE(vol);
@ -358,10 +354,6 @@ cleanup:
VIR_FREE(names); VIR_FREE(names);
virStorageBackendRBDCloseRADOSConn(ptr); virStorageBackendRBDCloseRADOSConn(ptr);
return ret; return ret;
out_of_memory:
virReportOOMError();
goto cleanup;
} }
static int virStorageBackendRBDDeleteVol(virConnectPtr conn, static int virStorageBackendRBDDeleteVol(virConnectPtr conn,

View File

@ -56,10 +56,8 @@ getDeviceType(uint32_t host,
int retval = 0; int retval = 0;
if (virAsprintf(&type_path, "/sys/bus/scsi/devices/%u:%u:%u:%u/type", if (virAsprintf(&type_path, "/sys/bus/scsi/devices/%u:%u:%u:%u/type",
host, bus, target, lun) < 0) { host, bus, target, lun) < 0)
virReportOOMError();
goto out; goto out;
}
typefile = fopen(type_path, "r"); typefile = fopen(type_path, "r");
if (typefile == NULL) { if (typefile == NULL) {
@ -213,7 +211,6 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
int retval = 0; int retval = 0;
if (VIR_ALLOC(vol) < 0) { if (VIR_ALLOC(vol) < 0) {
virReportOOMError();
retval = -1; retval = -1;
goto out; goto out;
} }
@ -226,13 +223,11 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
* just leave 'host' out * just leave 'host' out
*/ */
if (virAsprintf(&(vol->name), "unit:%u:%u:%u", bus, target, lun) < 0) { if (virAsprintf(&(vol->name), "unit:%u:%u:%u", bus, target, lun) < 0) {
virReportOOMError();
retval = -1; retval = -1;
goto free_vol; goto free_vol;
} }
if (virAsprintf(&devpath, "/dev/%s", dev) < 0) { if (virAsprintf(&devpath, "/dev/%s", dev) < 0) {
virReportOOMError();
retval = -1; retval = -1;
goto free_vol; goto free_vol;
} }
@ -284,7 +279,6 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
if (VIR_REALLOC_N(pool->volumes.objs, if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count + 1) < 0) { pool->volumes.count + 1) < 0) {
virReportOOMError();
retval = -1; retval = -1;
goto free_vol; goto free_vol;
} }
@ -310,10 +304,8 @@ getNewStyleBlockDevice(const char *lun_path,
struct dirent *block_dirent = NULL; struct dirent *block_dirent = NULL;
int retval = 0; int retval = 0;
if (virAsprintf(&block_path, "%s/block", lun_path) < 0) { if (virAsprintf(&block_path, "%s/block", lun_path) < 0)
virReportOOMError();
goto out; goto out;
}
VIR_DEBUG("Looking for block device in '%s'", block_path); VIR_DEBUG("Looking for block device in '%s'", block_path);
@ -395,10 +387,8 @@ getBlockDevice(uint32_t host,
int retval = 0; int retval = 0;
if (virAsprintf(&lun_path, "/sys/bus/scsi/devices/%u:%u:%u:%u", if (virAsprintf(&lun_path, "/sys/bus/scsi/devices/%u:%u:%u:%u",
host, bus, target, lun) < 0) { host, bus, target, lun) < 0)
virReportOOMError();
goto out; goto out;
}
lun_dir = opendir(lun_path); lun_dir = opendir(lun_path);
if (lun_dir == NULL) { if (lun_dir == NULL) {
@ -543,7 +533,6 @@ virStorageBackendSCSITriggerRescan(uint32_t host)
VIR_DEBUG("Triggering rescan of host %d", host); VIR_DEBUG("Triggering rescan of host %d", host);
if (virAsprintf(&path, "/sys/class/scsi_host/host%u/scan", host) < 0) { if (virAsprintf(&path, "/sys/class/scsi_host/host%u/scan", host) < 0) {
virReportOOMError();
retval = -1; retval = -1;
goto out; goto out;
} }
@ -708,10 +697,8 @@ virStorageBackendSCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
if (getHostNumber(name, &host) < 0) if (getHostNumber(name, &host) < 0)
goto cleanup; goto cleanup;
if (virAsprintf(&path, "/sys/class/scsi_host/host%d", host) < 0) { if (virAsprintf(&path, "/sys/class/scsi_host/host%d", host) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (access(path, F_OK) == 0) if (access(path, F_OK) == 0)
*isActive = true; *isActive = true;

View File

@ -263,10 +263,8 @@ virStorageBackendSheepdogRefreshVol(virConnectPtr conn ATTRIBUTE_UNUSED,
VIR_FREE(vol->key); VIR_FREE(vol->key);
if (virAsprintf(&vol->key, "%s/%s", if (virAsprintf(&vol->key, "%s/%s",
pool->def->source.name, vol->name) == -1) { pool->def->source.name, vol->name) == -1)
virReportOOMError();
goto cleanup; goto cleanup;
}
VIR_FREE(vol->target.path); VIR_FREE(vol->target.path);
ignore_value(VIR_STRDUP(vol->target.path, vol->name)); ignore_value(VIR_STRDUP(vol->target.path, vol->name));

View File

@ -158,11 +158,11 @@ storageStateInitialize(bool privileged,
*/ */
if (virAsprintf(&driverState->configDir, if (virAsprintf(&driverState->configDir,
"%s/storage", base) == -1) "%s/storage", base) == -1)
goto out_of_memory; goto error;
if (virAsprintf(&driverState->autostartDir, if (virAsprintf(&driverState->autostartDir,
"%s/storage/autostart", base) == -1) "%s/storage/autostart", base) == -1)
goto out_of_memory; goto error;
VIR_FREE(base); VIR_FREE(base);
@ -175,8 +175,6 @@ storageStateInitialize(bool privileged,
storageDriverUnlock(driverState); storageDriverUnlock(driverState);
return 0; return 0;
out_of_memory:
virReportOOMError();
error: error:
VIR_FREE(base); VIR_FREE(base);
storageDriverUnlock(driverState); storageDriverUnlock(driverState);
@ -1283,10 +1281,8 @@ storagePoolListAllVolumes(virStoragePoolPtr pool,
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC_N(tmp_vols, obj->volumes.count + 1) < 0) { if (VIR_ALLOC_N(tmp_vols, obj->volumes.count + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < obj->volumes.count; i++) { for (i = 0; i < obj->volumes.count; i++) {
if (!virStoragePoolListAllVolumesCheckACL(pool->conn, obj->def, if (!virStoragePoolListAllVolumesCheckACL(pool->conn, obj->def,
@ -1514,10 +1510,8 @@ storageVolCreateXML(virStoragePoolPtr obj,
} }
if (VIR_REALLOC_N(pool->volumes.objs, if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count+1) < 0) { pool->volumes.count+1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (!backend->createVol) { if (!backend->createVol) {
virReportError(VIR_ERR_NO_SUPPORT, virReportError(VIR_ERR_NO_SUPPORT,
@ -1543,7 +1537,6 @@ storageVolCreateXML(virStoragePoolPtr obj,
virStorageVolDefPtr buildvoldef = NULL; virStorageVolDefPtr buildvoldef = NULL;
if (VIR_ALLOC(buildvoldef) < 0) { if (VIR_ALLOC(buildvoldef) < 0) {
virReportOOMError();
voldef = NULL; voldef = NULL;
goto cleanup; goto cleanup;
} }
@ -1695,10 +1688,8 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
goto cleanup; goto cleanup;
if (VIR_REALLOC_N(pool->volumes.objs, if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count+1) < 0) { pool->volumes.count+1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
/* 'Define' the new volume so we get async progress reporting */ /* 'Define' the new volume so we get async progress reporting */
if (backend->createVol(obj->conn, pool, newvol) < 0) { if (backend->createVol(obj->conn, pool, newvol) < 0) {
@ -2175,10 +2166,8 @@ storageVolWipeInternal(virStorageVolDefPtr def,
ret = storageVolZeroSparseFile(def, st.st_size, fd); ret = storageVolZeroSparseFile(def, st.st_size, fd);
} else { } else {
if (VIR_ALLOC_N(writebuf, st.st_blksize) != 0) { if (VIR_ALLOC_N(writebuf, st.st_blksize) < 0)
virReportOOMError();
goto out; goto out;
}
ret = storageWipeExtent(def, ret = storageWipeExtent(def,
fd, fd,