From 34ee6f90bb5f69b619116d2c61a3f61fbdbca536 Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Wed, 28 Aug 2013 18:37:45 -0700 Subject: [PATCH] CLOUDSTACK-4458: Volume attach/detach command needs to sent to hypervisor resource even when target VM is in Stopped state (cherry picked from commit 995e193be2a1aad8ffe0eeb03357e23fb5c63769) Signed-off-by: animesh --- .../storage/snapshot/SnapshotServiceImpl.java | 1 - .../src/com/cloud/hypervisor/guru/VMwareGuru.java | 2 +- .../storage/resource/VmwareStorageProcessor.java | 2 +- server/src/com/cloud/storage/VolumeManagerImpl.java | 12 +++++++++++- .../cloud/hypervisor/vmware/mo/VirtualMachineMO.java | 3 +-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java index e53bf9c0529..00d96316e24 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java @@ -247,7 +247,6 @@ public class SnapshotServiceImpl implements SnapshotService { AsyncCallFuture future = new AsyncCallFuture(); SnapshotResult result = new SnapshotResult(snapshot, null); try { - snapObj.processEvent(Snapshot.Event.BackupToSecondary); DataStore imageStore = this.findSnapshotImageStore(snapshot); diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java index c8e82ab13b0..73cc8e3e5a2 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java @@ -351,7 +351,7 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru { } } } - + if(!needDelegation) { return new Pair(Boolean.FALSE, new Long(hostId)); } diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java index 20c26fbc441..14fca3afd8d 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -969,7 +969,7 @@ public class VmwareStorageProcessor implements StorageProcessor { throw new Exception("unable to prepare snapshot backup directory"); } } - } + } VirtualMachineMO clonedVm = null; try { diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index 35fe72a43a3..85a19ca63b3 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -2026,6 +2026,16 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { String errorMsg = "Failed to detach volume: " + volume.getName() + " from VM: " + vm.getHostName(); boolean sendCommand = (vm.getState() == State.Running); + Long hostId = vm.getHostId(); + if (hostId == null) { + hostId = vm.getLastHostId(); + HostVO host = _hostDao.findById(hostId); + if (host != null + && host.getHypervisorType() == HypervisorType.VMware) { + sendCommand = true; + } + } + Answer answer = null; if (sendCommand) { @@ -2044,7 +2054,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { cmd.set_iScsiName(volume.get_iScsiName()); try { - answer = _agentMgr.send(vm.getHostId(), cmd); + answer = _agentMgr.send(hostId, cmd); } catch (Exception e) { throw new CloudRuntimeException(errorMsg + " due to: " + e.getMessage()); diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java index 7dd947c39a9..6007bf0f1aa 100644 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java @@ -1055,8 +1055,7 @@ public class VirtualMachineMO extends BaseMO { // VirtualDisk, we only perform prefix matching Pair deviceInfo = getDiskDevice(vmdkDatastorePath, false); if(deviceInfo == null) { - if(s_logger.isTraceEnabled()) - s_logger.trace("vCenter API trace - detachDisk() done (failed)"); + s_logger.warn("vCenter API trace - detachDisk() done (failed)"); throw new Exception("No such disk device: " + vmdkDatastorePath); }