Skip to content

Commit ba0204f

Browse files
JoaoJandreJoão Jandre
andauthored
Block volume shrink on Xen (#11004)
Co-authored-by: João Jandre <[email protected]>
1 parent 75147b7 commit ba0204f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ public Answer execute(final ResizeVolumeCommand command, final CitrixResourceBas
4949

5050
try {
5151

52-
if (command.getCurrentSize() >= newSize) {
53-
logger.info("No need to resize volume: " + volId +", current size " + toHumanReadableSize(command.getCurrentSize()) + " is same as new size " + toHumanReadableSize(newSize));
52+
if (command.getCurrentSize() == newSize) {
53+
logger.info("No need to resize volume [{}], current size [{}] is same as new size [{}].", volId, toHumanReadableSize(command.getCurrentSize()), toHumanReadableSize(newSize));
5454
return new ResizeVolumeAnswer(command, true, "success", newSize);
55+
} else if (command.getCurrentSize() > newSize) {
56+
logger.error("XenServer does not support volume shrink. Volume [{}] current size [{}] is smaller than new size [{}]", volId, toHumanReadableSize(command.getCurrentSize()), toHumanReadableSize(newSize));
57+
return new ResizeVolumeAnswer(command, false, "operation not supported");
5558
}
5659
if (command.isManaged()) {
5760
resizeSr(conn, command);

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,9 @@ private void validateVolumeResizeWithSize(VolumeVO volume, long currentSize, Lon
24292429
throw new InvalidParameterValueException("Going from existing size of " + currentSize + " to size of " + newSize + " would shrink the volume."
24302430
+ "Need to sign off by supplying the shrinkok parameter with value of true.");
24312431
}
2432+
if (ApiDBUtils.getHypervisorTypeFromFormat(volume.getDataCenterId(), volume.getFormat()) == HypervisorType.XenServer) {
2433+
throw new InvalidParameterValueException("Shrink volume is not supported for the XenServer hypervisor.");
2434+
}
24322435
}
24332436
}
24342437
/* Check resource limit for this account */

ui/src/views/storage/ChangeOfferingForVolume.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
:checked="autoMigrate"
9191
@change="val => { autoMigrate = val }"/>
9292
</a-form-item>
93-
<a-form-item name="shrinkOk" ref="shrinkOk" :label="$t('label.shrinkok')">
93+
<a-form-item name="shrinkOk" ref="shrinkOk" :label="$t('label.shrinkok')" v-if="!['XenServer'].includes(resource.hypervisor)">
9494
<a-switch
9595
v-model:checked="form.shrinkOk"
9696
:checked="shrinkOk"

0 commit comments

Comments
 (0)