提交 eb9aaa26 编写于 作者: J John Ferlan 提交者: Cole Robinson

storage: Adjust calculation of alloc/capacity for disk

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.

(cherry picked from commit 1895b421)
上级 770ffbf8
...@@ -156,7 +156,8 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, ...@@ -156,7 +156,8 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
VIR_STORAGE_VOL_OPEN_DEFAULT | VIR_STORAGE_VOL_OPEN_DEFAULT |
VIR_STORAGE_VOL_OPEN_NOERROR) == -1) VIR_STORAGE_VOL_OPEN_NOERROR) == -1)
return -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); (vol->source.extents[0].end - vol->source.extents[0].start);
} else { } else {
if (virStorageBackendUpdateVolInfo(vol, false, if (virStorageBackendUpdateVolInfo(vol, false,
...@@ -164,6 +165,20 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, ...@@ -164,6 +165,20 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
return -1; 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")) if (STRNEQ(groups[2], "metadata"))
pool->def->allocation += vol->target.allocation; pool->def->allocation += vol->target.allocation;
if (vol->source.extents[0].end > pool->def->capacity) if (vol->source.extents[0].end > pool->def->capacity)
...@@ -748,17 +763,14 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn, ...@@ -748,17 +763,14 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
/* If this is not a logical partition, then either we've removed an /* Refreshing the pool is the easiest option as LOGICAL and EXTENDED
* extended partition or a primary partion - refresh the pool which * partition allocation/capacity management is handled within
* includes resetting the [n]freeExtents data so a subsequent allocation * virStorageBackendDiskMakeDataVol and trying to redo that logic
* might be able to use what was deleted. A logical partition is part * here is pointless
* of an extended partition and handled differently
*/ */
if (vol->source.partType != VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) { virStoragePoolObjClearVols(pool);
virStoragePoolObjClearVols(pool); if (virStorageBackendDiskRefreshPool(conn, pool) < 0)
if (virStorageBackendDiskRefreshPool(conn, pool) < 0) goto cleanup;
goto cleanup;
}
rc = 0; rc = 0;
cleanup: cleanup:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册