From 4ad451190cb4d1655851b1cf3a79f75552953ac5 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Fri, 9 Oct 2009 11:49:54 +0100
Subject: [PATCH] KVMHypervisor: use the StopInstance retry feature

Since we know StopInstance is going to be called more than once (at
least twice, once with force and once without, but normally quite a lot
more) we don't need our own sleep/loop, and we can just send one monitor
command per call.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Olivier Tharan <olive@google.com>
---
 lib/hypervisor/hv_kvm.py | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index bd3334565..6c90c2783 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -521,32 +521,16 @@ class KVMHypervisor(hv_base.BaseHypervisor):
 
     return result
 
-  def _RetryInstancePowerdown(self, instance, pid, timeout=30):
-    """Wait for an instance  to power down.
-
-    """
-    # Wait up to $timeout seconds
-    end = time.time() + timeout
-    wait = 1
-    while time.time() < end and utils.IsProcessAlive(pid):
-      self._CallMonitorCommand(instance.name, 'system_powerdown')
-      time.sleep(wait)
-      # Make wait time longer for next try
-      if wait < 5:
-        wait *= 1.3
-
   def StopInstance(self, instance, force=False, retry=False):
     """Stop an instance.
 
     """
-    if retry:
-      return
     pidfile, pid, alive = self._InstancePidAlive(instance.name)
     if pid > 0 and alive:
       if force or not instance.hvparams[constants.HV_ACPI]:
         utils.KillProcess(pid)
       else:
-        self._RetryInstancePowerdown(instance, pid)
+        self._CallMonitorCommand(instance.name, 'system_powerdown')
 
     if not utils.IsProcessAlive(pid):
       self._RemoveInstanceRuntimeFiles(pidfile, instance.name)
-- 
GitLab