Skip to content

Commit 8cf154d

Browse files
author
Sateesh Chodapuneedi
committed
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 <sateesh@apache.org>
1 parent ad5d607 commit 8cf154d

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4946,7 +4946,10 @@ protected Answer execute(AttachIsoCommand cmd) {
49464946
vmMo.mountToolsInstaller();
49474947
} else {
49484948
try{
4949-
vmMo.unmountToolsInstaller();
4949+
if (!vmMo.unmountToolsInstaller()) {
4950+
return new Answer(cmd, false,
4951+
"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.");
4952+
}
49504953
}catch(Throwable e){
49514954
vmMo.detachIso(null);
49524955
}

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,9 @@ private Answer attachIso(DiskTO disk, boolean isAttach, String vmName) {
12961296
vmMo.mountToolsInstaller();
12971297
} else {
12981298
try{
1299-
vmMo.unmountToolsInstaller();
1299+
if (!vmMo.unmountToolsInstaller()) {
1300+
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.");
1301+
}
13001302
} catch(Throwable e){
13011303
vmMo.detachIso(null);
13021304
}

vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2398,11 +2398,13 @@ public void mountToolsInstaller() throws Exception {
23982398
_context.getService().mountToolsInstaller(_mor);
23992399
}
24002400

2401-
public void unmountToolsInstaller() throws Exception {
2401+
public boolean unmountToolsInstaller() throws Exception {
24022402
int i = 1;
24032403
// Monitor VM questions
24042404
final Boolean[] flags = {false};
24052405
final VirtualMachineMO vmMo = this;
2406+
final boolean[] encounterQuestion = new boolean[1];
2407+
encounterQuestion[0] = false;
24062408
Future<?> future = _monitorServiceExecutor.submit(new Runnable() {
24072409
@Override
24082410
public void run() {
@@ -2413,6 +2415,7 @@ public void run() {
24132415
VirtualMachineRuntimeInfo runtimeInfo = vmMo.getRuntimeInfo();
24142416
VirtualMachineQuestionInfo question = runtimeInfo.getQuestion();
24152417
if (question != null) {
2418+
encounterQuestion[0] = true;
24162419
if (s_logger.isTraceEnabled()) {
24172420
s_logger.trace("Question id: " + question.getId());
24182421
s_logger.trace("Question text: " + question.getText());
@@ -2479,6 +2482,13 @@ public void run() {
24792482
flags[0] = true;
24802483
future.cancel(true);
24812484
}
2485+
if (encounterQuestion[0]) {
2486+
s_logger.warn("cdrom is locked by VM. Failed to detach the ISO.");
2487+
return false;
2488+
} else {
2489+
s_logger.info("Successfully unmounted tools installer from VM.");
2490+
return true;
2491+
}
24822492
}
24832493

24842494
public void redoRegistration(ManagedObjectReference morHost) throws Exception {

0 commit comments

Comments
 (0)