Skip to content

Commit 84f1f52

Browse files
committed
Add global preload to template gathering
Affects suspend, which uses this function. For: QubesOS/qubes-issues#1512
1 parent 8de4cd0 commit 84f1f52

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

qubes/api/internal.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ async def suspend_pre(self):
265265
:return:
266266
"""
267267

268-
preload_templates = qubes.vm.dispvm.get_preload_templates(
269-
self.app.domains
270-
)
268+
preload_templates = qubes.vm.dispvm.get_preload_templates(self.app)
271269
for qube in preload_templates:
272270
qube.remove_preload_excess(0)
273271

@@ -416,9 +414,7 @@ async def suspend_post(self):
416414
"qubes.SuspendPostAll",
417415
)
418416

419-
preload_templates = qubes.vm.dispvm.get_preload_templates(
420-
self.app.domains
421-
)
417+
preload_templates = qubes.vm.dispvm.get_preload_templates(self.app)
422418
for qube in preload_templates:
423419
asyncio.ensure_future(
424420
qube.fire_event_async("domain-preload-dispvm-autostart")

qubes/vm/dispvm.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,27 @@ def _setter_template(self, prop, value):
4040
return value
4141

4242

43-
def get_preload_templates(domains) -> list:
44-
return [
45-
qube
46-
for qube in domains
47-
if int(qube.features.get("preload-dispvm-max", 0) or 0) > 0
48-
and qube.klass == "AppVM"
49-
and getattr(qube, "template_for_dispvms", False)
50-
]
43+
def get_preload_templates(app) -> list:
44+
domains = app.domains
45+
appvms = []
46+
default_dispvm = getattr(app, "default_dispvm", None)
47+
# Only add default_dispvm now if it will not be added by the other clause.
48+
if (
49+
int(domains["dom0"].features.get("preload-dispvm-max", 0) or 0) > 0
50+
and default_dispvm
51+
and int(default_dispvm.features.get("preload-dispvm-max", 0) or 0) == 0
52+
):
53+
appvms.append(default_dispvm)
54+
appvms.extend(
55+
[
56+
qube
57+
for qube in domains
58+
if int(qube.features.get("preload-dispvm-max", 0) or 0) > 0
59+
and qube.klass == "AppVM"
60+
and getattr(qube, "template_for_dispvms", False)
61+
]
62+
)
63+
return appvms
5164

5265

5366
class DispVM(qubes.vm.qubesvm.QubesVM):

0 commit comments

Comments
 (0)