if (!def)
goto error;
- if (VIR_REALLOC_N(pool->volumes.objs,
- pool->volumes.count+1) < 0)
- goto error;
-
if (def->target.path == NULL) {
if (virAsprintf(&def->target.path, "%s/%s",
pool->def->target.path,
if (!def->key && VIR_STRDUP(def->key, def->target.path) < 0)
goto error;
+ if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, def) < 0)
+ goto error;
pool->def->allocation += def->allocation;
pool->def->available = (pool->def->capacity -
pool->def->allocation);
-
- pool->volumes.objs[pool->volumes.count++] = def;
def = NULL;
}
goto cleanup;
}
- if (VIR_REALLOC_N(privpool->volumes.objs,
- privpool->volumes.count+1) < 0)
- goto cleanup;
-
if (virAsprintf(&privvol->target.path, "%s/%s",
privpool->def->target.path,
privvol->name) == -1)
goto cleanup;
- if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
+ if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 ||
+ VIR_APPEND_ELEMENT_COPY(privpool->volumes.objs,
+ privpool->volumes.count, privvol) < 0)
goto cleanup;
privpool->def->allocation += privvol->allocation;
privpool->def->available = (privpool->def->capacity -
privpool->def->allocation);
- privpool->volumes.objs[privpool->volumes.count++] = privvol;
-
ret = virGetStorageVol(pool->conn, privpool->def->name,
privvol->name, privvol->key,
NULL, NULL);
privpool->def->available = (privpool->def->capacity -
privpool->def->allocation);
- if (VIR_REALLOC_N(privpool->volumes.objs,
- privpool->volumes.count+1) < 0)
- goto cleanup;
-
if (virAsprintf(&privvol->target.path, "%s/%s",
privpool->def->target.path,
privvol->name) == -1)
goto cleanup;
- if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
+ if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 ||
+ VIR_APPEND_ELEMENT_COPY(privpool->volumes.objs,
+ privpool->volumes.count, privvol) < 0)
goto cleanup;
privpool->def->allocation += privvol->allocation;
privpool->def->available = (privpool->def->capacity -
privpool->def->allocation);
- privpool->volumes.objs[privpool->volumes.count++] = privvol;
-
ret = virGetStorageVol(pool->conn, privpool->def->name,
privvol->name, privvol->key,
NULL, NULL);
if (privpool->volumes.objs[i] == privvol) {
virStorageVolDefFree(privvol);
- if (i < (privpool->volumes.count - 1))
- memmove(privpool->volumes.objs + i,
- privpool->volumes.objs + i + 1,
- sizeof(*(privpool->volumes.objs)) *
- (privpool->volumes.count - (i + 1)));
-
- if (VIR_REALLOC_N(privpool->volumes.objs,
- privpool->volumes.count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- privpool->volumes.count--;
-
+ VIR_DELETE_ELEMENT(privpool->volumes.objs, i, privpool->volumes.count);
break;
}
}