Skip to content

Commit bdb8107

Browse files
author
Sateesh Chodapuneedi
committed
CLOUDSTACK-4375 VM Migration is failing from one cluster to another cluster.
listHostsForMigrationOfVM is being called when user attempts to move a VM to other host. This is trying to find list of suitable storage pools that are attached to each of the suitable hosts for the VM. Currently the selection of target storage pools for each volume of the VM is left to storage pool allocators. But user might want to leave his volume unmoved/intact If it is on a zone wide storage pool. This would be more efficient while migrating VM as storage live migration is not required and VM continues to use volumes on same storage pool as before. Hence idea is to set same storage pool as target pool for each of the volume if the volume is already on zone wide storage pool. A comparison of source pool of volume against target pool of volume yields the information if storage migration is required for the VM to move to target host or not. Based on that information apropriate API migrateVM or migrateVmWithVolume could be decided. Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>
1 parent dabc071 commit bdb8107

1 file changed

Lines changed: 40 additions & 29 deletions

File tree

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.security.SecureRandom;
2424
import java.util.ArrayList;
2525
import java.util.Calendar;
26-
import java.util.Collection;
2726
import java.util.Comparator;
2827
import java.util.Date;
2928
import java.util.HashMap;
@@ -517,6 +516,7 @@
517516
import com.cloud.storage.GuestOSCategoryVO;
518517
import com.cloud.storage.GuestOSVO;
519518
import com.cloud.storage.GuestOsCategory;
519+
import com.cloud.storage.ScopeType;
520520
import com.cloud.storage.Storage.ImageFormat;
521521
import com.cloud.storage.Storage.TemplateType;
522522
import com.cloud.storage.StorageManager;
@@ -1109,7 +1109,7 @@ public Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd) {
11091109
List<HostVO> allHosts = null;
11101110
Map<Host, Boolean> requiresStorageMotion = new HashMap<Host, Boolean>();
11111111
DataCenterDeployment plan = null;
1112-
boolean allZoneWideStoragePools = false;
1112+
boolean migrationRequired = false;
11131113
if (canMigrateWithStorage) {
11141114
allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, srcHost.getDataCenterId(), null,
11151115
null, null, null, null, null, srcHost.getHypervisorType(), srcHost.getHypervisorVersion());
@@ -1124,9 +1124,10 @@ public Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd) {
11241124
iterator.remove();
11251125
} else {
11261126
if (srcHost.getHypervisorType() == HypervisorType.VMware || srcHost.getHypervisorType() == HypervisorType.KVM) {
1127-
allZoneWideStoragePools = checkIfAllZoneWideStoragePools(volumePools);
1127+
// Check if each volume required migrating to other pool or not.
1128+
migrationRequired = checkIfMigrationRequired(volumePools);
11281129
}
1129-
if ((!host.getClusterId().equals(srcHost.getClusterId()) || usesLocal) && !allZoneWideStoragePools) {
1130+
if ((!host.getClusterId().equals(srcHost.getClusterId()) || usesLocal) && migrationRequired) {
11301131
requiresStorageMotion.put(host, true);
11311132
}
11321133
}
@@ -1188,20 +1189,20 @@ public Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd) {
11881189
suitableHosts, requiresStorageMotion);
11891190
}
11901191

1191-
private boolean checkIfAllZoneWideStoragePools(Map<Volume, List<StoragePool>> volumePools) {
1192-
boolean allZoneWideStoragePools = true;
1193-
Collection<List<StoragePool>> pools = volumePools.values();
1194-
List<StoragePool> aggregatePoolList = new ArrayList<StoragePool>();
1195-
for (Iterator<List<StoragePool>> volumePoolsIter = pools.iterator(); volumePoolsIter.hasNext();) {
1196-
aggregatePoolList.addAll(volumePoolsIter.next());
1197-
}
1198-
for (StoragePool pool : aggregatePoolList) {
1199-
if (null != pool.getClusterId()) {
1200-
allZoneWideStoragePools = false;
1201-
break;
1192+
private boolean checkIfMigrationRequired(Map<Volume, List<StoragePool>> volumePools) {
1193+
boolean migratingToOtherStoragePool = false;
1194+
Iterator<Volume> volumesIt = volumePools.keySet().iterator();
1195+
while(volumesIt.hasNext()) {
1196+
Volume vol = volumesIt.next();
1197+
List<StoragePool> poolList = volumePools.get(vol);
1198+
for (StoragePool pool : poolList) {
1199+
// See if any volume requies migration to another storage pool
1200+
if (pool.getId() != vol.getPoolId()) {
1201+
migratingToOtherStoragePool = true;
1202+
}
12021203
}
12031204
}
1204-
return allZoneWideStoragePools;
1205+
return migratingToOtherStoragePool;
12051206
}
12061207

12071208
private Map<Volume, List<StoragePool>> findSuitablePoolsForVolumes(VirtualMachineProfile<VMInstanceVO> vmProfile,
@@ -1211,20 +1212,30 @@ private Map<Volume, List<StoragePool>> findSuitablePoolsForVolumes(VirtualMachin
12111212

12121213
// For each volume find list of suitable storage pools by calling the allocators
12131214
for (VolumeVO volume : volumes) {
1214-
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
1215-
DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
1216-
DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(),
1217-
host.getClusterId(), host.getId(), null, null);
1218-
ExcludeList avoid = new ExcludeList();
1219-
12201215
boolean foundPools = false;
1221-
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
1222-
List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid,
1223-
StoragePoolAllocator.RETURN_UPTO_ALL);
1224-
if (poolList != null && !poolList.isEmpty()) {
1225-
suitableVolumeStoragePools.put(volume, poolList);
1226-
foundPools = true;
1227-
break;
1216+
// If volume is already on zone wide storage pool, do not search further to allocate target storage pool for that volume.
1217+
List<StoragePool> poolList = new ArrayList<StoragePool>();
1218+
Long volPoolId = volume.getPoolId();
1219+
StoragePoolVO volumePool = _poolDao.findById(volPoolId);
1220+
if (volumePool.getScope() == ScopeType.ZONE) {
1221+
poolList.add(volumePool);
1222+
suitableVolumeStoragePools.put(volume, poolList);
1223+
foundPools = true;
1224+
} else {
1225+
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
1226+
DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
1227+
DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(),
1228+
host.getClusterId(), host.getId(), null, null);
1229+
ExcludeList avoid = new ExcludeList();
1230+
1231+
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
1232+
poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid,
1233+
StoragePoolAllocator.RETURN_UPTO_ALL);
1234+
if (poolList != null && !poolList.isEmpty()) {
1235+
suitableVolumeStoragePools.put(volume, poolList);
1236+
foundPools = true;
1237+
break;
1238+
}
12281239
}
12291240
}
12301241

0 commit comments

Comments
 (0)