Skip to content

Commit 404e264

Browse files
CloudStack fails to migrate VM with volume when there are datadisks attatched (#5410)
* Check if should map volume in createStoragePoolMappingsForVolumes * Invert conditional at internalCanHandle
1 parent 798d7be commit 404e264

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,8 +2947,8 @@ protected void executeManagedStorageChecksWhenTargetStoragePoolProvided(StorageP
29472947
* For each one of the volumes we will map it to a storage pool that is available via the target host.
29482948
* An exception is thrown if we cannot find a storage pool that is accessible in the target host to migrate the volume to.
29492949
*/
2950-
protected void createStoragePoolMappingsForVolumes(VirtualMachineProfile profile, DataCenterDeployment plan, Map<Volume, StoragePool> volumeToPoolObjectMap, List<Volume> allVolumes) {
2951-
for (Volume volume : allVolumes) {
2950+
protected void createStoragePoolMappingsForVolumes(VirtualMachineProfile profile, DataCenterDeployment plan, Map<Volume, StoragePool> volumeToPoolObjectMap, List<Volume> volumesNotMapped) {
2951+
for (Volume volume : volumesNotMapped) {
29522952
StoragePoolVO currentPool = _storagePoolDao.findById(volume.getPoolId());
29532953

29542954
Host targetHost = null;
@@ -2958,12 +2958,25 @@ protected void createStoragePoolMappingsForVolumes(VirtualMachineProfile profile
29582958
executeManagedStorageChecksWhenTargetStoragePoolNotProvided(targetHost, currentPool, volume);
29592959
if (ScopeType.HOST.equals(currentPool.getScope()) || isStorageCrossClusterMigration(plan.getClusterId(), currentPool)) {
29602960
createVolumeToStoragePoolMappingIfPossible(profile, plan, volumeToPoolObjectMap, volume, currentPool);
2961-
} else {
2961+
} else if (shouldMapVolume(profile, volume, currentPool)){
29622962
volumeToPoolObjectMap.put(volume, currentPool);
29632963
}
29642964
}
29652965
}
29662966

2967+
/**
2968+
* Returns true if it should map the volume for a storage pool to migrate.
2969+
* <br><br>
2970+
* Some context: VMware migration workflow requires all volumes to be mapped (even if volume stays on its current pool);
2971+
* however, this is not necessary/desirable for the KVM flow.
2972+
*/
2973+
protected boolean shouldMapVolume(VirtualMachineProfile profile, Volume volume, StoragePoolVO currentPool) {
2974+
boolean isManaged = currentPool.isManaged();
2975+
boolean isNotKvm = HypervisorType.KVM != profile.getHypervisorType();
2976+
boolean isNotDatadisk = Type.DATADISK != volume.getVolumeType();
2977+
return isNotKvm || isNotDatadisk || isManaged;
2978+
}
2979+
29672980
/**
29682981
* Executes the managed storage checks for the volumes that the user has not entered a mapping of <volume, storage pool>. The following checks are performed.
29692982
* <ul>

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,19 @@ public class KvmNonManagedStorageDataMotionStrategy extends StorageSystemDataMot
8282
*/
8383
@Override
8484
protected StrategyPriority internalCanHandle(Map<VolumeInfo, DataStore> volumeMap, Host srcHost, Host destHost) {
85-
if (super.internalCanHandle(volumeMap, srcHost, destHost) == StrategyPriority.CANT_HANDLE) {
86-
if (canHandleKVMNonManagedLiveNFSStorageMigration(volumeMap, srcHost, destHost) == StrategyPriority.CANT_HANDLE) {
87-
Set<VolumeInfo> volumeInfoSet = volumeMap.keySet();
88-
89-
for (VolumeInfo volumeInfo : volumeInfoSet) {
90-
StoragePoolVO storagePoolVO = _storagePoolDao.findById(volumeInfo.getPoolId());
85+
if (super.internalCanHandle(volumeMap, srcHost, destHost) != StrategyPriority.CANT_HANDLE
86+
|| canHandleKVMNonManagedLiveNFSStorageMigration(volumeMap, srcHost, destHost) != StrategyPriority.CANT_HANDLE) {
87+
return StrategyPriority.CANT_HANDLE;
88+
}
9189

92-
if (!supportStoragePoolType(storagePoolVO.getPoolType())) {
93-
return StrategyPriority.CANT_HANDLE;
94-
}
95-
}
90+
Set<VolumeInfo> volumeInfoSet = volumeMap.keySet();
91+
for (VolumeInfo volumeInfo : volumeInfoSet) {
92+
StoragePoolVO storagePoolVO = _storagePoolDao.findById(volumeInfo.getPoolId());
93+
if (!supportStoragePoolType(storagePoolVO.getPoolType())) {
94+
return StrategyPriority.CANT_HANDLE;
9695
}
97-
return StrategyPriority.HYPERVISOR;
9896
}
99-
return StrategyPriority.CANT_HANDLE;
97+
return StrategyPriority.HYPERVISOR;
10098
}
10199

102100
/**

0 commit comments

Comments
 (0)