virStorageBackendPtr backend;
virStorageVolDefPtr voldef = NULL;
virStorageVolPtr ret = NULL, volobj = NULL;
+ virStorageVolDefPtr buildvoldef = NULL;
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
goto cleanup;
}
- if (backend->buildVol) {
- int buildret;
- virStorageVolDefPtr buildvoldef = NULL;
+ if (VIR_ALLOC(buildvoldef) < 0) {
+ voldef = NULL;
+ goto cleanup;
+ }
- if (VIR_ALLOC(buildvoldef) < 0) {
- voldef = NULL;
- goto cleanup;
- }
+ /* Make a shallow copy of the 'defined' volume definition, since the
+ * original allocation value will change as the user polls 'info',
+ * but we only need the initial requested values
+ */
+ memcpy(buildvoldef, voldef, sizeof(*voldef));
- /* Make a shallow copy of the 'defined' volume definition, since the
- * original allocation value will change as the user polls 'info',
- * but we only need the initial requested values
- */
- memcpy(buildvoldef, voldef, sizeof(*voldef));
+ if (backend->buildVol) {
+ int buildret;
/* Drop the pool lock during volume allocation */
pool->asyncjobs++;
pool->asyncjobs--;
voldef = NULL;
- VIR_FREE(buildvoldef);
if (buildret < 0) {
virStoragePoolObjUnlock(pool);
}
+ /* Update pool metadata */
+ pool->def->allocation += buildvoldef->allocation;
+ pool->def->available -= buildvoldef->allocation;
+
VIR_INFO("Creating volume '%s' in storage pool '%s'",
volobj->name, pool->def->name);
ret = volobj;
cleanup:
virObjectUnref(volobj);
virStorageVolDefFree(voldef);
+ virStorageVolDefFree(buildvoldef);
if (pool)
virStoragePoolObjUnlock(pool);
return ret;
goto cleanup;
}
+ /* Updating pool metadata */
+ pool->def->allocation += newvol->allocation;
+ pool->def->available -= newvol->allocation;
+
VIR_INFO("Creating volume '%s' in storage pool '%s'",
volobj->name, pool->def->name);
ret = volobj;
goto out;
vol->capacity = abs_capacity;
+
+ /* Update pool metadata */
+ pool->def->allocation += (abs_capacity - vol->capacity);
+ pool->def->available -= (abs_capacity - vol->capacity);
+
ret = 0;
out:
if (backend->deleteVol(obj->conn, pool, vol, flags) < 0)
goto cleanup;
+ /* Update pool metadata */
+ pool->def->allocation -= vol->allocation;
+ pool->def->available += vol->allocation;
+
for (i = 0; i < pool->volumes.count; i++) {
if (pool->volumes.objs[i] == vol) {
VIR_INFO("Deleting volume '%s' from storage pool '%s'",