@@ -523,10 +523,13 @@ async def attach_and_notify(self, vm, assignment):
523
523
device , {vm : assignment }):
524
524
return
525
525
526
- await self .on_device_attach_usb (
527
- vm , 'device-pre-attach:usb' , device , assignment .options )
528
- await vm .fire_event_async (
529
- 'device-attach:usb' , device = device , options = assignment .options )
526
+ try :
527
+ await self .on_device_attach_usb (
528
+ vm , 'device-pre-attach:usb' , device , assignment .options )
529
+ await vm .fire_event_async (
530
+ 'device-attach:usb' , device = device , options = assignment .options )
531
+ except qubes .devices .DeviceAlreadyAttached :
532
+ pass
530
533
531
534
@qubes .ext .handler ('domain-qdb-change:/qubes-usb-devices' )
532
535
def on_qdb_change (self , vm , event , path ):
@@ -689,7 +692,9 @@ async def on_device_detach_usb(self, vm, event, port):
689
692
@qubes .ext .handler ('domain-start' )
690
693
async def on_domain_start (self , vm , _event , ** _kwargs ):
691
694
# pylint: disable=unused-argument
692
- for assignment in get_assigned_devices (vm .devices ['usb' ]):
695
+ # the most specific assignments first
696
+ for assignment in reversed (sorted (
697
+ get_assigned_devices (vm .devices ['usb' ]))):
693
698
await self .attach_and_notify (vm , assignment )
694
699
695
700
@qubes .ext .handler ('domain-shutdown' )
0 commit comments