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) {
}
- 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);
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;
}
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) {
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;
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;
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;
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",
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;