Skip to content

Commit e471a46

Browse files
Mike Tutkowskiyadvr
authored andcommitted
managed-storage: handle VM start in a new cluster on different host (#2656)
Example: A VM that uses managed storage is stopped. The VM is then started on a different host in the same cluster. The Start operation fails. To get around this issue, you must either start the VM up on the same host or on a host in a different cluster. The reason is due to a slightly erroneous check in VolumeOrchestrator.prepare. To solve this issue, we should be checking if the cluster ID changes, not if the host ID changes.
1 parent acc5fdc commit e471a46

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,30 +1344,29 @@ public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws Sto
13441344
StoragePool pool;
13451345
for (VolumeTask task : tasks) {
13461346
if (task.type == VolumeTaskType.NOP) {
1347-
pool = (StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
1348-
1349-
if (task.pool != null && task.pool.isManaged()) {
1350-
long hostId = vm.getVirtualMachine().getHostId();
1351-
Host host = _hostDao.findById(hostId);
1352-
1353-
volService.grantAccess(volFactory.getVolume(task.volume.getId()), host, (DataStore)pool);
1354-
}
1355-
13561347
vol = task.volume;
13571348

1358-
// For a zone-wide managed storage, it is possible that the VM can be started in another
1349+
pool = (StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
1350+
1351+
// For zone-wide managed storage, it is possible that the VM can be started in another
13591352
// cluster. In that case, make sure that the volume is in the right access group.
13601353
if (pool.isManaged()) {
1361-
long oldHostId = vm.getVirtualMachine().getLastHostId();
1362-
long hostId = vm.getVirtualMachine().getHostId();
1354+
Host lastHost = _hostDao.findById(vm.getVirtualMachine().getLastHostId());
1355+
Host host = _hostDao.findById(vm.getVirtualMachine().getHostId());
13631356

1364-
if (oldHostId != hostId) {
1365-
Host oldHost = _hostDao.findById(oldHostId);
1366-
DataStore storagePool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
1357+
long lastClusterId = lastHost == null || lastHost.getClusterId() == null ? -1 : lastHost.getClusterId();
1358+
long clusterId = host == null || host.getClusterId() == null ? -1 : host.getClusterId();
13671359

1368-
storageMgr.removeStoragePoolFromCluster(oldHostId, vol.get_iScsiName(), pool);
1360+
if (lastClusterId != clusterId) {
1361+
if (lastHost != null) {
1362+
storageMgr.removeStoragePoolFromCluster(lastHost.getId(), vol.get_iScsiName(), pool);
1363+
1364+
DataStore storagePool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
1365+
1366+
volService.revokeAccess(volFactory.getVolume(vol.getId()), lastHost, storagePool);
1367+
}
13691368

1370-
volService.revokeAccess(volFactory.getVolume(vol.getId()), oldHost, storagePool);
1369+
volService.grantAccess(volFactory.getVolume(vol.getId()), host, (DataStore)pool);
13711370
}
13721371
}
13731372
} else if (task.type == VolumeTaskType.MIGRATE) {

0 commit comments

Comments
 (0)