Skip to content

Commit

Permalink
q-dev: auto-attach only required block devices before vm start
Browse files Browse the repository at this point in the history
we might need to ask to attach rest
  • Loading branch information
piotrbartman committed Oct 15, 2024
1 parent e481e22 commit 9d82600
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions qubes/ext/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import qubes.device_protocol
import qubes.devices
import qubes.ext
from qubes.ext.utils import device_list_change
from qubes.ext.utils import device_list_change, confirm_device_attachment
from qubes.storage import Storage

name_re = re.compile(r"\A[a-z0-9-]{1,12}\Z")
Expand Down Expand Up @@ -541,8 +541,6 @@ def pre_attachment_internal(
async def on_domain_start(self, vm, _event, **_kwargs):
# pylint: disable=unused-argument
for assignment in vm.devices['block'].get_assigned_devices():
if assignment.mode == qubes.device_protocol.AssignmentMode.ASK:
pass
self.notify_auto_attached(vm, assignment)

def notify_auto_attached(self, vm, assignment):
Expand All @@ -556,6 +554,10 @@ def notify_auto_attached(self, vm, assignment):
f"does not match expected {identity}"
)

if assignment.mode.value == "ask-to-attach":
if vm.name != confirm_device_attachment(device, {vm: assignment}):
return

self.pre_attachment_internal(
vm, device, assignment.options, expected_attachment=vm)

Expand Down
2 changes: 1 addition & 1 deletion templates/libvirt/xen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
{# start external devices from xvdi #}
{% set counter = {'i': 4} %}
{% for assignment in vm.devices.block.get_assigned_devices(False) %}
{% for assignment in vm.devices.block.get_assigned_devices(True) %}
{% set device = assignment.device %}
{% set options = assignment.options %}
{% include 'libvirt/devices/block.xml' %}
Expand Down

0 comments on commit 9d82600

Please sign in to comment.