From 29dfeac857e454fac3f987e5a4194480091af716 Mon Sep 17 00:00:00 2001 From: Rajani Karuturi Date: Mon, 21 Sep 2015 16:11:15 +0530 Subject: [PATCH] CLOUDSTACK-8889: delete volume doesnt decrement primary store resource count Primary Storage count for an account does not decrease when a Data Disk is deleted belonging to the account unless the VM to which volume belonged is destroyed The resource counts are updated even before the disk is actually deleted resulting in the same value. Moved the resource counts updation to after the expunge operation as thats when the disk is actually deleted. all the tests in test/integration/component/test_ps_limits.py now pass --- .../src/com/cloud/storage/VolumeApiServiceImpl.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index d4e8c99fdca..6fe0a14343e 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -1222,13 +1222,6 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic if (instanceId == null || (vmInstance.getType().equals(VirtualMachine.Type.User))) { // Decrement the resource count for volumes and primary storage belonging user VM's only _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplayVolume()); - /* If volume is in primary storage, decrement primary storage count else decrement secondary - storage count (in case of upload volume). */ - if (volume.getFolder() != null || volume.getPath() != null || volume.getState() == Volume.State.Allocated) { - _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.primary_storage.getOrdinal()); - } else { - _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.secondary_storage.getOrdinal()); - } } } // Mark volume as removed if volume has not been created on primary or secondary @@ -1243,6 +1236,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic s_logger.info("Expunging volume " + volume.getId() + " from primary data store"); AsyncCallFuture future = volService.expungeVolumeAsync(volOnPrimary); future.get(); + //decrement primary storage count + _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.primary_storage.getOrdinal()); } // expunge volume from secondary if volume is on image store VolumeInfo volOnSecondary = volFactory.getVolume(volume.getId(), DataStoreRole.Image); @@ -1250,6 +1245,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic s_logger.info("Expunging volume " + volume.getId() + " from secondary data store"); AsyncCallFuture future2 = volService.expungeVolumeAsync(volOnSecondary); future2.get(); + //decrement secondary storage count + _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.secondary_storage.getOrdinal()); } // delete all cache entries for this volume List cacheVols = volFactory.listVolumeOnCache(volume.getId());