From f4be2843310ae21a6e47dbc520b4b3a669f3b52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 2 Apr 2018 23:56:03 +0200 Subject: [PATCH] vm/qubesvm: handle libvirt reporting domain already dead when killing If domain die when trying to kill it, qubesd may loose a race and try to kill it anyway. Handle libvirt exception in that case and conver it to QubesVMNotStartedError - as it would be if qubesd would win the race. Fixes QubesOS/qubes-issues#3755 --- qubes/vm/qubesvm.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 4db5ac38..c920c5a8 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1024,7 +1024,13 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): if not self.is_running() and not self.is_paused(): raise qubes.exc.QubesVMNotStartedError(self) - self.libvirt_domain.destroy() + try: + self.libvirt_domain.destroy() + except libvirt.libvirtError as e: + if e.get_error_code() == libvirt.VIR_ERR_OPERATION_INVALID: + raise qubes.exc.QubesVMNotStartedError(self) + else: + raise return self