src/storage: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2014-03-07 09:33:31 +01:00
parent ba52e4c715
commit d53bbfd159
7 changed files with 15 additions and 34 deletions

View File

@ -52,20 +52,15 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
if (vol == NULL) {
if (VIR_ALLOC(vol) < 0)
return -1;
if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count+1) < 0) {
virStorageVolDefFree(vol);
return -1;
}
pool->volumes.objs[pool->volumes.count++] = vol;
/* Prepended path will be same for all partitions, so we can
* strip the path to form a reasonable pool-unique name
*/
tmp = strrchr(groups[0], '/');
if (VIR_STRDUP(vol->name, tmp ? tmp + 1 : groups[0]) < 0)
if (VIR_STRDUP(vol->name, tmp ? tmp + 1 : groups[0]) < 0 ||
VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) {
virStorageVolDefFree(vol);
return -1;
}
}
if (vol->target.path == NULL) {

View File

@ -905,11 +905,8 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
}
if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count+1) < 0)
if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0)
goto cleanup;
pool->volumes.objs[pool->volumes.count++] = vol;
vol = NULL;
}
closedir(dir);

View File

@ -447,14 +447,11 @@ virStorageBackendISCSIGetTargets(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
if (VIR_STRDUP(target, groups[1]) < 0)
return -1;
if (VIR_REALLOC_N(list->targets, list->ntargets + 1) < 0) {
if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0) {
VIR_FREE(target);
return -1;
}
list->targets[list->ntargets] = target;
list->ntargets++;
return 0;
}

View File

@ -115,9 +115,6 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
if (VIR_STRDUP(vol->name, groups[0]) < 0)
goto cleanup;
if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count + 1))
goto cleanup;
}
if (vol->target.path == NULL) {
@ -251,8 +248,9 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
vol->source.nextent++;
}
if (is_new_vol)
pool->volumes.objs[pool->volumes.count++] = vol;
if (is_new_vol &&
VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0)
goto cleanup;
ret = 0;

View File

@ -99,10 +99,8 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
if (VIR_STRDUP(vol->key, vol->target.path) < 0)
goto cleanup;
if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count + 1) < 0)
if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, vol) < 0)
goto cleanup;
pool->volumes.objs[pool->volumes.count++] = vol;
pool->def->capacity += vol->capacity;
pool->def->allocation += vol->allocation;
ret = 0;

View File

@ -382,11 +382,6 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn,
for (name = names; name < names + max_size;) {
virStorageVolDefPtr vol;
if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) {
virStoragePoolObjClearVols(pool);
goto cleanup;
}
if (STREQ(name, ""))
break;
@ -405,7 +400,10 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn,
goto cleanup;
}
pool->volumes.objs[pool->volumes.count++] = vol;
if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) {
virStoragePoolObjClearVols(pool);
goto cleanup;
}
}
VIR_DEBUG("Found %zu images in RBD pool %s",

View File

@ -249,12 +249,10 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
pool->def->capacity += vol->capacity;
pool->def->allocation += vol->allocation;
if (VIR_REALLOC_N(pool->volumes.objs,
pool->volumes.count + 1) < 0) {
if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) {
retval = -1;
goto free_vol;
}
pool->volumes.objs[pool->volumes.count++] = vol;
goto out;