@@ -9864,7 +9864,7 @@ public Optional<UserVm> cloneVirtualMachine(CloneVMCmd cmd) throws ResourceAlloc
98649864 _snapshotDao.update(snapVO.getId(), snapVO);
98659865 }
98669866 VolumeVO newVol = cloneVolumeFromSnapToDB(curVmAccount, true, zoneId, diskOfferingId, provisioningType, size, minIops, maxIops, parentRootVolume, rootVolumeName,
9867- _uuidMgr.generateUuid(Volume.class, null), new HashMap<>(), Volume.Type.ROOT);
9867+ _uuidMgr.generateUuid(Volume.class, null), new HashMap<>(), Volume.Type.ROOT, 0L );
98689868 VolumeVO rootVolume = (VolumeVO) _volumeService.cloneVolumeFromSnapshot(newVol, snapVO.getId(), curVm.getId());
98699869 if (rootVolume == null) {
98709870 throw new CloudRuntimeException("Creation of root volume is not queried. The virtual machine cannot be cloned!");
@@ -9907,16 +9907,13 @@ public Optional<UserVm> cloneVirtualMachine(CloneVMCmd cmd) throws ResourceAlloc
99079907 VolumeVO newDataDiskVol = null;
99089908 try {
99099909 newDataDiskVol = cloneVolumeFromSnapToDB(curVmAccount, true, zoneId, diskOfferingId, provisioningType, size, minIops, maxIops, parentDataDiskVolume, dataVolumeName,
9910- _uuidMgr.generateUuid(Volume.class, null), new HashMap<>(), Volume.Type.DATADISK);
9910+ _uuidMgr.generateUuid(Volume.class, null), new HashMap<>(), Volume.Type.DATADISK, parentDataDiskVolume.getDeviceId() );
99119911 VolumeVO dataDiskVolume = (VolumeVO) _volumeService.cloneVolumeFromSnapshot(newDataDiskVol, snapVO.getId(), curVm.getId());
99129912 if (dataDiskVolume == null) {
99139913 throw new CloudRuntimeException("Creation of root volume is not queried. The virtual machine cannot be cloned!");
99149914 }
99159915 createdVolumes.add(dataDiskVolume);
9916-
9917- for (VolumeVO createdVol : createdVolumes) {
9918- _volumeService.attachVolumeToVM(cmd.getEntityId(), createdVol.getId(), createdVol.getDeviceId(), false);
9919- }
9916+ _volumeService.attachVolumeToVM(cmd.getEntityId(), dataDiskVolume.getId(), dataDiskVolume.getDeviceId(), false);
99209917 } catch (CloudRuntimeException e){
99219918 logger.warn("data disk process failed during clone, clearing the temporary resources...");
99229919 for (VolumeVO dataDiskToClear : createdVolumes) {
@@ -10033,7 +10030,7 @@ public UserVm createCloneVM(CloneVMCmd cmd, Long rootVolumeId) throws Concurrent
1003310030 private VolumeVO cloneVolumeFromSnapToDB(final Account owner, final Boolean displayVolume, final Long zoneId, final Long diskOfferingId,
1003410031 final Storage.ProvisioningType provisioningType, final Long size, final Long minIops, final Long maxIops,
1003510032 final VolumeVO parentVolume, final String volumeName, final String uuid, final Map<String, String> details,
10036- Volume.Type volType) {
10033+ Volume.Type volType, final Long deviceId ) {
1003710034 return Transaction.execute((TransactionCallback<VolumeVO>) status -> {
1003810035 VolumeVO volume = new VolumeVO(volumeName, -1, -1, -1, -1, Long.valueOf(-1), null, null, provisioningType, 0, volType);
1003910036 volume.setPoolId(null);
@@ -10049,9 +10046,8 @@ private VolumeVO cloneVolumeFromSnapToDB(final Account owner, final Boolean disp
1004910046 volume.setInstanceId(null);
1005010047 volume.setUpdated(new Date());
1005110048 volume.setDisplayVolume(displayVolume);
10052- if (volType == Volume.Type.ROOT) {
10053- volume.setDeviceId(0L);
10054- }
10049+ volume.setDeviceId(deviceId);
10050+
1005510051 if (parentVolume != null) {
1005610052 volume.setTemplateId(parentVolume.getTemplateId());
1005710053 volume.setFormat(parentVolume.getFormat());
0 commit comments