https://bugzilla.redhat.com/show_bug.cgi?id=1247987
Calculation of the extended and logical partition values for the disk
pool is complex. As the bz points out an extended partition should have
it's allocation initialized to 0 (zero) and keep the capacity as the size
dictated by the extents read. Then for each logical partition found,
adjust the allocation of the extended partition.
Finally, previous logic tried to avoid recalculating things if a logical
partition was deleted; however, since we now have special logic to handle
the allocation of the extended partition, just make life easier by reading
the partition table again - rather than doing the reverse adjustment.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/storage/storage_backend_disk.c | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index c6317a2..7baecc1 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:
--
2.1.0