From c7e4af374f7d41efa2a2f50651826fb00dac50d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Jandre?= Date: Mon, 28 Apr 2025 13:45:31 -0300 Subject: [PATCH] Block volume shrink on Xen --- .../wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java | 7 +++++-- .../main/java/com/cloud/storage/VolumeApiServiceImpl.java | 3 +++ ui/src/views/storage/ChangeOfferingForVolume.vue | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java index 2ddf1bd18511..abf46b2771cd 100755 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java @@ -49,9 +49,12 @@ public Answer execute(final ResizeVolumeCommand command, final CitrixResourceBas try { - if (command.getCurrentSize() >= newSize) { - logger.info("No need to resize volume: " + volId +", current size " + toHumanReadableSize(command.getCurrentSize()) + " is same as new size " + toHumanReadableSize(newSize)); + if (command.getCurrentSize() == newSize) { + logger.info("No need to resize volume [{}], current size [{}] is same as new size [{}].", volId, toHumanReadableSize(command.getCurrentSize()), toHumanReadableSize(newSize)); return new ResizeVolumeAnswer(command, true, "success", newSize); + } else if (command.getCurrentSize() > newSize) { + logger.error("XenServer does not support volume shrink. Volume [{}] current size [{}] is smaller than new size [{}]", volId, toHumanReadableSize(command.getCurrentSize()), toHumanReadableSize(newSize)); + return new ResizeVolumeAnswer(command, false, "operation not supported"); } if (command.isManaged()) { resizeSr(conn, command); diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java index 6a2aa09c38a1..84e4bbf258f7 100644 --- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java @@ -2429,6 +2429,9 @@ private void validateVolumeResizeWithSize(VolumeVO volume, long currentSize, Lon throw new InvalidParameterValueException("Going from existing size of " + currentSize + " to size of " + newSize + " would shrink the volume." + "Need to sign off by supplying the shrinkok parameter with value of true."); } + if (ApiDBUtils.getHypervisorTypeFromFormat(volume.getDataCenterId(), volume.getFormat()) == HypervisorType.XenServer) { + throw new InvalidParameterValueException("Shrink volume is not supported for the XenServer hypervisor."); + } } } /* Check resource limit for this account */ diff --git a/ui/src/views/storage/ChangeOfferingForVolume.vue b/ui/src/views/storage/ChangeOfferingForVolume.vue index 5ab803909992..dedc2e8dc041 100644 --- a/ui/src/views/storage/ChangeOfferingForVolume.vue +++ b/ui/src/views/storage/ChangeOfferingForVolume.vue @@ -90,7 +90,7 @@ :checked="autoMigrate" @change="val => { autoMigrate = val }"/> - +