Skip to content

Commit 0271494

Browse files
authored
Fix: Update rootdisksize detail on restore VM (#8981)
* Fix: Update rootdisksize detail on restore VM * minor fixup
1 parent f7b95cd commit 0271494

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7975,17 +7975,25 @@ public Pair<UserVmVO, Volume> doInTransaction(final TransactionStatus status) th
79757975
private void updateVolume(Volume vol, VMTemplateVO template, UserVmVO userVm, DiskOffering diskOffering, Map<String, String> details) {
79767976
VolumeVO resizedVolume = (VolumeVO) vol;
79777977

7978-
if (userVmDetailsDao.findDetail(userVm.getId(), VmDetailConstants.ROOT_DISK_SIZE) == null && !vol.getSize().equals(template.getSize())) {
7979-
if (template.getSize() != null) {
7978+
if (template != null && template.getSize() != null) {
7979+
UserVmDetailVO vmRootDiskSizeDetail = userVmDetailsDao.findDetail(userVm.getId(), VmDetailConstants.ROOT_DISK_SIZE);
7980+
if (vmRootDiskSizeDetail == null) {
79807981
resizedVolume.setSize(template.getSize());
7982+
} else {
7983+
long rootDiskSize = Long.parseLong(vmRootDiskSizeDetail.getValue()) * GiB_TO_BYTES;
7984+
if (template.getSize() >= rootDiskSize) {
7985+
resizedVolume.setSize(template.getSize());
7986+
userVmDetailsDao.remove(vmRootDiskSizeDetail.getId());
7987+
} else {
7988+
resizedVolume.setSize(rootDiskSize);
7989+
}
79817990
}
79827991
}
79837992

79847993
if (diskOffering != null) {
79857994
resizedVolume.setDiskOfferingId(diskOffering.getId());
7986-
resizedVolume.setSize(diskOffering.getDiskSize());
7987-
if (diskOffering.isCustomized()) {
7988-
resizedVolume.setSize(vol.getSize());
7995+
if (!diskOffering.isCustomized()) {
7996+
resizedVolume.setSize(diskOffering.getDiskSize());
79897997
}
79907998
if (diskOffering.getMinIops() != null) {
79917999
resizedVolume.setMinIops(diskOffering.getMinIops());
@@ -7999,6 +8007,14 @@ private void updateVolume(Volume vol, VMTemplateVO template, UserVmVO userVm, Di
79998007
if (StringUtils.isNumeric(details.get(VmDetailConstants.ROOT_DISK_SIZE))) {
80008008
Long rootDiskSize = Long.parseLong(details.get(VmDetailConstants.ROOT_DISK_SIZE)) * GiB_TO_BYTES;
80018009
resizedVolume.setSize(rootDiskSize);
8010+
UserVmDetailVO vmRootDiskSizeDetail = userVmDetailsDao.findDetail(userVm.getId(), VmDetailConstants.ROOT_DISK_SIZE);
8011+
if (vmRootDiskSizeDetail != null) {
8012+
vmRootDiskSizeDetail.setValue(details.get(VmDetailConstants.ROOT_DISK_SIZE));
8013+
userVmDetailsDao.update(vmRootDiskSizeDetail.getId(), vmRootDiskSizeDetail);
8014+
} else {
8015+
userVmDetailsDao.persist(new UserVmDetailVO(userVm.getId(), VmDetailConstants.ROOT_DISK_SIZE,
8016+
details.get(VmDetailConstants.ROOT_DISK_SIZE), true));
8017+
}
80028018
}
80038019

80048020
String minIops = details.get(MIN_IOPS);

0 commit comments

Comments
 (0)