Skip to content

Commit 69e63e4

Browse files
Abhinandan PrateekRohit Yadav
authored andcommitted
CLOUDSTACK-9473: storage pool capacity check when volume is resized or migrated is added
1 parent fcf9282 commit 69e63e4

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

engine/components-api/src/com/cloud/storage/StorageManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public interface StorageManager extends StorageService {
134134
*/
135135
boolean storagePoolHasEnoughSpace(List<Volume> volume, StoragePool pool, Long clusterId);
136136

137+
boolean storagePoolHasEnoughSpaceForResize(StoragePool pool, long currentSize, long newSiz);
138+
137139
boolean registerHostListener(String providerUuid, HypervisorHostListener listener);
138140

139141
void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException;

server/src/com/cloud/storage/StorageManagerImpl.java

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,14 @@ private VolumeVO orchestrateResizeVolume(long volumeId, long currentSize, long n
11041104
UserVmVO userVm = _userVmDao.findById(volume.getInstanceId());
11051105
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
11061106
boolean isManaged = storagePool.isManaged();
1107+
1108+
List<Volume> volumes = new ArrayList<Volume>();
1109+
volumes.add(volume);
1110+
1111+
//check if there is space
1112+
if (!storageMgr.storagePoolHasEnoughSpaceForResize(storagePool, currentSize, newSize)) {
1113+
throw new CloudRuntimeException("Storage pool " + storagePool.getName() + " does not have enough space to resize volume " + volume.getName());
1114+
}
11071115
/*
11081116
* get a list of hosts to send the commands to, try the system the
11091117
* associated vm is running on first, then the last known place it ran.
@@ -1923,6 +1931,14 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
19231931
throw new InvalidParameterValueException("Failed to find the destination storage pool: " + storagePoolId);
19241932
}
19251933

1934+
List<Volume> volumes = new ArrayList<Volume>();
1935+
volumes.add(vol);
1936+
1937+
//check if there is space
1938+
if (!storageMgr.storagePoolHasEnoughSpace(volumes, destPool)) {
1939+
throw new CloudRuntimeException("Storage pool " + destPool.getName() + " does not have enough space to migrate volume " + vol.getName());
1940+
}
1941+
19261942
if (_volumeMgr.volumeOnSharedStoragePool(vol)) {
19271943
if (destPool.isLocal()) {
19281944
throw new InvalidParameterValueException("Migration of volume from shared to local storage pool is not supported");

0 commit comments

Comments
 (0)