Skip to content

Commit 7234af6

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 223b272 commit 7234af6

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
@@ -4922,7 +4922,10 @@ protected Answer execute(AttachIsoCommand cmd) {
49224922
vmMo.mountToolsInstaller();
49234923
} else {
49244924
try{
4925-
vmMo.unmountToolsInstaller();
4925+
if (!vmMo.unmountToolsInstaller()) {
4926+
return new Answer(cmd, false,
4927+
"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.");
4928+
}
49264929
}catch(Throwable e){
49274930
vmMo.detachIso(null);
49284931
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,9 @@ private Answer attachIso(DiskTO disk, boolean isAttach, String vmName) {
13161316
vmMo.mountToolsInstaller();
13171317
} else {
13181318
try{
1319-
vmMo.unmountToolsInstaller();
1319+
if (!vmMo.unmountToolsInstaller()) {
1320+
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.");
1321+
}
13201322
} catch(Throwable e){
13211323
vmMo.detachIso(null);
13221324
}

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

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

2367-
public void unmountToolsInstaller() throws Exception {
2367+
public boolean unmountToolsInstaller() throws Exception {
23682368
int i = 1;
23692369
// Monitor VM questions
23702370
final Boolean[] flags = {false};
23712371
final VirtualMachineMO vmMo = this;
2372+
final boolean[] encounterQuestion = new boolean[1];
2373+
encounterQuestion[0] = false;
23722374
Future<?> future = _monitorServiceExecutor.submit(new Runnable() {
23732375
@Override
23742376
public void run() {
@@ -2379,6 +2381,7 @@ public void run() {
23792381
VirtualMachineRuntimeInfo runtimeInfo = vmMo.getRuntimeInfo();
23802382
VirtualMachineQuestionInfo question = runtimeInfo.getQuestion();
23812383
if (question != null) {
2384+
encounterQuestion[0] = true;
23822385
if (s_logger.isTraceEnabled()) {
23832386
s_logger.trace("Question id: " + question.getId());
23842387
s_logger.trace("Question text: " + question.getText());
@@ -2445,6 +2448,13 @@ public void run() {
24452448
flags[0] = true;
24462449
future.cancel(true);
24472450
}
2451+
if (encounterQuestion[0]) {
2452+
s_logger.warn("cdrom is locked by VM. Failed to detach the ISO.");
2453+
return false;
2454+
} else {
2455+
s_logger.info("Successfully unmounted tools installer from VM.");
2456+
return true;
2457+
}
24482458
}
24492459

24502460
public void redoRegistration(ManagedObjectReference morHost) throws Exception {

0 commit comments

Comments
 (0)