@@ -1721,7 +1721,7 @@ public boolean storagePoolHasEnoughSpace(List<Volume> volumes, StoragePool pool,
17211721 s_logger .debug ("Destination pool id: " + pool .getId ());
17221722 }
17231723 // allocated space includes templates
1724- StoragePoolVO poolVO = _storagePoolDao .findById (pool .getId ());
1724+ final StoragePoolVO poolVO = _storagePoolDao .findById (pool .getId ());
17251725 long allocatedSizeWithTemplate = _capacityMgr .getAllocatedPoolCapacity (poolVO , null );
17261726 long totalAskingSize = 0 ;
17271727
@@ -1772,12 +1772,37 @@ public boolean storagePoolHasEnoughSpace(List<Volume> volumes, StoragePool pool,
17721772 }
17731773 }
17741774
1775+ return checkPoolforSpace (pool , allocatedSizeWithTemplate , totalAskingSize );
1776+ }
1777+
1778+ @ Override
1779+ public boolean storagePoolHasEnoughSpaceForResize (StoragePool pool , long currentSize , long newSiz ) {
1780+ if (!checkUsagedSpace (pool )) {
1781+ return false ;
1782+ }
1783+ if (s_logger .isDebugEnabled ()) {
1784+ s_logger .debug ("Destination pool id: " + pool .getId ());
1785+ }
1786+ long totalAskingSize = newSiz - currentSize ;
1787+
1788+ if (totalAskingSize <= 0 ) {
1789+ return true ;
1790+ } else {
1791+ final StoragePoolVO poolVO = _storagePoolDao .findById (pool .getId ());
1792+ final long allocatedSizeWithTemplate = _capacityMgr .getAllocatedPoolCapacity (poolVO , null );
1793+ return checkPoolforSpace (pool , allocatedSizeWithTemplate , totalAskingSize );
1794+ }
1795+ }
1796+
1797+ private boolean checkPoolforSpace (StoragePool pool , long allocatedSizeWithTemplate , long totalAskingSize ) {
1798+ // allocated space includes templates
1799+ StoragePoolVO poolVO = _storagePoolDao .findById (pool .getId ());
1800+
17751801 long totalOverProvCapacity ;
17761802 if (pool .getPoolType () == StoragePoolType .NetworkFilesystem || pool .getPoolType () == StoragePoolType .VMFS || pool .getPoolType () == StoragePoolType .Filesystem ) {
17771803 BigDecimal overProvFactor = getStorageOverProvisioningFactor (pool .getId ());
17781804 totalOverProvCapacity = overProvFactor .multiply (new BigDecimal (pool .getCapacityBytes ())).longValue ();
1779- s_logger .debug ("Found storage pool " + poolVO .getName () + " of type " + pool .getPoolType ().toString () + " with overprovisioning factor "
1780- + overProvFactor .toString ());
1805+ s_logger .debug ("Found storage pool " + poolVO .getName () + " of type " + pool .getPoolType ().toString () + " with overprovisioning factor " + overProvFactor .toString ());
17811806 s_logger .debug ("Total over provisioned capacity calculated is " + overProvFactor + " * " + pool .getCapacityBytes ());
17821807 } else {
17831808 totalOverProvCapacity = pool .getCapacityBytes ();
@@ -1787,26 +1812,23 @@ public boolean storagePoolHasEnoughSpace(List<Volume> volumes, StoragePool pool,
17871812 s_logger .debug ("Total capacity of the pool " + poolVO .getName () + " id: " + pool .getId () + " is " + totalOverProvCapacity );
17881813 double storageAllocatedThreshold = CapacityManager .StorageAllocatedCapacityDisableThreshold .valueIn (pool .getDataCenterId ());
17891814 if (s_logger .isDebugEnabled ()) {
1790- s_logger .debug ("Checking pool: " + pool .getId () + " for volume allocation " + volumes .toString () + ", maxSize : " + totalOverProvCapacity +
1791- ", totalAllocatedSize : " + allocatedSizeWithTemplate + ", askingSize : " + totalAskingSize + ", allocated disable threshold: " +
1792- storageAllocatedThreshold );
1815+ s_logger .debug ("Checking pool: " + pool .getId () + " for storage allocation , maxSize : " + totalOverProvCapacity + ", totalAllocatedSize : " + allocatedSizeWithTemplate
1816+ + ", askingSize : " + totalAskingSize + ", allocated disable threshold: " + storageAllocatedThreshold );
17931817 }
17941818
17951819 double usedPercentage = (allocatedSizeWithTemplate + totalAskingSize ) / (double )(totalOverProvCapacity );
17961820 if (usedPercentage > storageAllocatedThreshold ) {
17971821 if (s_logger .isDebugEnabled ()) {
1798- s_logger .debug ("Insufficient un-allocated capacity on: " + pool .getId () + " for volume allocation: " + volumes .toString () +
1799- " since its allocated percentage: " + usedPercentage + " has crossed the allocated pool.storage.allocated.capacity.disablethreshold: " +
1800- storageAllocatedThreshold + ", skipping this pool" );
1822+ s_logger .debug ("Insufficient un-allocated capacity on: " + pool .getId () + " for storage allocation since its allocated percentage: " + usedPercentage
1823+ + " has crossed the allocated pool.storage.allocated.capacity.disablethreshold: " + storageAllocatedThreshold + ", skipping this pool" );
18011824 }
18021825 return false ;
18031826 }
18041827
18051828 if (totalOverProvCapacity < (allocatedSizeWithTemplate + totalAskingSize )) {
18061829 if (s_logger .isDebugEnabled ()) {
1807- s_logger .debug ("Insufficient un-allocated capacity on: " + pool .getId () + " for volume allocation: " + volumes .toString () +
1808- ", not enough storage, maxSize : " + totalOverProvCapacity + ", totalAllocatedSize : " + allocatedSizeWithTemplate + ", askingSize : " +
1809- totalAskingSize );
1830+ s_logger .debug ("Insufficient un-allocated capacity on: " + pool .getId () + " for storage allocation, not enough storage, maxSize : " + totalOverProvCapacity
1831+ + ", totalAllocatedSize : " + allocatedSizeWithTemplate + ", askingSize : " + totalAskingSize );
18101832 }
18111833 return false ;
18121834 }
0 commit comments