diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index b441203afea..e8baf8d2065 100644 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -739,7 +739,7 @@ public class ApiResponseHelper implements ResponseGenerator { volResponse.setDeviceId(volume.getDeviceId()); Long instanceId = volume.getInstanceId(); - if (instanceId != null) { + if (instanceId != null && volume.getState() != Volume.State.Destroy) { VMInstanceVO vm = ApiDBUtils.findVMInstanceById(instanceId); volResponse.setVirtualMachineId(vm.getId()); volResponse.setVirtualMachineName(vm.getName()); diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 57c2032bb19..4e3ad207872 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -562,6 +562,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId); Account systemAcct = _accountMgr.getSystemAccount(); User systemUser = _accountMgr.getSystemUser(); + if (proxy.getState() == VirtualMachine.State.Running) { + return proxy; + } return _itMgr.start(proxy, null, systemUser, systemAcct); } diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 1d6a35a38ed..254844457bb 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -2723,8 +2723,10 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } String vmName = null; if (vol.getVolumeType() == VolumeType.ROOT && vol.getInstanceId() != null) { - VirtualMachine vm = _vmInstanceDao.findById(vol.getInstanceId()); - vmName = vm.getInstanceName(); + VirtualMachine vm = _vmInstanceDao.findByIdIncludingRemoved(vol.getInstanceId()); + if (vm != null) { + vmName = vm.getInstanceName(); + } } String volumePath = vol.getPath(); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index d583832e272..54cfe63342f 100644 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -461,7 +461,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager { while (retry-- != 0) { Transaction txn = Transaction.currentTxn(); txn.start(); - if (_vmDao.updateIf(vm, Event.StartRequested, null, work.getId())) { + if (stateTransitTo(vm, Event.StartRequested, null, work.getId())) { Journal journal = new Journal.LogJournal("Creating " + vm, s_logger); work = _workDao.persist(work); @@ -470,6 +470,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager { if (s_logger.isDebugEnabled()) { s_logger.debug("Successfully transitioned to start state for " + vm + " reservation id = " + work.getId()); } + txn.commit(); return new Ternary(vmGuru.findById(vmId), context, work); } @@ -477,35 +478,32 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager { s_logger.debug("Determining why we're unable to update the state to Starting for " + vm); } - try { - VMInstanceVO instance = _vmDao.lockRow(vmId, true); - if (instance == null) { - throw new ConcurrentOperationException("Unable to acquire lock on " + vm); + VMInstanceVO instance = _vmDao.lockRow(vmId, true); + if (instance == null) { + throw new ConcurrentOperationException("Unable to acquire lock on " + vm); + } + + State state = instance.getState(); + if (state == State.Running) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("VM is already started: " + vm); } - - State state = instance.getState(); - if (state == State.Running) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("VM is already started: " + vm); - } - return null; - } - - if (state.isTransitional()) { - if (!checkWorkItems(vm, state)) { - throw new ConcurrentOperationException("There are concurrent operations on the VM " + vm); - } else { - continue; - } - } - - if (state != State.Stopped) { - s_logger.debug("VM " + vm + " is not in a state to be started: " + state); - return null; - } - - } finally { txn.commit(); + return null; + } + + if (state.isTransitional()) { + if (!checkWorkItems(vm, state)) { + throw new ConcurrentOperationException("There are concurrent operations on the VM " + vm); + } else { + continue; + } + } + + if (state != State.Stopped) { + s_logger.debug("VM " + vm + " is not in a state to be started: " + state); + txn.commit(); + return null; } }