From 059171eef89d19175a56fa542fc41971ad76987e Mon Sep 17 00:00:00 2001 From: Ali Mirjamali Date: Tue, 3 Sep 2024 12:43:46 +0330 Subject: [PATCH] Kill paused qubes on system shutdown fixes: https://github.com/QubesOS/qubes-issues/issues/8580 --- qubes/tests/__init__.py | 13 +++++++++++++ qubes/tests/integ/basic.py | 1 + qubes/vm/qubesvm.py | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index f0db98fbb..9600dadee 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -1233,6 +1233,19 @@ def shutdown_and_wait(self, vm, timeout=60): del vm self.fail("Timeout while waiting for VM {} shutdown".format(name)) + def shutdown_paused(self, vm, timeout=60): + try: + self.loop.run_until_complete(vm.pause()) + with self.assertRaises(qubes.exc.QubesVMNotRunningError): + self.loop.run_until_complete( + vm.shutdown(wait=True, timeout=timeout, force=False)) + self.loop.run_until_complete( + vm.shutdown(wait=True, timeout=timeout, force=True)) + except qubes.exc.QubesException: + name = vm.name + del vm + self.fail("Timeout while waiting for VM {} shutdown".format(name)) + def prepare_hvm_system_linux(self, vm, init_script, extra_files=None): if not os.path.exists('/usr/lib/grub/i386-pc'): self.skipTest('grub2 not installed') diff --git a/qubes/tests/integ/basic.py b/qubes/tests/integ/basic.py index 47517267f..ff53ef69d 100644 --- a/qubes/tests/integ/basic.py +++ b/qubes/tests/integ/basic.py @@ -427,6 +427,7 @@ def _do_test(self): self.loop.run_until_complete(self.test_template.start()) self.loop.run_until_complete(self.wait_for_session(self.test_template)) self.shutdown_and_wait(self.test_template) + self.shutdown_paused(self.test_template) checksum_changed = self.get_rootimg_checksum() if checksum_before == checksum_changed: self.log.warning("template not modified, test result will be " diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index fa7fd3ec6..bbbc74b3c 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1382,10 +1382,17 @@ async def shutdown(self, force=False, wait=False, timeout=None): await self.fire_event_async('domain-pre-shutdown', pre_event=True, force=force) + if self.is_paused() and not force: + raise qubes.exc.QubesVMNotRunningError(self) + if self.__waiter is None: self.__waiter = asyncio.get_running_loop().create_future() waiter = self.__waiter - self.libvirt_domain.shutdown() + + if self.is_paused(): + self.libvirt_domain.destroy() + else: + self.libvirt_domain.shutdown() if wait: if timeout is None: