Commit 4ad45119 authored by Guido Trotter's avatar Guido Trotter
Browse files

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: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarOlivier Tharan <olive@google.com>
parent e4e9b806
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment