Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update rootdisksize detail on restore VM #8981

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7975,17 +7975,25 @@ public Pair<UserVmVO, Volume> doInTransaction(final TransactionStatus status) th
private void updateVolume(Volume vol, VMTemplateVO template, UserVmVO userVm, DiskOffering diskOffering, Map<String, String> 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);
}
}
}

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());
Expand All @@ -7999,6 +8007,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);
Expand Down
Loading