Skip to content

Commit

Permalink
q-dev: keep partial backward compatibility for auto-attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Jun 6, 2024
1 parent 5cb2a8f commit cad623a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions qubesusbproxy/core3ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@
from qubes.device_protocol import DeviceInterface
from qubes.ext import utils
from qubes.devices import UnrecognizedDevice

def get_assigned_devices(devices):
yield from devices.get_assigned_devices()
except ImportError:
# This extension supports both the legacy and new device API.
# In the case of the legacy backend, functionality is limited.
from qubes.devices import DeviceInfo as LegacyDeviceInfo
import qubesusbproxy.utils
from qubesusbproxy import utils

class DescriptionOverrider:
@property
Expand Down Expand Up @@ -77,6 +80,10 @@ class DeviceInterface:
class UnrecognizedDevice(ValueError):
pass

def get_assigned_devices(devices):
yield from devices.assignments(persistent=True)


import qubes.devices
import qubes.ext
import qubes.vm.adminvm
Expand Down Expand Up @@ -650,7 +657,7 @@ async def on_device_detach_usb(self, vm, event, device):
@qubes.ext.handler('domain-start')
async def on_domain_start(self, vm, _event, **_kwargs):
# pylint: disable=unused-argument
for assignment in vm.devices['usb'].get_assigned_devices():
for assignment in get_assigned_devices(vm.devices['usb']):
await self.attach_and_notify(
vm, assignment.device, assignment.options)

Expand Down
3 changes: 2 additions & 1 deletion qubesusbproxy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def device_list_change(
for front_vm in vm.app.domains:
if not front_vm.is_running():
continue
for assignment in front_vm.devices[devclass].get_assigned_devices():
for assignment in front_vm.devices[devclass].assignments(
persistent=True):
if (assignment.backend_domain == vm
and assignment.ident in added
and assignment.ident not in attached
Expand Down

0 comments on commit cad623a

Please sign in to comment.