Skip to content

Commit 7c186ba

Browse files
committed
Fix preload dispvm autostart
- Clean the feature after it's qubes are removed - Start after qubesd - Separate feature set events - Convert maximum value to integer to not set '01' for example
1 parent ceff798 commit 7c186ba

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

linux/systemd/qubes-preload-dispvm.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Description=Preload Qubes DispVMs
33
ConditionKernelCommandLine=!qubes.skip_autostart
44
# After qmemman so the daemon can create the file containing available memory.
5-
After=qubes-qmemman.service
5+
After=qubesd.service qubes-meminfo-writer-dom0.service
66

77
[Service]
88
Type=oneshot

qubes/vm/mix/dvmtemplate.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,23 @@ def can_preload(self) -> bool:
6262
def on_feature_pre_set_preload_dispvm_max(
6363
self, event, feature, value, oldvalue=None
6464
): # pylint: disable=unused-argument
65-
if not value:
66-
value = "0"
65+
value = value or "0"
6766
if not value.isdigit():
6867
raise qubes.exc.QubesValueError(
6968
"Invalid preload-dispvm-max value: not a digit"
7069
)
71-
if not oldvalue:
72-
oldvalue = 0
70+
71+
@qubes.events.handler("domain-feature-set:preload-dispvm-max")
72+
def on_feature_set_preload_dispvm_max(
73+
self, event, feature, value, oldvalue=None
74+
): # pylint: disable=unused-argument
75+
value = value or 0
76+
oldvalue = oldvalue or 0
7377
oldvalue = int(oldvalue)
7478
value = int(value)
7579
if value > oldvalue or (value == oldvalue and self.can_preload()):
7680
# Also try to preload qubes when value hasn't changed so the loop
77-
# can start on a system that is already running but preload qubes
81+
# can start on a system that is already running but preloaded qubes
7882
# were killed, such as with 'qvm-shutdown --all'.
7983
asyncio.ensure_future(
8084
self.fire_event_async("domain-preloaded-dispvm-start")
@@ -86,8 +90,9 @@ def on_feature_pre_set_preload_dispvm_max(
8690
new_preload = old_preload[:value]
8791
self.features["preload-dispvm"] = " ".join(new_preload or [])
8892
for unwanted_disp in old_preload[value:]:
89-
dispvm = self.app.domains[unwanted_disp]
90-
asyncio.ensure_future(dispvm.cleanup())
93+
if unwanted_disp in self.app.domains:
94+
dispvm = self.app.domains[unwanted_disp]
95+
asyncio.ensure_future(dispvm.cleanup())
9196

9297
@qubes.events.handler("domain-feature-pre-set:preload-dispvm")
9398
def on_feature_pre_set_preload_dispvm(
@@ -189,6 +194,11 @@ async def on_domain_preloaded_dispvm_used(
189194
"""
190195
event = event.removeprefix("domain-preloaded-dispvm-")
191196
if event == "autostart":
197+
old_preload = self.get_feat_preload()
198+
for unwanted_name in old_preload:
199+
if unwanted_name in self.app.domains:
200+
unwanted_dispvm = self.app.domains[unwanted_name]
201+
asyncio.ensure_future(unwanted_dispvm.cleanup())
192202
self.features["preload-dispvm"] = ""
193203
if not self.can_preload():
194204
return

0 commit comments

Comments
 (0)