Skip to content

Commit

Permalink
q-dev: simplify parent_device
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Jun 12, 2024
1 parent 14e431f commit 69adb22
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
9 changes: 3 additions & 6 deletions qubes/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def description(self) -> str:
elif self.serial and self.serial != "unknown":
prod = self.serial
elif self.parent_device is not None:
return f"partition of {self.parent_device}"
return f"sub-device of {self.parent_device}"
else:
prod = f"unknown {self.devclass if self.devclass else ''} device"

Expand All @@ -316,17 +316,14 @@ def interfaces(self) -> List[DeviceInterface]:
return self._interfaces

@property
def parent_device(self) -> Optional['DeviceInfo']:
def parent_device(self) -> Optional[Device]:
"""
The parent device if any.
If the device is part of another device (e.g. it's a single
partition of an usb stick), the parent device id should be here.
"""
if self._parent is None:
return None
return self.backend_domain.devices.get(
self._parent.devclass, {}).get(self._parent.ident, None)
return self._parent

@property
def subdevices(self) -> List['DeviceInfo']:
Expand Down
10 changes: 2 additions & 8 deletions qubes/ext/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def device_node(self):
return '/dev/' + self.ident.replace('_', '/')

@property
def parent_device(self) -> Optional[qubes.devices.DeviceInfo]:
def parent_device(self) -> Optional[qubes.devices.Device]:
"""
The parent device if any.
Expand All @@ -130,13 +130,7 @@ def parent_device(self) -> Optional[qubes.devices.DeviceInfo]:
parent_ident = self._sanitize(untrusted_parent)
self._parent = qubes.devices.Device(
self.backend_domain, parent_ident)
return self.backend_domain.devices.get(
self._parent.devclass, {}).get(
self._parent.ident, qubes.devices.UnknownDevice(
backend_domain=self._parent.backend_domain,
ident=self._parent.ident
)
)
return self._parent

@staticmethod
def _sanitize(
Expand Down

0 comments on commit 69adb22

Please sign in to comment.