From f5cebeb71af1ce097c20fd4d3b3ba6f31e28cbfd Mon Sep 17 00:00:00 2001 From: Syed Mushtaq Ahmed Date: Fri, 1 Sep 2017 15:10:44 -0400 Subject: [PATCH] CLOUDSTACK-10061: When starting a VM, make sure it is attached to correct VAG when using managed storage (#2253) This can happen when you stop a VM in one cluster and start a VM in another cluster. When the VM starts in a new cluster, we don't add a new VAG and hence it fails to start. This PR ensures that we call grantAccess to the VM that gets started which will fix the access issue. --- .../engine/orchestration/VolumeOrchestrator.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java index 018c62e47be..c039a2f8152 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java @@ -1369,6 +1369,20 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (task.type == VolumeTaskType.NOP) { pool = (StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary); vol = task.volume; + // For a zone-wide managed storage, it is possible that the VM can be started in another + // cluster. In that case make sure that the volume in in the right access group cluster. + if (pool.isManaged()) { + long oldHostId = vm.getVirtualMachine().getLastHostId(); + long hostId = vm.getVirtualMachine().getHostId(); + if (oldHostId != hostId) { + Host oldHost = _hostDao.findById(oldHostId); + Host host = _hostDao.findById(hostId); + DataStore storagePool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); + + volService.revokeAccess(volFactory.getVolume(vol.getId()), oldHost, storagePool); + volService.grantAccess(volFactory.getVolume(vol.getId()), host, storagePool); + } + } } else if (task.type == VolumeTaskType.MIGRATE) { pool = (StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary); vol = migrateVolume(task.volume, pool);