@@ -364,16 +364,7 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) {
364364 final TemplateObjectTO newTemplate = new TemplateObjectTO ();
365365 newTemplate .setPath (primaryVol .getName ());
366366 newTemplate .setSize (primaryVol .getSize ());
367-
368- if (List .of (
369- StoragePoolType .RBD ,
370- StoragePoolType .PowerFlex ,
371- StoragePoolType .Linstor ,
372- StoragePoolType .FiberChannel ).contains (primaryPool .getType ())) {
373- newTemplate .setFormat (ImageFormat .RAW );
374- } else {
375- newTemplate .setFormat (ImageFormat .QCOW2 );
376- }
367+ newTemplate .setFormat (getFormat (primaryPool .getType ()));
377368 data = newTemplate ;
378369 } else if (destData .getObjectType () == DataObjectType .VOLUME ) {
379370 final VolumeObjectTO volumeObjectTO = new VolumeObjectTO ();
@@ -2990,7 +2981,7 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
29902981 final VolumeObjectTO srcVol = (VolumeObjectTO )srcData ;
29912982 final VolumeObjectTO destVol = (VolumeObjectTO )destData ;
29922983 final ImageFormat srcFormat = srcVol .getFormat ();
2993- final ImageFormat destFormat = destVol .getFormat ();
2984+ ImageFormat destFormat = destVol .getFormat ();
29942985 final DataStoreTO srcStore = srcData .getDataStore ();
29952986 final DataStoreTO destStore = destData .getDataStore ();
29962987 final PrimaryDataStoreTO srcPrimaryStore = (PrimaryDataStoreTO )srcStore ;
@@ -3025,14 +3016,17 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
30253016 volume .setFormat (PhysicalDiskFormat .valueOf (srcFormat .toString ()));
30263017 volume .setDispName (srcVol .getName ());
30273018 volume .setVmName (srcVol .getVmName ());
3028-
3029- String destVolumeName = null ;
3019+ KVMPhysicalDisk newVolume ;
3020+ String destVolumeName ;
3021+ destPool = storagePoolMgr .getStoragePool (destPrimaryStore .getPoolType (), destPrimaryStore .getUuid ());
30303022 if (destPrimaryStore .isManaged ()) {
30313023 if (!storagePoolMgr .connectPhysicalDisk (destPrimaryStore .getPoolType (), destPrimaryStore .getUuid (), destVolumePath , destPrimaryStore .getDetails ())) {
30323024 logger .warn ("Failed to connect dest volume {}, in storage pool {}" , destVol , destPrimaryStore );
30333025 }
30343026 destVolumeName = derivePath (destPrimaryStore , destData , destPrimaryStore .getDetails ());
30353027 } else {
3028+ PhysicalDiskFormat destPoolDefaultFormat = destPool .getDefaultFormat ();
3029+ destFormat = getFormat (destPoolDefaultFormat );
30363030 final String volumeName = UUID .randomUUID ().toString ();
30373031 destVolumeName = volumeName + "." + destFormat .getFileExtension ();
30383032
@@ -3042,16 +3036,15 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
30423036 }
30433037 }
30443038
3045- destPool = storagePoolMgr .getStoragePool (destPrimaryStore .getPoolType (), destPrimaryStore .getUuid ());
30463039 try {
30473040 Volume .Type volumeType = srcVol .getVolumeType ();
30483041
30493042 resource .createOrUpdateLogFileForCommand (cmd , Command .State .PROCESSING_IN_BACKEND );
30503043 if (srcVol .getPassphrase () != null && (Volume .Type .ROOT .equals (volumeType ) || Volume .Type .DATADISK .equals (volumeType ))) {
30513044 volume .setQemuEncryptFormat (QemuObject .EncryptFormat .LUKS );
3052- storagePoolMgr .copyPhysicalDisk (volume , destVolumeName , destPool , cmd .getWaitInMillSeconds (), srcVol .getPassphrase (), destVol .getPassphrase (), srcVol .getProvisioningType ());
3045+ newVolume = storagePoolMgr .copyPhysicalDisk (volume , destVolumeName , destPool , cmd .getWaitInMillSeconds (), srcVol .getPassphrase (), destVol .getPassphrase (), srcVol .getProvisioningType ());
30533046 } else {
3054- storagePoolMgr .copyPhysicalDisk (volume , destVolumeName , destPool , cmd .getWaitInMillSeconds ());
3047+ newVolume = storagePoolMgr .copyPhysicalDisk (volume , destVolumeName , destPool , cmd .getWaitInMillSeconds ());
30553048 }
30563049 resource .createOrUpdateLogFileForCommand (cmd , Command .State .COMPLETED );
30573050 } catch (Exception e ) { // Any exceptions while copying the disk, should send failed answer with the error message
@@ -3076,7 +3069,8 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
30763069 path = destVolumePath + File .separator + destVolumeName ;
30773070 }
30783071 newVol .setPath (path );
3079- newVol .setFormat (destFormat );
3072+ ImageFormat newVolumeFormat = getFormat (newVolume .getFormat ());
3073+ newVol .setFormat (newVolumeFormat );
30803074 newVol .setEncryptFormat (destVol .getEncryptFormat ());
30813075 return new CopyCmdAnswer (newVol );
30823076 } catch (final CloudRuntimeException e ) {
@@ -3088,6 +3082,26 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
30883082 }
30893083 }
30903084
3085+ private Storage .ImageFormat getFormat (PhysicalDiskFormat format ) {
3086+ if (format == null ) {
3087+ return null ;
3088+ }
3089+
3090+ return ImageFormat .valueOf (format .toString ().toUpperCase ());
3091+ }
3092+
3093+ private Storage .ImageFormat getFormat (StoragePoolType poolType ) {
3094+ if (List .of (
3095+ StoragePoolType .RBD ,
3096+ StoragePoolType .PowerFlex ,
3097+ StoragePoolType .Linstor ,
3098+ StoragePoolType .FiberChannel ).contains (poolType )) {
3099+ return ImageFormat .RAW ;
3100+ } else {
3101+ return ImageFormat .QCOW2 ;
3102+ }
3103+ }
3104+
30913105 /**
30923106 * True if location exists
30933107 */
0 commit comments