Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions qubes/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1912,9 +1912,12 @@ async def vm_device_list(self, endpoint):
async def vm_device_attached(self, endpoint):
devclass = endpoint
try:
device_assignments = self.dest.devices[
devclass
].get_attached_devices()
if self.dest.klass == "RemoteVM":
device_assignments = []
else:
device_assignments = self.dest.devices[
devclass
].get_attached_devices()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

device_assignments = []
if hasattr(self.dest, "devices") and devclass in self.dest.devices:
    self.dest.devices[devclass].get_attached_devices()

So we don't have to check for the klass explictly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier version of this commit did it like this, but it has an unfortunate side effect - accessing devices attribute during qubesd restart may throw AttributeError too, and the version with hasattr would result in a successful answer listing no devices. This, at the very least would result in a wrong state of the devices widget (and it won't be fixed soon, as there won't be events about new devices just because it got erroneously an empty list once).

except AttributeError as e:
if e.name == "devices":
# shutdown in progress, return specific error
Expand Down Expand Up @@ -1984,6 +1987,9 @@ async def vm_device_assign(self, endpoint, untrusted_payload):
options=assignment.options,
)

if not hasattr(self.dest, "devices"):
raise qubes.exc.QubesException("This qube doesn't support devices")

await self.dest.devices[devclass].assign(assignment)
self.app.save()

Expand Down Expand Up @@ -2026,6 +2032,9 @@ async def vm_device_unassign(self, endpoint):

self.fire_event_for_permission(device=dev)

if not hasattr(self.dest, "devices"):
raise qubes.exc.QubesException("This qube doesn't support devices")

await self.dest.devices[devclass].unassign(assignment)
self.app.save()

Expand Down Expand Up @@ -2054,6 +2063,9 @@ async def vm_device_attach(self, endpoint, untrusted_payload):
device=dev, mode=assignment.mode.value, options=assignment.options
)

if not hasattr(self.dest, "devices"):
raise qubes.exc.QubesException("This qube doesn't support devices")

await self.dest.devices[devclass].attach(assignment)

# Attach/Detach action can modify only a volatile state of running VM.
Expand All @@ -2076,6 +2088,9 @@ async def vm_device_detach(self, endpoint):

self.fire_event_for_permission(device=dev)

if not hasattr(self.dest, "devices"):
raise qubes.exc.QubesException("This qube doesn't support devices")

assignment = qubes.device_protocol.DeviceAssignment(dev)
await self.dest.devices[devclass].detach(assignment)

Expand Down
2 changes: 1 addition & 1 deletion qubes/ext/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def attachment(self) -> Optional[QubesVM]:
if not self.backend_domain or not self.backend_domain.is_running():
return None
for vm in self.backend_domain.app.domains:
if not vm.is_running():
if not vm.is_running() or not hasattr(vm, "libvirt_domain"):
continue
if self._is_attached_to(vm):
return vm
Expand Down