Skip to content

Commit efb572e

Browse files
committed
q-dev: matches
1 parent c93f8c3 commit efb572e

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

qubes/device_protocol.py

+11
Original file line numberDiff line numberDiff line change
@@ -1213,3 +1213,14 @@ def _deserialize(
12131213
properties['device'] = expected_device
12141214

12151215
return cls(**properties)
1216+
1217+
def matches(self, device: VirtualDevice) -> bool:
1218+
if self.backend_domain != '*' and self.backend_domain != device.backend_domain:
1219+
return False
1220+
if self.port_id != '*' and self.port_id != device.port_id:
1221+
return False
1222+
if self.devclass != '*' and self.devclass != device.devclass:
1223+
return False
1224+
if self.device_id != '*' and self.device_id != device.device_id:
1225+
return False
1226+
return True

qubes/ext/block.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,8 @@ async def on_domain_start(self, vm, _event, **_kwargs):
545545
self.notify_auto_attached(vm, assignment)
546546

547547
def notify_auto_attached(self, vm, assignment):
548-
identity = assignment.device_id
549548
for device in assignment.devices:
550-
if identity not in ('*', device.device_id):
549+
if not assignment.matches(device):
551550
print("Unrecognized identity, skipping attachment of device "
552551
f"from the port {assignment}", file=sys.stderr)
553552
continue

qubes/ext/utils.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# along with this program; if not, write to the Free Software
1919
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
2020
# USA.
21-
import importlib
2221
import asyncio
2322
import subprocess
2423

@@ -67,8 +66,7 @@ def device_list_change(
6766
continue
6867
for assignment in front_vm.devices[devclass].get_assigned_devices():
6968
for device in assignment.devices:
70-
if (device.backend_domain == vm
71-
and assignment.device_id == device.device_id
69+
if (assignment.matches(device)
7270
and device.port_id in added
7371
and device.port_id not in attached
7472
):

qubes/tests/devices_block.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ def test_062_on_qdb_change_attached(self):
731731
'/qubes-block-devices/sda/size': b'1024000',
732732
'/qubes-block-devices/sda/mode': b'r',
733733
}, domain_xml=domain_xml_template.format(""))
734-
exp_dev = qubes.ext.block.BlockDevice(back_vm, 'sda')
734+
exp_dev = qubes.ext.block.BlockDevice(back_vm, 'sda')
735735

736736
self.ext.devices_cache = {'sys-usb': {'sda': None}}
737737

0 commit comments

Comments
 (0)