Skip to content

Commit 53b6bd9

Browse files
committed
q-dev: fix detaching required devices
1 parent a851333 commit 53b6bd9

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

qubes/devices.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -309,24 +309,25 @@ async def detach(self, port: Port):
309309
"""
310310
Detach device from domain.
311311
"""
312-
for assign in self.get_attached_devices():
313-
if port.port_id == assign.port_id:
312+
for attached in self.get_attached_devices():
313+
if port.port_id == attached.port_id:
314314
# load all options
315-
assignment = assign
316315
break
317316
else:
318317
raise DeviceNotAssigned(
319318
f'{self._bus} device {port.port_id!s} not '
320319
f'attached to {self._vm!s}')
321320

322-
if assignment.required and not self._vm.is_halted():
323-
raise qubes.exc.QubesVMNotHaltedError(
324-
self._vm,
325-
"Can not detach a required device from a non halted qube. "
326-
"You need to unassign device first.")
321+
for assign in self.get_assigned_devices():
322+
if (assign.required and not self._vm.is_halted()
323+
and assign.matches(attached.device)):
324+
raise qubes.exc.QubesVMNotHaltedError(
325+
self._vm,
326+
"Can not detach a required device from a non halted qube. "
327+
"You need to unassign device first.")
327328

328329
# use the local object, only one device can match
329-
port = assignment.device.port
330+
port = attached.device.port
330331
await self._vm.fire_event_async(
331332
'device-pre-detach:' + self._bus, pre_event=True, port=port)
332333

0 commit comments

Comments
 (0)