From 633de1180d6114c1ba9f2c845623829e4420833b Mon Sep 17 00:00:00 2001 From: Sathvika Date: Mon, 19 Oct 2026 20:37:28 +0530 Subject: [PATCH] CSTACKEX-337: fixing the bug for First VM deployment double-counts template size (#125) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit template size is counted twice when calculating the minimum primary storagepool size required image ### 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... ### 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 Screenshot 2026-10-15 at 6 52 45 PM NFS VM creation , allocated size get's only used bytes of pool for first time VM creation Screenshot 2026-10-15 at 8 37 29 PM Screenshot 2026-10-15 at 8 38 43 PM BOTH NFS AND ISCSI POOLS WERE MADE OF 18 GB and succeeded Screenshot 2026-10-15 at 8 38 52 PM #### How did you try to break this feature and the system with this change? --- .../com/cloud/capacity/CapacityManagerImpl.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java b/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java index 3be7384ffb71..8ed70f32f9af 100644 --- a/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java @@ -573,6 +573,8 @@ public long getUsedIops(StoragePoolVO pool) { throw new CloudRuntimeException("Storage driver in CapacityManagerImpl.getUsedIops(StoragePoolVO) is not a PrimaryDataStoreDriver."); } + //Managed pool, return value contains used size of the pool. + //Unmanaged pool, return value contains used pool size and template size. @Override public long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation) { long totalAllocatedSize; @@ -580,18 +582,7 @@ public long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateFo // 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 // in this case, call getUsedBytes(StoragePoolVO) if (pool.isManaged()) { - totalAllocatedSize = getUsedBytes(pool); - - if (templateForVmCreation != null) { - VMTemplateStoragePoolVO templatePoolVO = _templatePoolDao.findByPoolTemplate(pool.getId(), templateForVmCreation.getId(), null); - if (templatePoolVO == null) { - // template is not installed in the pool, consider the template size for allocation - long templateForVmCreationSize = templateForVmCreation.getSize() != null ? templateForVmCreation.getSize() : 0; - totalAllocatedSize += templateForVmCreationSize; - } - } - - return totalAllocatedSize; + return getUsedBytes(pool); } else { // Get size for all the non-destroyed volumes. Pair sizes = _volumeDao.getNonDestroyedCountAndTotalByPool(pool.getId());