mike-tutkowski closed pull request #2501: Only perform certain actions with 
managed storage if the VM is s…
URL: https://github.com/apache/cloudstack/pull/2501
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
 
b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
index f02fdc495f9..ce4191f58f6 100644
--- 
a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
+++ 
b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
@@ -1379,31 +1379,29 @@ public void prepare(VirtualMachineProfile vm, 
DeployDestination dest) throws Sto
         StoragePool pool;
         for (VolumeTask task : tasks) {
             if (task.type == VolumeTaskType.NOP) {
-                pool = 
(StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), 
DataStoreRole.Primary);
-
-                if (task.pool != null && task.pool.isManaged()) {
-                    long hostId = vm.getVirtualMachine().getHostId();
-                    Host host = _hostDao.findById(hostId);
-
-                    
volService.grantAccess(volFactory.getVolume(task.volume.getId()), host, 
(DataStore)pool);
-                }
-
                 vol = task.volume;
 
-                // For a zone-wide managed storage, it is possible that the VM 
can be started in another
+                pool = 
(StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), 
DataStoreRole.Primary);
+
+                // For zone-wide managed storage, it is possible that the VM 
can be started in another
                 // cluster. In that case, make sure that the volume is in the 
right access group.
                 if (pool.isManaged()) {
-                    long oldHostId = vm.getVirtualMachine().getLastHostId();
-                    long hostId = vm.getVirtualMachine().getHostId();
+                    Host lastHost = 
_hostDao.findById(vm.getVirtualMachine().getLastHostId());
+                    Host host = 
_hostDao.findById(vm.getVirtualMachine().getHostId());
 
-                    if (oldHostId != hostId) {
-                        Host oldHost = _hostDao.findById(oldHostId);
-                        Host host = _hostDao.findById(hostId);
-                        DataStore storagePool = 
dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
+                    long lastClusterId = lastHost == null || 
lastHost.getClusterId() == null ? -1 : lastHost.getClusterId();
+                    long clusterId = host == null || host.getClusterId() == 
null ? -1 : host.getClusterId();
 
-                        storageMgr.removeStoragePoolFromCluster(oldHostId, 
vol.get_iScsiName(), pool);
+                    if (lastClusterId != clusterId) {
+                        if (lastHost != null) {
+                            
storageMgr.removeStoragePoolFromCluster(lastHost.getId(), vol.get_iScsiName(), 
pool);
+
+                            DataStore storagePool = 
dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
+
+                            
volService.revokeAccess(volFactory.getVolume(vol.getId()), lastHost, 
storagePool);
+                        }
 
-                        
volService.revokeAccess(volFactory.getVolume(vol.getId()), oldHost, 
storagePool);
+                        
volService.grantAccess(volFactory.getVolume(vol.getId()), host, 
(DataStore)pool);
                     }
                 }
             } else if (task.type == VolumeTaskType.MIGRATE) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to