From 8904b35c4e23ee51b988acfb9043e284f048a32d Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Mon, 19 Apr 2010 16:22:33 +0100
Subject: [PATCH] KVM: move post-shutdown cleanup operations

Currently putting the cleanup just after the actual shutdown ensures
that it never gets called, due to how the retry/shutdown cycle works.
So we move those cleanups to their new dedicated place.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/hypervisor/hv_kvm.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index fd36efeb2..cc8152130 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -631,18 +631,21 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       acpi = instance.hvparams[constants.HV_ACPI]
     else:
       acpi = False
-    pidfile, pid, alive = self._InstancePidAlive(name)
+    _, pid, alive = self._InstancePidAlive(name)
     if pid > 0 and alive:
       if force or not acpi:
         utils.KillProcess(pid)
       else:
         self._CallMonitorCommand(name, 'system_powerdown')
 
-    if not self._InstancePidAlive(name)[2]:
-      self._RemoveInstanceRuntimeFiles(pidfile, name)
-      return True
-    else:
-      return False
+  def CleanupInstance(self, instance_name):
+    """Cleanup after a stopped instance
+
+    """
+    pidfile, pid, alive = self._InstancePidAlive(instance_name)
+    if pid > 0 and alive:
+      raise errors.HypervisorError("Cannot cleanup a live instance")
+    self._RemoveInstanceRuntimeFiles(pidfile, instance_name)
 
   def RebootInstance(self, instance):
     """Reboot an instance.
-- 
GitLab