src/test: 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 d53bbfd159
commit 7e89de172d

View File

@ -1243,10 +1243,6 @@ testOpenVolumesForPool(const char *file,
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,
@ -1256,12 +1252,12 @@ testOpenVolumesForPool(const char *file,
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;
}
@ -5459,24 +5455,20 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
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);
@ -5547,24 +5539,20 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
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);
@ -5624,18 +5612,7 @@ testStorageVolDelete(virStorageVolPtr vol,
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;
}
}