|
184 | 184 | import com.cloud.vm.dao.UserVmCloneSettingDao; |
185 | 185 | import com.cloud.vm.dao.UserVmDao; |
186 | 186 | import com.cloud.vm.dao.VMInstanceDetailsDao; |
| 187 | +import com.cloud.vm.dao.VMInstanceDao; |
187 | 188 |
|
188 | 189 | public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrationService, Configurable { |
189 | 190 |
|
@@ -270,6 +271,8 @@ public enum UserVmCloneType { |
270 | 271 | ConfigDepot configDepot; |
271 | 272 | @Inject |
272 | 273 | ConfigurationDao configurationDao; |
| 274 | + @Inject |
| 275 | + VMInstanceDao vmInstanceDao; |
273 | 276 |
|
274 | 277 | @Inject |
275 | 278 | protected SnapshotHelper snapshotHelper; |
@@ -972,9 +975,7 @@ private DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering |
972 | 975 |
|
973 | 976 | // Create event and update resource count for volumes if vm is a user vm |
974 | 977 | if (vm.getType() == VirtualMachine.Type.User) { |
975 | | - |
976 | 978 | Long offeringId = null; |
977 | | - |
978 | 979 | if (!offering.isComputeOnly()) { |
979 | 980 | offeringId = offering.getId(); |
980 | 981 | } |
@@ -1943,14 +1944,18 @@ protected void updateVolumeSize(DataStore store, VolumeVO vol) throws ResourceAl |
1943 | 1944 |
|
1944 | 1945 | if (newSize != vol.getSize()) { |
1945 | 1946 | DiskOfferingVO diskOffering = diskOfferingDao.findByIdIncludingRemoved(vol.getDiskOfferingId()); |
1946 | | - if (newSize > vol.getSize()) { |
1947 | | - _resourceLimitMgr.checkPrimaryStorageResourceLimit(_accountMgr.getActiveAccountById(vol.getAccountId()), |
1948 | | - vol.isDisplay(), newSize - vol.getSize(), diskOffering); |
1949 | | - _resourceLimitMgr.incrementVolumePrimaryStorageResourceCount(vol.getAccountId(), vol.isDisplay(), |
1950 | | - newSize - vol.getSize(), diskOffering); |
1951 | | - } else { |
1952 | | - _resourceLimitMgr.decrementVolumePrimaryStorageResourceCount(vol.getAccountId(), vol.isDisplay(), |
1953 | | - vol.getSize() - newSize, diskOffering); |
| 1947 | + VMInstanceVO vm = vol.getInstanceId() != null ? vmInstanceDao.findById(vol.getInstanceId()) : null; |
| 1948 | + if (vm == null || vm.getType() == VirtualMachine.Type.User) { |
| 1949 | + // Update resource count for user vm volumes when volume is attached |
| 1950 | + if (newSize > vol.getSize()) { |
| 1951 | + _resourceLimitMgr.checkPrimaryStorageResourceLimit(_accountMgr.getActiveAccountById(vol.getAccountId()), |
| 1952 | + vol.isDisplay(), newSize - vol.getSize(), diskOffering); |
| 1953 | + _resourceLimitMgr.incrementVolumePrimaryStorageResourceCount(vol.getAccountId(), vol.isDisplay(), |
| 1954 | + newSize - vol.getSize(), diskOffering); |
| 1955 | + } else { |
| 1956 | + _resourceLimitMgr.decrementVolumePrimaryStorageResourceCount(vol.getAccountId(), vol.isDisplay(), |
| 1957 | + vol.getSize() - newSize, diskOffering); |
| 1958 | + } |
1954 | 1959 | } |
1955 | 1960 | vol.setSize(newSize); |
1956 | 1961 | _volsDao.persist(vol); |
|
0 commit comments