From 2ac8f682e8f7c173add2c7bc635e9cbe0a578b92 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 31 Jan 2011 14:02:39 -0800 Subject: [PATCH] bug 8279: In the recreatable case, we considered the vm fenced off and restarted it elsewhere. That causes the vm sync to think the vm is in stopped state for which there is no StopCommand sent. We now cleanup the halted vms in this situation. --- .../xen/resource/CitrixResourceBase.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index b1b93c8ac16..ac68a47ff64 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -1993,6 +1993,23 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR throw new CloudRuntimeException("Com'on no control domain? What the crap?!#@!##$@"); } + protected void cleanupHaltedVms(Connection conn) throws XenAPIException, XmlRpcException { + Host host = Host.getByUuid(conn, _host.uuid); + Set vms = host.getResidentVMs(conn); + + for (VM vm : vms) { + try { + if (VmPowerState.HALTED.equals(vm.getPowerState(conn))) { + vm.destroy(conn); + } + } catch (XenAPIException e) { + s_logger.warn("Unable to cleanup " + vm); + } catch (XmlRpcException e) { + s_logger.warn("Unable to cleanup " + vm); + } + } + } + protected HashMap sync() { HashMap newStates; HashMap oldStates = null; @@ -3779,6 +3796,16 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } setupLinkLocalNetwork(); + + try { + cleanupHaltedVms(getConnection()); + } catch (XenAPIException e) { + s_logger.warn("Unable to cleanup halted vms", e); + return null; + } catch (XmlRpcException e) { + s_logger.warn("Unable to cleanup halted vms", e); + return null; + } StartupRoutingCommand cmd = new StartupRoutingCommand();