diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index c6317a24194f11715d61f859ace3a3e4034792ed..7baecc1e47bf863d3bad0b80e565f6feaa862a9a 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -156,7 +156,8 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, VIR_STORAGE_VOL_OPEN_DEFAULT | VIR_STORAGE_VOL_OPEN_NOERROR) == -1) return -1; - vol->target.allocation = vol->target.capacity = + vol->target.allocation = 0; + vol->target.capacity = (vol->source.extents[0].end - vol->source.extents[0].start); } else { if (virStorageBackendUpdateVolInfo(vol, false, @@ -164,6 +165,20 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, return -1; } + /* Find the extended partition and increase the allocation value */ + if (vol->source.partType == VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) { + size_t i; + + for (i = 0; i < pool->volumes.count; i++) { + if (pool->volumes.objs[i]->source.partType == + VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) { + pool->volumes.objs[i]->target.allocation += + vol->target.allocation; + break; + } + } + } + if (STRNEQ(groups[2], "metadata")) pool->def->allocation += vol->target.allocation; if (vol->source.extents[0].end > pool->def->capacity) @@ -841,17 +856,14 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn, goto cleanup; } - /* If this is not a logical partition, then either we've removed an - * extended partition or a primary partion - refresh the pool which - * includes resetting the [n]freeExtents data so a subsequent allocation - * might be able to use what was deleted. A logical partition is part - * of an extended partition and handled differently + /* Refreshing the pool is the easiest option as LOGICAL and EXTENDED + * partition allocation/capacity management is handled within + * virStorageBackendDiskMakeDataVol and trying to redo that logic + * here is pointless */ - if (vol->source.partType != VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) { - virStoragePoolObjClearVols(pool); - if (virStorageBackendDiskRefreshPool(conn, pool) < 0) - goto cleanup; - } + virStoragePoolObjClearVols(pool); + if (virStorageBackendDiskRefreshPool(conn, pool) < 0) + goto cleanup; rc = 0; cleanup: