Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
12 changes: 1 addition & 11 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simplified logic now ignores the actual size of existing volumes and snapshots, which could lead to data loss or corruption when the configured size is smaller than the source volume/snapshot size. Consider adding validation to ensure the configured size is at least as large as the source.

Suggested change
// Validate that the configured size is at least as large as the source volume or snapshot size
if (snapshot != null) {
long sourceSize = snapshot.getSize(); // Assuming snapshot.getSize() returns the size in bytes
if (volumesSize < sourceSize) {
throw new InvalidParameterValueException("The configured root disk size (" + volumesSize +
" bytes) is smaller than the source snapshot size (" + sourceSize + " bytes).");
}
} else if (volume != null) {
long sourceSize = volume.getSize(); // Assuming volume.getSize() returns the size in bytes
if (volumesSize < sourceSize) {
throw new InvalidParameterValueException("The configured root disk size (" + volumesSize +
" bytes) is smaller than the source volume size (" + sourceSize + " bytes).");
}
}

Copilot uses AI. Check for mistakes.
if (rootDiskOffering.getEncrypt() && hypervisorType != HypervisorType.KVM) {
throw new InvalidParameterValueException("Root volume encryption is not supported for hypervisor type " + hypervisorType);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
Loading