Skip to content

Commit

Permalink
serialize parent devclass
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Feb 19, 2024
1 parent 9236a1c commit 0856651
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions qubes/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,12 @@ def serialize(self) -> bytes:
properties += b' ' + interfaces_prop

if self.parent_device is not None:
parent_ident = serialize_str(self.parent_device.ident)
parent_prop = (b'parent=' + parent_ident.encode('ascii'))
properties += b' ' + parent_prop
ident = serialize_str(self.parent_device.ident)
ident_prop = (b'parent_ident=' + ident.encode('ascii'))
properties += b' ' + ident_prop
devclass = serialize_str(self.parent_device.devclass)
devclass_prop = (b'parent_devclass=' + devclass.encode('ascii'))
properties += b' ' + devclass_prop

data = b' '.join(
f'_{prop}={serialize_str(value)}'.encode('ascii')
Expand Down Expand Up @@ -609,11 +612,14 @@ def _deserialize(
for i in range(0, len(interfaces), 7)]
properties['interfaces'] = interfaces

if 'parent' in properties:
if 'parent_ident' in properties:
properties['parent'] = Device(
backend_domain=expected_backend_domain,
ident=properties['parent']
ident=properties['parent_ident'],
devclass=properties['parent_devclass'],
)
del properties['parent_ident']
del properties['parent_devclass']

return cls(**properties)

Expand Down
6 changes: 4 additions & 2 deletions qubes/ext/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,14 @@ def on_device_pre_attached_block(self, vm, event, device, options):
)
elif option == 'parent_identity':
identity = value
if device.parent.self_identity != identity:
p = device.parent_device
parent_info = p.backend_domain.devices[p.devclass][p.ident]
if parent_info.self_identity != identity:
print("Unrecognized parent identity, skipping attachment of"
f" {device}", file=sys.stderr)
raise qubes.devices.UnrecognizedDevice(
f"Parent device of {device} presents identity that"
f" {device.parent.self_identity} "
f" {parent_info.self_identity} "
f"does not match expected {identity}"
)
else:
Expand Down

0 comments on commit 0856651

Please sign in to comment.