@@ -10118,7 +10118,7 @@ public Optional<UserVm> cloneVirtualMachine(CloneVMCmd cmd) throws ResourceAlloc
1011810118 _snapshotDao.update(snapVO.getId(), snapVO);
1011910119 }
1012010120 VolumeVO newVol = cloneVolumeFromSnapToDB(curVmAccount, true, zoneId, diskOfferingId, provisioningType, size, minIops, maxIops, parentRootVolume, rootVolumeName,
10121- _uuidMgr.generateUuid(Volume.class, null), new HashMap<>(), Volume.Type.ROOT);
10121+ _uuidMgr.generateUuid(Volume.class, null), new HashMap<>(), Volume.Type.ROOT, 0L );
1012210122 VolumeVO rootVolume = (VolumeVO) _volumeService.cloneVolumeFromSnapshot(newVol, snapVO.getId(), curVm.getId());
1012310123 if (rootVolume == null) {
1012410124 throw new CloudRuntimeException("Creation of root volume is not queried. The virtual machine cannot be cloned!");
@@ -10161,16 +10161,13 @@ public Optional<UserVm> cloneVirtualMachine(CloneVMCmd cmd) throws ResourceAlloc
1016110161 VolumeVO newDataDiskVol = null;
1016210162 try {
1016310163 newDataDiskVol = cloneVolumeFromSnapToDB(curVmAccount, true, zoneId, diskOfferingId, provisioningType, size, minIops, maxIops, parentDataDiskVolume, dataVolumeName,
10164- _uuidMgr.generateUuid(Volume.class, null), new HashMap<>(), Volume.Type.DATADISK);
10164+ _uuidMgr.generateUuid(Volume.class, null), new HashMap<>(), Volume.Type.DATADISK, parentDataDiskVolume.getDeviceId() );
1016510165 VolumeVO dataDiskVolume = (VolumeVO) _volumeService.cloneVolumeFromSnapshot(newDataDiskVol, snapVO.getId(), curVm.getId());
1016610166 if (dataDiskVolume == null) {
1016710167 throw new CloudRuntimeException("Creation of root volume is not queried. The virtual machine cannot be cloned!");
1016810168 }
1016910169 createdVolumes.add(dataDiskVolume);
10170-
10171- for (VolumeVO createdVol : createdVolumes) {
10172- _volumeService.attachVolumeToVM(cmd.getEntityId(), createdVol.getId(), createdVol.getDeviceId(), false);
10173- }
10170+ _volumeService.attachVolumeToVM(cmd.getEntityId(), dataDiskVolume.getId(), dataDiskVolume.getDeviceId(), false);
1017410171 } catch (CloudRuntimeException e){
1017510172 logger.warn("data disk process failed during clone, clearing the temporary resources...");
1017610173 for (VolumeVO dataDiskToClear : createdVolumes) {
@@ -10287,7 +10284,7 @@ public UserVm createCloneVM(CloneVMCmd cmd, Long rootVolumeId) throws Concurrent
1028710284 private VolumeVO cloneVolumeFromSnapToDB(final Account owner, final Boolean displayVolume, final Long zoneId, final Long diskOfferingId,
1028810285 final Storage.ProvisioningType provisioningType, final Long size, final Long minIops, final Long maxIops,
1028910286 final VolumeVO parentVolume, final String volumeName, final String uuid, final Map<String, String> details,
10290- Volume.Type volType) {
10287+ Volume.Type volType, final Long deviceId ) {
1029110288 return Transaction.execute((TransactionCallback<VolumeVO>) status -> {
1029210289 VolumeVO volume = new VolumeVO(volumeName, -1, -1, -1, -1, Long.valueOf(-1), null, null, provisioningType, 0, volType);
1029310290 volume.setPoolId(null);
@@ -10303,9 +10300,8 @@ private VolumeVO cloneVolumeFromSnapToDB(final Account owner, final Boolean disp
1030310300 volume.setInstanceId(null);
1030410301 volume.setUpdated(new Date());
1030510302 volume.setDisplayVolume(displayVolume);
10306- if (volType == Volume.Type.ROOT) {
10307- volume.setDeviceId(0L);
10308- }
10303+ volume.setDeviceId(deviceId);
10304+
1030910305 if (parentVolume != null) {
1031010306 volume.setTemplateId(parentVolume.getTemplateId());
1031110307 volume.setFormat(parentVolume.getFormat());
0 commit comments