@@ -1958,25 +1958,26 @@ protected MigrationOptions createFullCloneMigrationOptions(VolumeInfo srcVolumeI
1958
1958
* - Full clones (no backing file): Take snapshot of the VM prior disk creation
1959
1959
* Return this information
1960
1960
*/
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 );
1979
1978
}
1979
+ migrationOptions .setTimeout (StorageManager .KvmStorageOnlineMigrationWait .value ());
1980
+ destVolumeInfo .setMigrationOptions (migrationOptions );
1980
1981
}
1981
1982
1982
1983
/**
@@ -2007,6 +2008,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
2007
2008
Map <VolumeInfo , VolumeInfo > srcVolumeInfoToDestVolumeInfo = new HashMap <>();
2008
2009
2009
2010
boolean managedStorageDestination = false ;
2011
+ boolean migrateNonSharedInc = false ;
2010
2012
for (Map .Entry <VolumeInfo , DataStore > entry : volumeDataStoreMap .entrySet ()) {
2011
2013
VolumeInfo srcVolumeInfo = entry .getKey ();
2012
2014
DataStore destDataStore = entry .getValue ();
@@ -2024,15 +2026,8 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
2024
2026
continue ;
2025
2027
}
2026
2028
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 );
2036
2031
2037
2032
VolumeVO destVolume = duplicateVolumeOnAnotherStorage (srcVolume , destStoragePool );
2038
2033
VolumeInfo destVolumeInfo = _volumeDataFactory .getVolume (destVolume .getId (), destDataStore );
@@ -2044,7 +2039,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
2044
2039
// move the volume from Ready to Migrating
2045
2040
destVolumeInfo .processEvent (Event .MigrationRequested );
2046
2041
2047
- setVolumeMigrationOptions (srcVolumeInfo , destVolumeInfo , vmTO , srcHost , destStoragePool );
2042
+ setVolumeMigrationOptions (srcVolumeInfo , destVolumeInfo , vmTO , srcHost , destStoragePool , migrationType );
2048
2043
2049
2044
// create a volume on the destination storage
2050
2045
destDataStore .getDriver ().createAsync (destDataStore , destVolumeInfo , null );
@@ -2059,7 +2054,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
2059
2054
2060
2055
_volumeDao .update (destVolume .getId (), destVolume );
2061
2056
2062
- postVolumeCreationActions (srcVolumeInfo , destVolumeInfo , vmTO , srcHost );
2057
+ postVolumeCreationActions (srcVolumeInfo , destVolumeInfo );
2063
2058
2064
2059
destVolumeInfo = _volumeDataFactory .getVolume (destVolume .getId (), destDataStore );
2065
2060
@@ -2110,8 +2105,6 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
2110
2105
VMInstanceVO vm = _vmDao .findById (vmTO .getId ());
2111
2106
boolean isWindows = _guestOsCategoryDao .findById (_guestOsDao .findById (vm .getGuestOSId ()).getCategoryId ()).getName ().equalsIgnoreCase ("Windows" );
2112
2107
2113
- boolean migrateNonSharedInc = isSourceAndDestinationPoolTypeOfNfs (volumeDataStoreMap );
2114
-
2115
2108
MigrateCommand migrateCommand = new MigrateCommand (vmTO .getName (), destHost .getPrivateIpAddress (), isWindows , vmTO , true );
2116
2109
migrateCommand .setWait (StorageManager .KvmStorageOnlineMigrationWait .value ());
2117
2110
migrateCommand .setMigrateStorage (migrateStorage );
@@ -2161,6 +2154,22 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
2161
2154
}
2162
2155
}
2163
2156
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
+
2164
2173
protected String formatMigrationElementsAsJsonToDisplayOnLog (String objectName , Object object , Object from , Object to ){
2165
2174
return String .format ("{%s: \" %s\" , from: \" %s\" , to:\" %s\" }" , objectName , object , from , to );
2166
2175
}
@@ -2422,7 +2431,7 @@ protected void updateCopiedTemplateReference(VolumeInfo srcVolumeInfo, VolumeInf
2422
2431
/**
2423
2432
* Handle post destination volume creation actions depending on the migrating volume type: full clone or linked clone
2424
2433
*/
2425
- protected void postVolumeCreationActions (VolumeInfo srcVolumeInfo , VolumeInfo destVolumeInfo , VirtualMachineTO vmTO , Host srcHost ) {
2434
+ protected void postVolumeCreationActions (VolumeInfo srcVolumeInfo , VolumeInfo destVolumeInfo ) {
2426
2435
MigrationOptions migrationOptions = destVolumeInfo .getMigrationOptions ();
2427
2436
if (migrationOptions != null ) {
2428
2437
if (migrationOptions .getType () == MigrationOptions .Type .LinkedClone && migrationOptions .isCopySrcTemplate ()) {
0 commit comments