Skip to content

Commit f30b5ce

Browse files
raveningDaanHoogland
authored andcommitted
Fix resource count of expunged volume (#3669)
If the volume is in "Expunged" state then it should not be considered towards total resource count of "primarystoragetotal" field. Currently cloudstack takes into resource calculation even if the volume is expunged. The volume itself doesnt exist in primage storage and hence it should not be considered towrds resource caculation. Steps to reproduce the issue: 1 . Get the resource count of "primarystoragetotal" of a particular domain. 2 . Create a VM with 5GB root disk size and stop it. 3 . Now the value of "primarystoragetotal" should be intitial value plus 5. 4 . Navigate to "volumes" of the VM and select "Download Volume" option. 5 . Once the volume is downloaded, expunge the VM. 6 . Get the resource count of "primarystoragetotal". it will be same value as in step 3 But it should be same as initial value obtained in step 1. With this fix, the value obtained at step 6 will be same as in step 1.
1 parent 2427114 commit f30b5ce

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public List<VolumeVO> findByInstanceAndDeviceId(long instanceId, long deviceId)
122122
public List<VolumeVO> findByPoolId(long poolId) {
123123
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
124124
sc.setParameters("poolId", poolId);
125-
sc.setParameters("notDestroyed", Volume.State.Destroy);
125+
sc.setParameters("notDestroyed", Volume.State.Destroy, Volume.State.Expunged);
126126
sc.setParameters("vType", Volume.Type.ROOT.toString());
127127
return listBy(sc);
128128
}
@@ -132,7 +132,7 @@ public List<VolumeVO> findByInstanceIdAndPoolId(long instanceId, long poolId) {
132132
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
133133
sc.setParameters("instanceId", instanceId);
134134
sc.setParameters("poolId", poolId);
135-
sc.setParameters("notDestroyed", Volume.State.Destroy);
135+
sc.setParameters("notDestroyed", Volume.State.Destroy, Volume.State.Expunged);
136136
return listBy(sc);
137137
}
138138

@@ -148,7 +148,7 @@ public VolumeVO findByPoolIdName(long poolId, String name) {
148148
public List<VolumeVO> findByPoolId(long poolId, Volume.Type volumeType) {
149149
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
150150
sc.setParameters("poolId", poolId);
151-
sc.setParameters("notDestroyed", Volume.State.Destroy);
151+
sc.setParameters("notDestroyed", Volume.State.Destroy, Volume.State.Expunged);
152152

153153
if (volumeType != null) {
154154
sc.setParameters("vType", volumeType.toString());
@@ -349,7 +349,7 @@ public VolumeDaoImpl() {
349349
AllFieldsSearch.and("vType", AllFieldsSearch.entity().getVolumeType(), Op.EQ);
350350
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
351351
AllFieldsSearch.and("destroyed", AllFieldsSearch.entity().getState(), Op.EQ);
352-
AllFieldsSearch.and("notDestroyed", AllFieldsSearch.entity().getState(), Op.NEQ);
352+
AllFieldsSearch.and("notDestroyed", AllFieldsSearch.entity().getState(), Op.NIN);
353353
AllFieldsSearch.and("updateTime", AllFieldsSearch.entity().getUpdated(), SearchCriteria.Op.LT);
354354
AllFieldsSearch.and("updatedCount", AllFieldsSearch.entity().getUpdatedCount(), Op.EQ);
355355
AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.EQ);
@@ -410,6 +410,7 @@ public VolumeDaoImpl() {
410410
primaryStorageSearch.cp();
411411
primaryStorageSearch.and("displayVolume", primaryStorageSearch.entity().isDisplayVolume(), Op.EQ);
412412
primaryStorageSearch.and("isRemoved", primaryStorageSearch.entity().getRemoved(), Op.NULL);
413+
primaryStorageSearch.and("NotCountStates", primaryStorageSearch.entity().getState(), Op.NIN);
413414
primaryStorageSearch.done();
414415

415416
primaryStorageSearch2 = createSearchBuilder(SumCount.class);
@@ -423,6 +424,7 @@ public VolumeDaoImpl() {
423424
primaryStorageSearch2.cp();
424425
primaryStorageSearch2.and("displayVolume", primaryStorageSearch2.entity().isDisplayVolume(), Op.EQ);
425426
primaryStorageSearch2.and("isRemoved", primaryStorageSearch2.entity().getRemoved(), Op.NULL);
427+
primaryStorageSearch2.and("NotCountStates", primaryStorageSearch2.entity().getState(), Op.NIN);
426428
primaryStorageSearch2.done();
427429

428430
secondaryStorageSearch = createSearchBuilder(SumCount.class);
@@ -448,7 +450,7 @@ public Pair<Long, Long> getCountAndTotalByPool(long poolId) {
448450
public Long countAllocatedVolumesForAccount(long accountId) {
449451
SearchCriteria<Long> sc = CountByAccount.create();
450452
sc.setParameters("account", accountId);
451-
sc.setParameters("state", Volume.State.Destroy);
453+
sc.setParameters("state", Volume.State.Destroy, Volume.State.Expunged);
452454
sc.setParameters("displayVolume", 1);
453455
return customSearch(sc, null).get(0);
454456
}
@@ -464,6 +466,7 @@ public long primaryStorageUsedForAccount(long accountId, List<Long> virtualRoute
464466
}
465467
sc.setParameters("accountId", accountId);
466468
sc.setParameters("states", State.Allocated);
469+
sc.setParameters("NotCountStates", State.Destroy, State.Expunged);
467470
sc.setParameters("displayVolume", 1);
468471
List<SumCount> storageSpace = customSearch(sc, null);
469472
if (storageSpace != null) {

0 commit comments

Comments
 (0)