@@ -1958,25 +1958,26 @@ protected MigrationOptions createFullCloneMigrationOptions(VolumeInfo srcVolumeI
19581958 * - Full clones (no backing file): Take snapshot of the VM prior disk creation
19591959 * Return this information
19601960 */
1961- protected void setVolumeMigrationOptions (VolumeInfo srcVolumeInfo , VolumeInfo destVolumeInfo ,
1962- VirtualMachineTO vmTO , Host srcHost , StoragePoolVO destStoragePool ) {
1963- if (!destStoragePool .isManaged ()) {
1964- String srcVolumeBackingFile = getVolumeBackingFile (srcVolumeInfo );
1965-
1966- String srcPoolUuid = srcVolumeInfo .getDataStore ().getUuid ();
1967- StoragePoolVO srcPool = _storagePoolDao .findById (srcVolumeInfo .getPoolId ());
1968- Storage .StoragePoolType srcPoolType = srcPool .getPoolType ();
1969-
1970- MigrationOptions migrationOptions ;
1971- if (StringUtils .isNotBlank (srcVolumeBackingFile )) {
1972- migrationOptions = createLinkedCloneMigrationOptions (srcVolumeInfo , destVolumeInfo ,
1973- srcVolumeBackingFile , srcPoolUuid , srcPoolType );
1974- } else {
1975- migrationOptions = createFullCloneMigrationOptions (srcVolumeInfo , vmTO , srcHost , srcPoolUuid , srcPoolType );
1976- }
1977- migrationOptions .setTimeout (StorageManager .KvmStorageOnlineMigrationWait .value ());
1978- destVolumeInfo .setMigrationOptions (migrationOptions );
1961+ protected void setVolumeMigrationOptions (VolumeInfo srcVolumeInfo , VolumeInfo destVolumeInfo , VirtualMachineTO vmTO , Host srcHost , StoragePoolVO destStoragePool ,
1962+ MigrationOptions .Type migrationType ) {
1963+ if (destStoragePool .isManaged ()) {
1964+ return ;
1965+ }
1966+
1967+ String srcVolumeBackingFile = getVolumeBackingFile (srcVolumeInfo );
1968+
1969+ String srcPoolUuid = srcVolumeInfo .getDataStore ().getUuid ();
1970+ StoragePoolVO srcPool = _storagePoolDao .findById (srcVolumeInfo .getPoolId ());
1971+ Storage .StoragePoolType srcPoolType = srcPool .getPoolType ();
1972+
1973+ MigrationOptions migrationOptions ;
1974+ if (MigrationOptions .Type .LinkedClone .equals (migrationType )) {
1975+ migrationOptions = createLinkedCloneMigrationOptions (srcVolumeInfo , destVolumeInfo , srcVolumeBackingFile , srcPoolUuid , srcPoolType );
1976+ } else {
1977+ migrationOptions = createFullCloneMigrationOptions (srcVolumeInfo , vmTO , srcHost , srcPoolUuid , srcPoolType );
19791978 }
1979+ migrationOptions .setTimeout (StorageManager .KvmStorageOnlineMigrationWait .value ());
1980+ destVolumeInfo .setMigrationOptions (migrationOptions );
19801981 }
19811982
19821983 /**
@@ -2007,6 +2008,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20072008 Map <VolumeInfo , VolumeInfo > srcVolumeInfoToDestVolumeInfo = new HashMap <>();
20082009
20092010 boolean managedStorageDestination = false ;
2011+ boolean migrateNonSharedInc = false ;
20102012 for (Map .Entry <VolumeInfo , DataStore > entry : volumeDataStoreMap .entrySet ()) {
20112013 VolumeInfo srcVolumeInfo = entry .getKey ();
20122014 DataStore destDataStore = entry .getValue ();
@@ -2024,15 +2026,8 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20242026 continue ;
20252027 }
20262028
2027- VMTemplateVO vmTemplate = _vmTemplateDao .findById (vmInstance .getTemplateId ());
2028- if (srcVolumeInfo .getTemplateId () != null &&
2029- Objects .nonNull (vmTemplate ) &&
2030- !Arrays .asList (KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME , VM_IMPORT_DEFAULT_TEMPLATE_NAME ).contains (vmTemplate .getName ())) {
2031- logger .debug (String .format ("Copying template [%s] of volume [%s] from source storage pool [%s] to target storage pool [%s]." , srcVolumeInfo .getTemplateId (), srcVolumeInfo .getId (), sourceStoragePool .getId (), destStoragePool .getId ()));
2032- copyTemplateToTargetFilesystemStorageIfNeeded (srcVolumeInfo , sourceStoragePool , destDataStore , destStoragePool , destHost );
2033- } else {
2034- logger .debug (String .format ("Skipping copy template from source storage pool [%s] to target storage pool [%s] before migration due to volume [%s] does not have a template." , sourceStoragePool .getId (), destStoragePool .getId (), srcVolumeInfo .getId ()));
2035- }
2029+ MigrationOptions .Type migrationType = decideMigrationTypeAndCopyTemplateIfNeeded (destHost , vmInstance , srcVolumeInfo , sourceStoragePool , destStoragePool , destDataStore );
2030+ migrateNonSharedInc = migrateNonSharedInc || MigrationOptions .Type .LinkedClone .equals (migrationType );
20362031
20372032 VolumeVO destVolume = duplicateVolumeOnAnotherStorage (srcVolume , destStoragePool );
20382033 VolumeInfo destVolumeInfo = _volumeDataFactory .getVolume (destVolume .getId (), destDataStore );
@@ -2044,7 +2039,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20442039 // move the volume from Ready to Migrating
20452040 destVolumeInfo .processEvent (Event .MigrationRequested );
20462041
2047- setVolumeMigrationOptions (srcVolumeInfo , destVolumeInfo , vmTO , srcHost , destStoragePool );
2042+ setVolumeMigrationOptions (srcVolumeInfo , destVolumeInfo , vmTO , srcHost , destStoragePool , migrationType );
20482043
20492044 // create a volume on the destination storage
20502045 destDataStore .getDriver ().createAsync (destDataStore , destVolumeInfo , null );
@@ -2059,7 +2054,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20592054
20602055 _volumeDao .update (destVolume .getId (), destVolume );
20612056
2062- postVolumeCreationActions (srcVolumeInfo , destVolumeInfo , vmTO , srcHost );
2057+ postVolumeCreationActions (srcVolumeInfo , destVolumeInfo );
20632058
20642059 destVolumeInfo = _volumeDataFactory .getVolume (destVolume .getId (), destDataStore );
20652060
@@ -2110,8 +2105,6 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
21102105 VMInstanceVO vm = _vmDao .findById (vmTO .getId ());
21112106 boolean isWindows = _guestOsCategoryDao .findById (_guestOsDao .findById (vm .getGuestOSId ()).getCategoryId ()).getName ().equalsIgnoreCase ("Windows" );
21122107
2113- boolean migrateNonSharedInc = isSourceAndDestinationPoolTypeOfNfs (volumeDataStoreMap );
2114-
21152108 MigrateCommand migrateCommand = new MigrateCommand (vmTO .getName (), destHost .getPrivateIpAddress (), isWindows , vmTO , true );
21162109 migrateCommand .setWait (StorageManager .KvmStorageOnlineMigrationWait .value ());
21172110 migrateCommand .setMigrateStorage (migrateStorage );
@@ -2161,6 +2154,22 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
21612154 }
21622155 }
21632156
2157+ private MigrationOptions .Type decideMigrationTypeAndCopyTemplateIfNeeded (Host destHost , VMInstanceVO vmInstance , VolumeInfo srcVolumeInfo , StoragePoolVO sourceStoragePool , StoragePoolVO destStoragePool , DataStore destDataStore ) {
2158+ VMTemplateVO vmTemplate = _vmTemplateDao .findById (vmInstance .getTemplateId ());
2159+ String srcVolumeBackingFile = getVolumeBackingFile (srcVolumeInfo );
2160+ if (StringUtils .isNotBlank (srcVolumeBackingFile ) && supportStoragePoolType (destStoragePool .getPoolType (), StoragePoolType .Filesystem ) &&
2161+ srcVolumeInfo .getTemplateId () != null &&
2162+ Objects .nonNull (vmTemplate ) &&
2163+ !Arrays .asList (KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME , VM_IMPORT_DEFAULT_TEMPLATE_NAME ).contains (vmTemplate .getName ())) {
2164+ logger .debug (String .format ("Copying template [%s] of volume [%s] from source storage pool [%s] to target storage pool [%s]." , srcVolumeInfo .getTemplateId (), srcVolumeInfo .getId (), sourceStoragePool .getId (), destStoragePool .getId ()));
2165+ copyTemplateToTargetFilesystemStorageIfNeeded (srcVolumeInfo , sourceStoragePool , destDataStore , destStoragePool , destHost );
2166+ return MigrationOptions .Type .LinkedClone ;
2167+ }
2168+ logger .debug (String .format ("Skipping copy template from source storage pool [%s] to target storage pool [%s] before migration due to volume [%s] does not have a " +
2169+ "template or we are doing full clone migration." , sourceStoragePool .getId (), destStoragePool .getId (), srcVolumeInfo .getId ()));
2170+ return MigrationOptions .Type .FullClone ;
2171+ }
2172+
21642173 protected String formatMigrationElementsAsJsonToDisplayOnLog (String objectName , Object object , Object from , Object to ){
21652174 return String .format ("{%s: \" %s\" , from: \" %s\" , to:\" %s\" }" , objectName , object , from , to );
21662175 }
@@ -2422,7 +2431,7 @@ protected void updateCopiedTemplateReference(VolumeInfo srcVolumeInfo, VolumeInf
24222431 /**
24232432 * Handle post destination volume creation actions depending on the migrating volume type: full clone or linked clone
24242433 */
2425- protected void postVolumeCreationActions (VolumeInfo srcVolumeInfo , VolumeInfo destVolumeInfo , VirtualMachineTO vmTO , Host srcHost ) {
2434+ protected void postVolumeCreationActions (VolumeInfo srcVolumeInfo , VolumeInfo destVolumeInfo ) {
24262435 MigrationOptions migrationOptions = destVolumeInfo .getMigrationOptions ();
24272436 if (migrationOptions != null ) {
24282437 if (migrationOptions .getType () == MigrationOptions .Type .LinkedClone && migrationOptions .isCopySrcTemplate ()) {
0 commit comments