Skip to content

Commit db99146

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> Conflicts: plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
1 parent f6b063d commit db99146

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4945,9 +4945,12 @@ protected Answer execute(AttachIsoCommand cmd) {
49454945
if (cmd.isAttach()) {
49464946
vmMo.mountToolsInstaller();
49474947
} else {
4948-
try {
4949-
vmMo.unmountToolsInstaller();
4950-
} catch (Throwable e) {
4948+
try{
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+
}
4953+
}catch(Throwable e){
49514954
vmMo.detachIso(null);
49524955
}
49534956
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,9 +1263,11 @@ private Answer attachIso(DiskTO disk, boolean isAttach, String vmName) {
12631263
if (isAttach) {
12641264
vmMo.mountToolsInstaller();
12651265
} else {
1266-
try {
1267-
vmMo.unmountToolsInstaller();
1268-
} catch (Throwable e) {
1266+
try{
1267+
if (!vmMo.unmountToolsInstaller()) {
1268+
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.");
1269+
}
1270+
} catch(Throwable e){
12691271
vmMo.detachIso(null);
12701272
}
12711273
}

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

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

2348-
public void unmountToolsInstaller() throws Exception {
2348+
public boolean unmountToolsInstaller() throws Exception {
23492349
int i = 1;
23502350
// Monitor VM questions
23512351
final Boolean[] flags = {false};
23522352
final VirtualMachineMO vmMo = this;
2353+
final boolean[] encounterQuestion = new boolean[1];
2354+
encounterQuestion[0] = false;
23532355
Future<?> future = MonitorServiceExecutor.submit(new Runnable() {
23542356
@Override
23552357
public void run() {
@@ -2360,6 +2362,7 @@ public void run() {
23602362
VirtualMachineRuntimeInfo runtimeInfo = vmMo.getRuntimeInfo();
23612363
VirtualMachineQuestionInfo question = runtimeInfo.getQuestion();
23622364
if (question != null) {
2365+
encounterQuestion[0] = true;
23632366
if (s_logger.isTraceEnabled()) {
23642367
s_logger.trace("Question id: " + question.getId());
23652368
s_logger.trace("Question text: " + question.getText());
@@ -2425,6 +2428,13 @@ public void run() {
24252428
flags[0] = true;
24262429
future.cancel(true);
24272430
}
2431+
if (encounterQuestion[0]) {
2432+
s_logger.warn("cdrom is locked by VM. Failed to detach the ISO.");
2433+
return false;
2434+
} else {
2435+
s_logger.info("Successfully unmounted tools installer from VM.");
2436+
return true;
2437+
}
24282438
}
24292439

24302440
public void redoRegistration(ManagedObjectReference morHost) throws Exception {

0 commit comments

Comments
 (0)