mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
storage: Forbid to shrink the vol's capacity if no --shrink is specified
As the document for "virsh-resize" says: <...> Attempts to shrink the volume will fail unless I<--shrink> is present; </...> This makes sense as it at least prevent the user shrinking the important data of volume without a notice.
This commit is contained in:
parent
aa2a4cff7c
commit
38b90e4df3
@ -1762,7 +1762,8 @@ storageVolResize(virStorageVolPtr obj,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virCheckFlags(VIR_STORAGE_VOL_RESIZE_ALLOCATE |
|
virCheckFlags(VIR_STORAGE_VOL_RESIZE_ALLOCATE |
|
||||||
VIR_STORAGE_VOL_RESIZE_DELTA, -1);
|
VIR_STORAGE_VOL_RESIZE_DELTA |
|
||||||
|
VIR_STORAGE_VOL_RESIZE_SHRINK, -1);
|
||||||
|
|
||||||
storageDriverLock(driver);
|
storageDriverLock(driver);
|
||||||
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
||||||
@ -1814,6 +1815,14 @@ storageVolResize(virStorageVolPtr obj,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (abs_capacity < vol->capacity &&
|
||||||
|
!(flags & VIR_STORAGE_VOL_RESIZE_SHRINK)) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
|
_("Can't shrink capacity below current "
|
||||||
|
"capacity with shrink flag explicitly specified"));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (abs_capacity > vol->capacity + pool->def->available) {
|
if (abs_capacity > vol->capacity + pool->def->available) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
_("Not enough space left on storage pool"));
|
_("Not enough space left on storage pool"));
|
||||||
|
Loading…
Reference in New Issue
Block a user