@@ -364,16 +364,7 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) {
364
364
final TemplateObjectTO newTemplate = new TemplateObjectTO ();
365
365
newTemplate .setPath (primaryVol .getName ());
366
366
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 ()));
377
368
data = newTemplate ;
378
369
} else if (destData .getObjectType () == DataObjectType .VOLUME ) {
379
370
final VolumeObjectTO volumeObjectTO = new VolumeObjectTO ();
@@ -2990,7 +2981,7 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
2990
2981
final VolumeObjectTO srcVol = (VolumeObjectTO )srcData ;
2991
2982
final VolumeObjectTO destVol = (VolumeObjectTO )destData ;
2992
2983
final ImageFormat srcFormat = srcVol .getFormat ();
2993
- final ImageFormat destFormat = destVol .getFormat ();
2984
+ ImageFormat destFormat = destVol .getFormat ();
2994
2985
final DataStoreTO srcStore = srcData .getDataStore ();
2995
2986
final DataStoreTO destStore = destData .getDataStore ();
2996
2987
final PrimaryDataStoreTO srcPrimaryStore = (PrimaryDataStoreTO )srcStore ;
@@ -3025,14 +3016,17 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
3025
3016
volume .setFormat (PhysicalDiskFormat .valueOf (srcFormat .toString ()));
3026
3017
volume .setDispName (srcVol .getName ());
3027
3018
volume .setVmName (srcVol .getVmName ());
3028
-
3029
- String destVolumeName = null ;
3019
+ KVMPhysicalDisk newVolume ;
3020
+ String destVolumeName ;
3021
+ destPool = storagePoolMgr .getStoragePool (destPrimaryStore .getPoolType (), destPrimaryStore .getUuid ());
3030
3022
if (destPrimaryStore .isManaged ()) {
3031
3023
if (!storagePoolMgr .connectPhysicalDisk (destPrimaryStore .getPoolType (), destPrimaryStore .getUuid (), destVolumePath , destPrimaryStore .getDetails ())) {
3032
3024
logger .warn ("Failed to connect dest volume {}, in storage pool {}" , destVol , destPrimaryStore );
3033
3025
}
3034
3026
destVolumeName = derivePath (destPrimaryStore , destData , destPrimaryStore .getDetails ());
3035
3027
} else {
3028
+ PhysicalDiskFormat destPoolDefaultFormat = destPool .getDefaultFormat ();
3029
+ destFormat = getFormat (destPoolDefaultFormat );
3036
3030
final String volumeName = UUID .randomUUID ().toString ();
3037
3031
destVolumeName = volumeName + "." + destFormat .getFileExtension ();
3038
3032
@@ -3042,16 +3036,15 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
3042
3036
}
3043
3037
}
3044
3038
3045
- destPool = storagePoolMgr .getStoragePool (destPrimaryStore .getPoolType (), destPrimaryStore .getUuid ());
3046
3039
try {
3047
3040
Volume .Type volumeType = srcVol .getVolumeType ();
3048
3041
3049
3042
resource .createOrUpdateLogFileForCommand (cmd , Command .State .PROCESSING_IN_BACKEND );
3050
3043
if (srcVol .getPassphrase () != null && (Volume .Type .ROOT .equals (volumeType ) || Volume .Type .DATADISK .equals (volumeType ))) {
3051
3044
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 ());
3053
3046
} else {
3054
- storagePoolMgr .copyPhysicalDisk (volume , destVolumeName , destPool , cmd .getWaitInMillSeconds ());
3047
+ newVolume = storagePoolMgr .copyPhysicalDisk (volume , destVolumeName , destPool , cmd .getWaitInMillSeconds ());
3055
3048
}
3056
3049
resource .createOrUpdateLogFileForCommand (cmd , Command .State .COMPLETED );
3057
3050
} 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) {
3076
3069
path = destVolumePath + File .separator + destVolumeName ;
3077
3070
}
3078
3071
newVol .setPath (path );
3079
- newVol .setFormat (destFormat );
3072
+ ImageFormat newVolumeFormat = getFormat (newVolume .getFormat ());
3073
+ newVol .setFormat (newVolumeFormat );
3080
3074
newVol .setEncryptFormat (destVol .getEncryptFormat ());
3081
3075
return new CopyCmdAnswer (newVol );
3082
3076
} catch (final CloudRuntimeException e ) {
@@ -3088,6 +3082,26 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
3088
3082
}
3089
3083
}
3090
3084
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
+
3091
3105
/**
3092
3106
* True if location exists
3093
3107
*/
0 commit comments