-
-
Notifications
You must be signed in to change notification settings - Fork 115
Preload disposables #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Preload disposables #660
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| all: | ||
| true | ||
|
|
||
| install: | ||
| mkdir -p $(DESTDIR)/etc/xdg/autostart | ||
| cp qubes-preload-dispvm.desktop $(DESTDIR)/etc/xdg/autostart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [Desktop Entry] | ||
| Icon=qubes | ||
| Name=Qubes Preload Disposables | ||
| Comment=Workaround for session monitoring with qubes.WaitForSession | ||
| Categories=System;Monitor; | ||
| Exec=systemctl start qubes-preload-dispvm.service | ||
| Terminal=false | ||
| NoDisplay=true | ||
| Type=Application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import asyncio | ||
| import concurrent.futures | ||
| import qubesadmin | ||
|
|
||
|
|
||
| def get_max(qube): | ||
| return int(qube.features.get("preload-dispvm-max", 0) or 0) | ||
|
|
||
|
|
||
| async def main(): | ||
| domains = qubesadmin.Qubes().domains | ||
| appvms = [ | ||
| qube | ||
| for qube in domains | ||
| if get_max(qube) > 0 | ||
| and qube.klass == "AppVM" | ||
| and getattr(qube, "template_for_dispvms", False) | ||
| ] | ||
| method = "admin.vm.CreateDisposable" | ||
| loop = asyncio.get_running_loop() | ||
| tasks = [] | ||
| with concurrent.futures.ThreadPoolExecutor() as executor: | ||
| for qube in appvms: | ||
| maximum = get_max(qube) | ||
| print(f"{qube}:{maximum}") | ||
| exec_args = qube.qubesd_call, qube.name, method, "preload-autostart" | ||
| future = loop.run_in_executor(executor, *exec_args) | ||
| tasks.append(future) | ||
| await asyncio.gather(*tasks) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ install: | |
| cp [email protected] $(DESTDIR)$(UNITDIR) | ||
| cp qubes-qmemman.service $(DESTDIR)$(UNITDIR) | ||
| cp qubesd.service $(DESTDIR)$(UNITDIR) | ||
| cp qubes-preload-dispvm.service $(DESTDIR)$(UNITDIR) | ||
| install -d $(DESTDIR)$(UNITDIR)/[email protected] | ||
| install -m 0644 [email protected]_30_qubes.conf \ | ||
| $(DESTDIR)$(UNITDIR)/[email protected]/30_qubes.conf | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [Unit] | ||
| Description=Preload Qubes DispVMs | ||
| ConditionKernelCommandLine=!qubes.skip_autostart | ||
| # After qmemman so the daemon can create the file containing available memory. | ||
| After=qubesd.service qubes-meminfo-writer-dom0.service | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/usr/lib/qubes/preload-dispvm | ||
| Group=qubes | ||
| RemainAfterExit=yes | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library; if not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| """ Internal interface for dom0 components to communicate with qubesd. """ | ||
| """Internal interface for dom0 components to communicate with qubesd.""" | ||
|
|
||
| import asyncio | ||
| import json | ||
|
|
@@ -45,6 +45,8 @@ | |
| "domain-shutdown", | ||
| "domain-tag-add:*", | ||
| "domain-tag-delete:*", | ||
| "domain-feature-set:internal", | ||
| "domain-feature-delete:internal", | ||
| "property-set:template_for_dispvms", | ||
| "property-reset:template_for_dispvms", | ||
| "property-set:default_dispvm", | ||
|
|
@@ -117,6 +119,7 @@ | |
| system_info = { | ||
| "domains": { | ||
| domain.name: { | ||
| "internal": domain.features.get("internal", None), | ||
| "tags": list(domain.tags), | ||
| "type": domain.__class__.__name__, | ||
| "template_for_dispvms": getattr( | ||
|
|
@@ -262,6 +265,12 @@ | |
| :return: | ||
| """ | ||
|
|
||
| preload_templates = qubes.vm.dispvm.get_preload_templates( | ||
| self.app.domains | ||
| ) | ||
| for qube in preload_templates: | ||
| qube.remove_preload_excess(0) | ||
|
|
||
| # first keep track of VMs which were paused before suspending | ||
| previously_paused = [ | ||
| vm.name | ||
|
|
@@ -406,3 +415,11 @@ | |
| qubes.config.suspend_timeout, | ||
| "qubes.SuspendPostAll", | ||
| ) | ||
|
|
||
| preload_templates = qubes.vm.dispvm.get_preload_templates( | ||
| self.app.domains | ||
| ) | ||
| for qube in preload_templates: | ||
| asyncio.ensure_future( | ||
| qube.fire_event_async("domain-preload-dispvm-autostart") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I change the other places to call autostart to no call future, do you think it matters here? I think that awaiting would make post suspend slower to finish? I don't know the impacts of this. |
||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.