Skip to content

Commit e363c97

Browse files
authored
CSTACKEX-337: fixing the bug for First VM deployment double-counts template size (#125)
template size is counted twice when calculating the minimum primary storagepool size required <img width="2196" height="902" alt="image" src="https://github.com/user-attachments/assets/009bc45f-4375-41f7-ae1c-90edca683a87" /> ### Description storagePoolHasEnoughSpace accepts a pool when allocatedSizeWithTemplate + totalAskingSize fits. On the first VM deploy from a template onto a managed pool, the template size was added on both sides. For a root volume, the method passes the template into getAllocatedPoolCapacity, which stored it in allocatedSizeWithTemplate. It then adds the volume size and getAskingSizeForTemplateBasedOnClusterAndStoragePool into totalAskingSize. That second call returns the template size again from getBytesRequiredForTemplate when the pool is managed and clusterId is set. The check asked for used bytes + volume size + 2 × template size. Managed pools now return only getUsedBytes from getAllocatedPoolCapacity. The template is reserved once, in totalAskingSize. This extra add came from Dell's PowerFlex PR.Before that, a managed pool contributed only getUsedBytes to allocatedSizeWithTemplate. This PR... <!--- Describe your changes in DETAIL - And how has behaviour functionally changed. --> <!-- For new features, provide link to FS, dev ML discussion etc. --> <!-- In case of bug fix, the expected and actual behaviours, steps to reproduce. --> <!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be closed when this PR gets merged --> <!-- For addressing multiple issues/PRs, use multiple "Fixes: #<id>" --> <!-- Fixes: # --> <!--- ******************************************************************************* --> <!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE DOCUMENTATION. --> <!--- PLEASE PUT AN 'X' in only **ONE** box --> <!--- ******************************************************************************* --> ### Types of changes - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] New feature (non-breaking change which adds functionality) - [X] Bug fix (non-breaking change which fixes an issue) - [ ] Enhancement (improves an existing feature and functionality) - [ ] Cleanup (Code refactoring and cleanup, that may add test cases) - [ ] Build/CI - [ ] Test (unit or integration test code) ### Feature/Enhancement Scale or Bug Severity #### Feature/Enhancement Scale - [ ] Major - [X] Minor #### Bug Severity - [ ] BLOCKER - [ ] Critical - [ ] Major - [X] Minor - [ ] Trivial ### Screenshots (if appropriate): ### How Has This Been Tested? ISCSI VM creation , allocated size get's only used bytes of pool for first time VM creation <img width="1403" height="272" alt="Screenshot 2026-10-15 at 6 52 45 PM" src="https://github.com/user-attachments/assets/3d862c7b-a8fe-472c-9857-29003284cb22" /> NFS VM creation , allocated size get's only used bytes of pool for first time VM creation <img width="1402" height="358" alt="Screenshot 2026-10-15 at 8 37 29 PM" src="https://github.com/user-attachments/assets/88bdca34-3144-45f2-a081-4f864a48ed39" /> <img width="1453" height="271" alt="Screenshot 2026-10-15 at 8 38 43 PM" src="https://github.com/user-attachments/assets/7b3635c5-d1df-4cf2-b38b-71dce915410e" /> BOTH NFS AND ISCSI POOLS WERE MADE OF 18 GB and succeeded <img width="1517" height="118" alt="Screenshot 2026-10-15 at 8 38 52 PM" src="https://github.com/user-attachments/assets/ba7607d6-c176-4216-88ab-3b934c5df549" /> <!-- Please describe in detail how you tested your changes. --> <!-- Include details of your testing environment, and the tests you ran to --> #### How did you try to break this feature and the system with this change? <!-- see how your change affects other areas of the code, etc. --> <!-- Please read the [CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md) document -->
1 parent be1f7dd commit e363c97

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

‎server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -573,25 +573,16 @@ public long getUsedIops(StoragePoolVO pool) {
573573
throw new CloudRuntimeException("Storage driver in CapacityManagerImpl.getUsedIops(StoragePoolVO) is not a PrimaryDataStoreDriver.");
574574
}
575575

576+
//Managed pool, return value contains used size of the pool.
577+
//Unmanaged pool, return value contains used pool size and template size.
576578
@Override
577579
public long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation) {
578580
long totalAllocatedSize;
579581

580582
// if the storage pool is managed, the used bytes can be larger than the sum of the sizes of all of the non-destroyed volumes
581583
// in this case, call getUsedBytes(StoragePoolVO)
582584
if (pool.isManaged()) {
583-
totalAllocatedSize = getUsedBytes(pool);
584-
585-
if (templateForVmCreation != null) {
586-
VMTemplateStoragePoolVO templatePoolVO = _templatePoolDao.findByPoolTemplate(pool.getId(), templateForVmCreation.getId(), null);
587-
if (templatePoolVO == null) {
588-
// template is not installed in the pool, consider the template size for allocation
589-
long templateForVmCreationSize = templateForVmCreation.getSize() != null ? templateForVmCreation.getSize() : 0;
590-
totalAllocatedSize += templateForVmCreationSize;
591-
}
592-
}
593-
594-
return totalAllocatedSize;
585+
return getUsedBytes(pool);
595586
} else {
596587
// Get size for all the non-destroyed volumes.
597588
Pair<Long, Long> sizes = _volumeDao.getNonDestroyedCountAndTotalByPool(pool.getId());

0 commit comments

Comments
 (0)