提交 7211f66a 编写于 作者: J Ján Tomko

Simplify allocation check in storageVolResize

Since shrinking a volume below existing allocation is not allowed,
it is not possible for a successful resize with VOL_RESIZE_ALLOCATE
to increase the pool's available value.

Even with the SHRINK flag it is possible to extend the current
allocation or even the capacity. Remove the overflow when
computing delta with this flag and do the check even if the
flag was specified.

https://bugzilla.redhat.com/show_bug.cgi?id=1073305
上级 30ae6857
...@@ -2292,7 +2292,7 @@ storageVolResize(virStorageVolPtr obj, ...@@ -2292,7 +2292,7 @@ storageVolResize(virStorageVolPtr obj,
virStorageBackendPtr backend; virStorageBackendPtr backend;
virStoragePoolObjPtr pool = NULL; virStoragePoolObjPtr pool = NULL;
virStorageVolDefPtr vol = NULL; virStorageVolDefPtr vol = NULL;
unsigned long long abs_capacity, delta; unsigned long long abs_capacity, delta = 0;
int ret = -1; int ret = -1;
virCheckFlags(VIR_STORAGE_VOL_RESIZE_ALLOCATE | virCheckFlags(VIR_STORAGE_VOL_RESIZE_ALLOCATE |
...@@ -2341,18 +2341,10 @@ storageVolResize(virStorageVolPtr obj, ...@@ -2341,18 +2341,10 @@ storageVolResize(virStorageVolPtr obj,
goto cleanup; goto cleanup;
} }
if (flags & VIR_STORAGE_VOL_RESIZE_SHRINK) if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE)
delta = vol->target.allocation - abs_capacity;
else
delta = abs_capacity - vol->target.allocation; delta = abs_capacity - vol->target.allocation;
/* If the operation is going to increase the allocation value and not if (delta > pool->def->available) {
* just the capacity value, then let's make sure there's enough space
* in the pool in order to perform that operation
*/
if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE &&
!(flags & VIR_STORAGE_VOL_RESIZE_SHRINK) &&
delta > pool->def->available) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s", virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("Not enough space left in storage pool")); _("Not enough space left in storage pool"));
goto cleanup; goto cleanup;
...@@ -2375,15 +2367,8 @@ storageVolResize(virStorageVolPtr obj, ...@@ -2375,15 +2367,8 @@ storageVolResize(virStorageVolPtr obj,
*/ */
if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE) { if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE) {
vol->target.allocation = abs_capacity; vol->target.allocation = abs_capacity;
pool->def->allocation += delta;
/* Update pool metadata */ pool->def->available -= delta;
if (flags & VIR_STORAGE_VOL_RESIZE_SHRINK) {
pool->def->allocation -= delta;
pool->def->available += delta;
} else {
pool->def->allocation += delta;
pool->def->available -= delta;
}
} }
ret = 0; ret = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册