提交 d53bbfd1 编写于 作者: M Michal Privoznik

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

Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 ba52e4c7
......@@ -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) {
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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",
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册