storage: validate disk size range of custom disk offering when resize volume (#7073)

This commit is contained in:
Wei Zhou 2023-01-18 09:40:43 +01:00 committed by GitHub
parent 4bb43f7879
commit 3dc0e499dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 12 deletions

View File

@ -154,6 +154,8 @@ public interface VolumeApiService {
Volume recoverVolume(long volumeId);
void validateCustomDiskOfferingSizeRange(Long sizeInGB);
boolean validateVolumeSizeInBytes(long size);
Volume changeDiskOfferingForVolume(ChangeOfferingForVolumeCmd cmd) throws ResourceAllocationException;

View File

@ -715,12 +715,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
if (size == null) {
throw new InvalidParameterValueException("This disk offering requires a custom size specified");
}
Long customDiskOfferingMaxSize = VolumeOrchestrationService.CustomDiskOfferingMaxSize.value();
Long customDiskOfferingMinSize = VolumeOrchestrationService.CustomDiskOfferingMinSize.value();
if ((sizeInGB < customDiskOfferingMinSize) || (sizeInGB > customDiskOfferingMaxSize)) {
throw new InvalidParameterValueException("Volume size: " + sizeInGB + "GB is out of allowed range. Max: " + customDiskOfferingMaxSize + " Min:" + customDiskOfferingMinSize);
}
validateCustomDiskOfferingSizeRange(sizeInGB);
}
if (!diskOffering.isCustomized() && size != null) {
@ -872,6 +867,16 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
_uuidMgr.generateUuid(Volume.class, cmd.getCustomId()), details);
}
@Override
public void validateCustomDiskOfferingSizeRange(Long sizeInGB) {
Long customDiskOfferingMaxSize = VolumeOrchestrationService.CustomDiskOfferingMaxSize.value();
Long customDiskOfferingMinSize = VolumeOrchestrationService.CustomDiskOfferingMinSize.value();
if ((sizeInGB < customDiskOfferingMinSize) || (sizeInGB > customDiskOfferingMaxSize)) {
throw new InvalidParameterValueException(String.format("Volume size: %s GB is out of allowed range. Min: %s. Max: %s", sizeInGB, customDiskOfferingMinSize, customDiskOfferingMaxSize));
}
}
private VolumeVO commitVolume(final CreateVolumeCmd cmd, final Account caller, final Account owner, final Boolean displayVolume, final Long zoneId, final Long diskOfferingId,
final Storage.ProvisioningType provisioningType, final Long size, final Long minIops, final Long maxIops, final VolumeVO parentVolume, final String userSpecifiedName, final String uuid, final Map<String, String> details) {
return Transaction.execute(new TransactionCallback<VolumeVO>() {
@ -1060,6 +1065,10 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
throw new InvalidParameterValueException(String.format("Resize of volume %s is not allowed, since disk size is strictly fixed as per the disk offering", volume.getUuid()));
}
if (diskOffering.isCustomized()) {
validateCustomDiskOfferingSizeRange(newSize);
}
if (isNotPossibleToResize(volume, diskOffering)) {
throw new InvalidParameterValueException(
"Failed to resize Root volume. The service offering of this Volume has been configured with a root disk size; "
@ -1138,6 +1147,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
throw new InvalidParameterValueException("The new disk offering requires that a size be specified.");
}
validateCustomDiskOfferingSizeRange(newSize);
// convert from GiB to bytes
newSize = newSize << 30;
} else {

View File

@ -4187,12 +4187,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
if (diskSize == null) {
throw new InvalidParameterValueException("This disk offering requires a custom size specified");
}
Long customDiskOfferingMaxSize = VolumeOrchestrationService.CustomDiskOfferingMaxSize.value();
Long customDiskOfferingMinSize = VolumeOrchestrationService.CustomDiskOfferingMinSize.value();
if ((diskSize < customDiskOfferingMinSize) || (diskSize > customDiskOfferingMaxSize)) {
throw new InvalidParameterValueException("VM Creation failed. Volume size: " + diskSize + "GB is out of allowed range. Max: " + customDiskOfferingMaxSize
+ " Min:" + customDiskOfferingMinSize);
}
_volumeService.validateCustomDiskOfferingSizeRange(diskSize);
size = diskSize * GiB_TO_BYTES;
} else {
size = diskOffering.getDiskSize();