From 7359e394bc130336936494580bd8473bdcadd810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 14 Nov 2015 23:36:22 +0100 Subject: [PATCH] core: detach connected VMs when shutting down NetVM This is workaround for missing libxl/libvirt functionality: QubesOS/qubes-issues#1426 Also it should improve system shutdown time, as this is the situation where all the VMs are shutting down simultaneously. Fixes QubesOS/qubes-issues#1425 --- core-modules/005QubesNetVm.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core-modules/005QubesNetVm.py b/core-modules/005QubesNetVm.py index c721bbab..33934f4b 100644 --- a/core-modules/005QubesNetVm.py +++ b/core-modules/005QubesNetVm.py @@ -23,7 +23,7 @@ # import sys import os.path -import xen.lowlevel.xs +import libvirt from qubes.qubes import QubesVm,register_qubes_vm_class,vmm,dry_run from qubes.qubes import defaults,system_path,vm_files @@ -153,6 +153,18 @@ class QubesNetVm(QubesVm): if connected_vms and not force: raise QubesException("There are other VMs connected to this VM: " + str([vm.name for vm in connected_vms])) + # detach network interfaces of connected VMs before shutting down, + # otherwise libvirt will not notice it and will try to detach them + # again (which would fail, obviously). + # This code can be removed when #1426 got implemented + for vm in self.connected_vms.values(): + if vm.is_running(): + try: + vm.detach_network() + except (QubesException, libvirt.libvirtError): + # ignore errors + pass + super(QubesNetVm, self).shutdown(force=force) def add_external_ip_permission(self, xid):