This is an automated email from the ASF dual-hosted git repository.

nvazquez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new d6390bd5c30 Validate Storage Capacity Before Volume Create (#14314)
d6390bd5c30 is described below

commit d6390bd5c3084268fd039c96fa01bdce3ccf91f1
Author: sugapriyap <[email protected]>
AuthorDate: Mon Nov 2 02:55:10 2026 +0530

    Validate Storage Capacity Before Volume Create (#14314)
    
    * CSTACKEX-325: Validate storage capacity before creating volume
    
    * Merge pull request #123
    
    CSTACKEX-345: validate storage pool capacity for volume creation
---
 .../src/main/java/com/cloud/storage/VolumeApiServiceImpl.java  | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java 
b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
index 0702450d85c..1a2edb58a00 100644
--- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
@@ -1127,6 +1127,13 @@ public class VolumeApiServiceImpl extends ManagerBase 
implements VolumeApiServic
             throw new InvalidParameterValueException(String.format("Disk 
offering: %s is not compatible with the storage pool", diskOffering.getUuid()));
         }
 
+        HypervisorType hypervisorType = 
_volsDao.getHypervisorType(volume.getId());
+        DiskProfile diskProfile = new DiskProfile(volume, diskOffering, 
hypervisorType);
+        if 
(!storageMgr.storagePoolHasEnoughSpace(Collections.singletonList(new 
Pair<>(volume, diskProfile)), storagePool, storagePool.getClusterId())) {
+            throw new InvalidParameterValueException(String.format("Storage 
pool %s does not have enough space to create volume %s.",
+                    storagePool.getName(), volume.getUuid()));
+        }
+
         DataStore dataStore = dataStoreMgr.getDataStore(storageId, 
DataStoreRole.Primary);
         VolumeInfo volumeInfo = volFactory.getVolume(volumeId, dataStore);
         AsyncCallFuture<VolumeApiResult> createVolumeFuture = 
volService.createVolumeAsync(volumeInfo, dataStore);
@@ -1184,6 +1191,9 @@ public class VolumeApiServiceImpl extends ManagerBase 
implements VolumeApiServic
             created = false;
             VolumeInfo vol = volFactory.getVolume(volumeId);
             vol.stateTransit(Volume.Event.DestroyRequested);
+            if (e instanceof InvalidParameterValueException) {
+                throw (InvalidParameterValueException) e;
+            }
             throw new CloudRuntimeException(String.format("Failed to create 
volume: %s", volume), e);
         } finally {
             if (!created) {

Reply via email to