Skip to content

Commit 29dfeac

Browse files
committed
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
1 parent f241455 commit 29dfeac

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,13 +1222,6 @@ public boolean deleteVolume(long volumeId, Account caller) throws ConcurrentOper
12221222
if (instanceId == null || (vmInstance.getType().equals(VirtualMachine.Type.User))) {
12231223
// Decrement the resource count for volumes and primary storage belonging user VM's only
12241224
_resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplayVolume());
1225-
/* If volume is in primary storage, decrement primary storage count else decrement secondary
1226-
storage count (in case of upload volume). */
1227-
if (volume.getFolder() != null || volume.getPath() != null || volume.getState() == Volume.State.Allocated) {
1228-
_resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.primary_storage.getOrdinal());
1229-
} else {
1230-
_resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.secondary_storage.getOrdinal());
1231-
}
12321225
}
12331226
}
12341227
// Mark volume as removed if volume has not been created on primary or secondary
@@ -1243,13 +1236,17 @@ storage count (in case of upload volume). */
12431236
s_logger.info("Expunging volume " + volume.getId() + " from primary data store");
12441237
AsyncCallFuture<VolumeApiResult> future = volService.expungeVolumeAsync(volOnPrimary);
12451238
future.get();
1239+
//decrement primary storage count
1240+
_resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.primary_storage.getOrdinal());
12461241
}
12471242
// expunge volume from secondary if volume is on image store
12481243
VolumeInfo volOnSecondary = volFactory.getVolume(volume.getId(), DataStoreRole.Image);
12491244
if (volOnSecondary != null) {
12501245
s_logger.info("Expunging volume " + volume.getId() + " from secondary data store");
12511246
AsyncCallFuture<VolumeApiResult> future2 = volService.expungeVolumeAsync(volOnSecondary);
12521247
future2.get();
1248+
//decrement secondary storage count
1249+
_resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.secondary_storage.getOrdinal());
12531250
}
12541251
// delete all cache entries for this volume
12551252
List<VolumeInfo> cacheVols = volFactory.listVolumeOnCache(volume.getId());

0 commit comments

Comments
 (0)