From 48170e1530046104b8d589f3dedb214c9a47e7ba Mon Sep 17 00:00:00 2001 From: Slavka Peleva Date: Tue, 29 Jul 2025 08:59:29 +0300 Subject: [PATCH 1/2] Fix of deployment VM from a copied snapshot in another zone fix of deploy VM with a snapshot that is copied to another zone fix of creating StorPool volume from a snapshot if the size in the offering is bigger than the snapshot size --- .../StorPoolDownloadTemplateCommandWrapper.java | 3 ++- .../main/java/com/cloud/vm/UserVmManagerImpl.java | 12 +----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java index 3e7118ab81d7..87b04317d2c1 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java @@ -103,9 +103,10 @@ public CopyCmdAnswer execute(final StorPoolDownloadTemplateCommand cmd, final Li final QemuImgFile srcFile = new QemuImgFile(srcDisk.getPath(), srcDisk.getFormat()); final QemuImg qemu = new QemuImg(cmd.getWaitInMillSeconds()); - StorPoolStorageAdaptor.resize( Long.toString(srcDisk.getVirtualSize()), dst.getPath()); if (dst instanceof TemplateObjectTO) { + StorPoolStorageAdaptor.resize( Long.toString(srcDisk.getVirtualSize()), dst.getPath()); + ((TemplateObjectTO) dst).setSize(srcDisk.getVirtualSize()); } diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 6cdcba7e3b62..cd7d198eb611 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -4195,15 +4195,7 @@ private UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOffe } DiskOfferingVO rootDiskOffering = _diskOfferingDao.findById(rootDiskOfferingId); - long volumesSize = 0; - if (volume != null) { - volumesSize = volume.getSize(); - } else if (snapshot != null) { - VolumeVO volumeVO = _volsDao.findById(snapshot.getVolumeId()); - volumesSize = volumeVO != null ? volumeVO.getSize() : 0; - } else { - volumesSize = configureCustomRootDiskSize(customParameters, template, hypervisorType, rootDiskOffering); - } + long volumesSize = configureCustomRootDiskSize(customParameters, template, hypervisorType, rootDiskOffering); if (rootDiskOffering.getEncrypt() && hypervisorType != HypervisorType.KVM) { throw new InvalidParameterValueException("Root volume encryption is not supported for hypervisor type " + hypervisorType); @@ -6292,7 +6284,6 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE } _accountMgr.checkAccess(caller, null, true, volume); templateId = volume.getTemplateId(); - overrideDiskOfferingId = volume.getDiskOfferingId(); } else if (cmd.getSnapshotId() != null) { snapshot = _snapshotDao.findById(cmd.getSnapshotId()); if (snapshot == null) { @@ -6301,7 +6292,6 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE _accountMgr.checkAccess(caller, null, true, snapshot); VolumeInfo volumeOfSnapshot = getVolume(snapshot.getVolumeId(), templateId, true); templateId = volumeOfSnapshot.getTemplateId(); - overrideDiskOfferingId = volumeOfSnapshot.getDiskOfferingId(); } VirtualMachineTemplate template = null; From 2d2990d43193abb2340a784aabed91a1c99033fc Mon Sep 17 00:00:00 2001 From: Slavka Peleva Date: Tue, 5 Aug 2025 11:41:05 +0300 Subject: [PATCH 2/2] addressed comments --- .../wrapper/StorPoolDownloadTemplateCommandWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java index 87b04317d2c1..da67812cbbee 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java @@ -105,7 +105,7 @@ public CopyCmdAnswer execute(final StorPoolDownloadTemplateCommand cmd, final Li final QemuImg qemu = new QemuImg(cmd.getWaitInMillSeconds()); if (dst instanceof TemplateObjectTO) { - StorPoolStorageAdaptor.resize( Long.toString(srcDisk.getVirtualSize()), dst.getPath()); + StorPoolStorageAdaptor.resize(Long.toString(srcDisk.getVirtualSize()), dst.getPath()); ((TemplateObjectTO) dst).setSize(srcDisk.getVirtualSize()); }