From dc41e2b313466121a1d266593a7aa0638c8a4451 Mon Sep 17 00:00:00 2001 From: Vishesh Date: Thu, 25 Apr 2024 13:14:24 +0530 Subject: [PATCH 1/2] Fix: Update rootdisksize detail on restore VM --- .../java/com/cloud/vm/UserVmManagerImpl.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 6c8aec0da48b..23e367097615 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -7975,9 +7975,18 @@ public Pair doInTransaction(final TransactionStatus status) th private void updateVolume(Volume vol, VMTemplateVO template, UserVmVO userVm, DiskOffering diskOffering, Map details) { VolumeVO resizedVolume = (VolumeVO) vol; - if (userVmDetailsDao.findDetail(userVm.getId(), VmDetailConstants.ROOT_DISK_SIZE) == null && !vol.getSize().equals(template.getSize())) { - if (template.getSize() != null) { + if (template != null && template.getSize() != null) { + UserVmDetailVO vmRootDiskSizeDetail = userVmDetailsDao.findDetail(userVm.getId(), VmDetailConstants.ROOT_DISK_SIZE); + if (vmRootDiskSizeDetail == null) { resizedVolume.setSize(template.getSize()); + } else { + long rootDiskSize = Long.parseLong(vmRootDiskSizeDetail.getValue()) * GiB_TO_BYTES; + if (template.getSize() >= rootDiskSize) { + resizedVolume.setSize(template.getSize()); + userVmDetailsDao.remove(vmRootDiskSizeDetail.getId()); + } else { + resizedVolume.setSize(rootDiskSize); + } } } @@ -7999,6 +8008,14 @@ private void updateVolume(Volume vol, VMTemplateVO template, UserVmVO userVm, Di if (StringUtils.isNumeric(details.get(VmDetailConstants.ROOT_DISK_SIZE))) { Long rootDiskSize = Long.parseLong(details.get(VmDetailConstants.ROOT_DISK_SIZE)) * GiB_TO_BYTES; resizedVolume.setSize(rootDiskSize); + UserVmDetailVO vmRootDiskSizeDetail = userVmDetailsDao.findDetail(userVm.getId(), VmDetailConstants.ROOT_DISK_SIZE); + if (vmRootDiskSizeDetail != null) { + vmRootDiskSizeDetail.setValue(details.get(VmDetailConstants.ROOT_DISK_SIZE)); + userVmDetailsDao.update(vmRootDiskSizeDetail.getId(), vmRootDiskSizeDetail); + } else { + userVmDetailsDao.persist(new UserVmDetailVO(userVm.getId(), VmDetailConstants.ROOT_DISK_SIZE, + details.get(VmDetailConstants.ROOT_DISK_SIZE), true)); + } } String minIops = details.get(MIN_IOPS); From 948508e3e819f452a223e2746361b263aff0182c Mon Sep 17 00:00:00 2001 From: Vishesh Date: Fri, 26 Apr 2024 11:05:54 +0530 Subject: [PATCH 2/2] minor fixup --- server/src/main/java/com/cloud/vm/UserVmManagerImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 23e367097615..053537d66ea1 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -7992,9 +7992,8 @@ private void updateVolume(Volume vol, VMTemplateVO template, UserVmVO userVm, Di if (diskOffering != null) { resizedVolume.setDiskOfferingId(diskOffering.getId()); - resizedVolume.setSize(diskOffering.getDiskSize()); - if (diskOffering.isCustomized()) { - resizedVolume.setSize(vol.getSize()); + if (!diskOffering.isCustomized()) { + resizedVolume.setSize(diskOffering.getDiskSize()); } if (diskOffering.getMinIops() != null) { resizedVolume.setMinIops(diskOffering.getMinIops());