Skip to content

Commit 78aacd1

Browse files
committed
Preload disposables
Is a disposable state, it runs on the background and awaits to intercept calls made to disposables of the same disposable template, having faster execution times. Information of the design choices is present in the DispVM class. To use them, set the number of allowed preloaded for each disposable template with the feature "preload-dispvm-max". In case there is not enough available memory, the maximum won't be preloaded at this instance, but will retry later on at any relevant event, such as a preloaded being used or a normal qube being requested while a preload can be created. GUI daemon requires a running qube to connect to the GUI agent in the qube, because of that, auto starting the preload mechanism only happens after a GUI login. Preloaded qubes are hidden from GUI applications until the qube itself is requested to be used. Any GUI application that allows opening applications on preloaded qubes before they are marked as used is considered a bug. Applications that autostart on the qube are shown before the qube has its state interrupted, it is also a bug but that can't be fixed easily. For: QubesOS/qubes-issues#1512 For: QubesOS/qubes-issues#9918
1 parent 37e49a1 commit 78aacd1

31 files changed

+1625
-130
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ include:
6363
project: QubesOS/qubes-continuous-integration
6464
- file: /r4.3/gitlab-host.yml
6565
project: QubesOS/qubes-continuous-integration
66+
- file: /r4.3/gitlab-host-openqa.yml
67+
project: QubesOS/qubes-continuous-integration
6668

6769
lint:
6870
extends: .lint

.pylintrc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ const-rgx=(([A-Za-z_][A-Za-z0-9_]*)|(__.*__))$
5858
class-rgx=([A-Z_][a-zA-Z0-9]+|TC_\d\d_[a-zA-Z0-9_]+)$
5959

6060
# Regular expression which should only match correct function names
61-
function-rgx=[a-z_][a-z0-9_]{2,30}$
61+
function-rgx=(test_[0-9]{3}_[a-z0-9_]{2,50}|[a-z_][a-z0-9_]{2,40})$
6262

6363
# Regular expression which should only match correct method names
64-
method-rgx=[a-z_][a-z0-9_]{2,30}$
64+
method-rgx=(test_[0-9]{3}_[a-z0-9_]{2,50}|[a-z_][a-z0-9_]{2,40})$
6565

6666
# Regular expression which should only match correct instance attribute names
67-
attr-rgx=[a-z_][a-z0-9_]{2,30}$
67+
attr-rgx=[a-z_][a-z0-9_]{2,40}$
6868

6969
# Regular expression which should only match correct argument names
70-
argument-rgx=[a-z_][a-z0-9_]{2,30}$
70+
argument-rgx=[a-z_][a-z0-9_]{2,40}$
7171

7272
# Regular expression which should only match correct variable names
73-
variable-rgx=[a-z_][a-z0-9_]{2,30}$
73+
variable-rgx=[a-z_][a-z0-9_]{2,40}$
7474

7575
# Regular expression which should only match correct list comprehension /
7676
# generator expression variable names

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ all:
179179

180180
install:
181181
ifeq ($(OS),Linux)
182+
$(MAKE) install -C linux/autostart
182183
$(MAKE) install -C linux/systemd
183184
$(MAKE) install -C linux/aux-tools
184185
$(MAKE) install -C linux/system-config

linux/autostart/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
all:
2+
true
3+
4+
install:
5+
mkdir -p $(DESTDIR)/etc/xdg/autostart
6+
cp qubes-preload-dispvm.desktop $(DESTDIR)/etc/xdg/autostart
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Desktop Entry]
2+
Icon=qubes
3+
Name=Qubes Preload Disposables
4+
Comment=Workaround for session monitoring with qubes.WaitForSession
5+
Categories=System;Monitor;
6+
Exec=systemctl start qubes-preload-dispvm.service
7+
Terminal=false
8+
NoDisplay=true
9+
Type=Application

linux/aux-tools/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ all:
33

44
install:
55
mkdir -p $(DESTDIR)/usr/lib/qubes
6-
cp cleanup-dispvms $(DESTDIR)/usr/lib/qubes
7-
cp startup-misc.sh $(DESTDIR)/usr/lib/qubes
6+
cp preload-dispvm $(DESTDIR)/usr/lib/qubes/
7+
cp cleanup-dispvms $(DESTDIR)/usr/lib/qubes/
8+
cp startup-misc.sh $(DESTDIR)/usr/lib/qubes/
89
cp fix-dir-perms.sh $(DESTDIR)/usr/lib/qubes/

linux/aux-tools/preload-dispvm

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
import asyncio
4+
import concurrent.futures
5+
import qubesadmin
6+
7+
8+
def get_max(qube):
9+
return int(qube.features.get("preload-dispvm-max", 0) or 0)
10+
11+
12+
async def main():
13+
domains = qubesadmin.Qubes().domains
14+
appvms = [
15+
qube
16+
for qube in domains
17+
if get_max(qube) > 0
18+
and qube.klass == "AppVM"
19+
and getattr(qube, "template_for_dispvms", False)
20+
]
21+
method = "admin.vm.CreateDisposable"
22+
loop = asyncio.get_running_loop()
23+
tasks = []
24+
with concurrent.futures.ThreadPoolExecutor() as executor:
25+
for qube in appvms:
26+
maximum = get_max(qube)
27+
print(f"{qube}:{maximum}")
28+
exec_args = qube.qubesd_call, qube.name, method, "preload-autostart"
29+
future = loop.run_in_executor(executor, *exec_args)
30+
tasks.append(future)
31+
await asyncio.gather(*tasks)
32+
33+
34+
if __name__ == "__main__":
35+
asyncio.run(main())

linux/systemd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ install:
99
cp [email protected] $(DESTDIR)$(UNITDIR)
1010
cp qubes-qmemman.service $(DESTDIR)$(UNITDIR)
1111
cp qubesd.service $(DESTDIR)$(UNITDIR)
12+
cp qubes-preload-dispvm.service $(DESTDIR)$(UNITDIR)
1213
install -d $(DESTDIR)$(UNITDIR)/[email protected]
1314
install -m 0644 [email protected]_30_qubes.conf \
1415
$(DESTDIR)$(UNITDIR)/[email protected]/30_qubes.conf
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=Preload Qubes DispVMs
3+
ConditionKernelCommandLine=!qubes.skip_autostart
4+
# After qmemman so the daemon can create the file containing available memory.
5+
After=qubesd.service qubes-meminfo-writer-dom0.service
6+
7+
[Service]
8+
Type=oneshot
9+
ExecStart=/usr/lib/qubes/preload-dispvm
10+
Group=qubes
11+
RemainAfterExit=yes
12+
13+
[Install]
14+
WantedBy=multi-user.target

linux/systemd/[email protected]

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[Unit]
22
Description=Start Qubes VM %i
33
After=qubesd.service qubes-meminfo-writer-dom0.service
4+
Before=qubes-preload-dispvm.service
45
ConditionKernelCommandLine=!qubes.skip_autostart
56

67
[Service]
78
Type=oneshot
8-
Environment=DISPLAY=:0
9-
ExecStart=/usr/bin/qvm-start --skip-if-running %i
9+
ExecStart=/usr/bin/qvm-start --skip-if-running -- %i
1010
Group=qubes
1111
RemainAfterExit=yes
1212

0 commit comments

Comments
 (0)