From 8cf154d5590eb577a6c1994863c8d440bb0effa6 Mon Sep 17 00:00:00 2001 From: Sateesh Chodapuneedi Date: Fri, 27 Dec 2013 17:15:35 +0530 Subject: [PATCH] CLOUDSTACK-5661 [VMware] DetachIsoCmd succeeds even though cdrom is locked by VM as cdrom is mounted DetachISO is succeeding even though detach opeartion is failing as cdrom is locked by VM as it was mounted inside VM. Detect if cdrom is locked or not. If locked fail detach operation and warn user to unmount before detaching the iso/cdrom device. Signed-off-by: Sateesh Chodapuneedi --- .../hypervisor/vmware/resource/VmwareResource.java | 5 ++++- .../storage/resource/VmwareStorageProcessor.java | 4 +++- .../cloud/hypervisor/vmware/mo/VirtualMachineMO.java | 12 +++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 3c7d5b6cb34..ee802d2e454 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -4946,7 +4946,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa vmMo.mountToolsInstaller(); } else { try{ - vmMo.unmountToolsInstaller(); + if (!vmMo.unmountToolsInstaller()) { + return new Answer(cmd, false, + "Failed to unmount vmware-tools installer ISO as the corresponding CDROM device is locked by VM. Please unmount the CDROM device inside the VM and ret-try."); + } }catch(Throwable e){ vmMo.detachIso(null); } 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 ef33ae6946b..44703d7896c 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -1296,7 +1296,9 @@ public class VmwareStorageProcessor implements StorageProcessor { vmMo.mountToolsInstaller(); } else { try{ - vmMo.unmountToolsInstaller(); + if (!vmMo.unmountToolsInstaller()) { + return new AttachAnswer("Failed to unmount vmware-tools installer ISO as the corresponding CDROM device is locked by VM. Please unmount the CDROM device inside the VM and ret-try."); + } } catch(Throwable e){ vmMo.detachIso(null); } 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 9728b3cbd0c..e4e2712ec23 100644 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java @@ -2398,11 +2398,13 @@ public class VirtualMachineMO extends BaseMO { _context.getService().mountToolsInstaller(_mor); } - public void unmountToolsInstaller() throws Exception { + public boolean unmountToolsInstaller() throws Exception { int i = 1; // Monitor VM questions final Boolean[] flags = {false}; final VirtualMachineMO vmMo = this; + final boolean[] encounterQuestion = new boolean[1]; + encounterQuestion[0] = false; Future future = _monitorServiceExecutor.submit(new Runnable() { @Override public void run() { @@ -2413,6 +2415,7 @@ public class VirtualMachineMO extends BaseMO { VirtualMachineRuntimeInfo runtimeInfo = vmMo.getRuntimeInfo(); VirtualMachineQuestionInfo question = runtimeInfo.getQuestion(); if (question != null) { + encounterQuestion[0] = true; if (s_logger.isTraceEnabled()) { s_logger.trace("Question id: " + question.getId()); s_logger.trace("Question text: " + question.getText()); @@ -2479,6 +2482,13 @@ public class VirtualMachineMO extends BaseMO { flags[0] = true; future.cancel(true); } + if (encounterQuestion[0]) { + s_logger.warn("cdrom is locked by VM. Failed to detach the ISO."); + return false; + } else { + s_logger.info("Successfully unmounted tools installer from VM."); + return true; + } } public void redoRegistration(ManagedObjectReference morHost) throws Exception {