@@ -1127,6 +1127,13 @@ private VolumeVO createVolumeOnStoragePool(Long volumeId, Long storageId) throws
11271127 throw new InvalidParameterValueException (String .format ("Disk offering: %s is not compatible with the storage pool" , diskOffering .getUuid ()));
11281128 }
11291129
1130+ HypervisorType hypervisorType = _volsDao .getHypervisorType (volume .getId ());
1131+ DiskProfile diskProfile = new DiskProfile (volume , diskOffering , hypervisorType );
1132+ if (!storageMgr .storagePoolHasEnoughSpace (Collections .singletonList (new Pair <>(volume , diskProfile )), storagePool , storagePool .getClusterId ())) {
1133+ throw new InvalidParameterValueException (String .format ("Storage pool %s does not have enough space to create volume %s." ,
1134+ storagePool .getName (), volume .getUuid ()));
1135+ }
1136+
11301137 DataStore dataStore = dataStoreMgr .getDataStore (storageId , DataStoreRole .Primary );
11311138 VolumeInfo volumeInfo = volFactory .getVolume (volumeId , dataStore );
11321139 AsyncCallFuture <VolumeApiResult > createVolumeFuture = volService .createVolumeAsync (volumeInfo , dataStore );
@@ -1184,6 +1191,9 @@ public VolumeVO createVolume(long volumeId, Long vmId, Long snapshotId, Long sto
11841191 created = false ;
11851192 VolumeInfo vol = volFactory .getVolume (volumeId );
11861193 vol .stateTransit (Volume .Event .DestroyRequested );
1194+ if (e instanceof InvalidParameterValueException ) {
1195+ throw (InvalidParameterValueException ) e ;
1196+ }
11871197 throw new CloudRuntimeException (String .format ("Failed to create volume: %s" , volume ), e );
11881198 } finally {
11891199 if (!created ) {
0 commit comments