From 4282dec833a430d1037eed479c7f59ad5f26ad39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20=C5=A0est=C3=A1k?= Date: Tue, 18 May 2021 10:38:55 +0200 Subject: [PATCH 1/3] Partial fix for PCI devices reordering See https://github.com/QubesOS/qubes-issues/issues/6587. Attempt to fix the rest of PCI device reordering --- qubes/devices.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/qubes/devices.py b/qubes/devices.py index a02eab8b0..bde2bdb94 100644 --- a/qubes/devices.py +++ b/qubes/devices.py @@ -55,6 +55,8 @@ `domain-qdb-change:path`) to detect changes and fire `device-list-change:class` event. ''' +from typing import Optional + import qubes.utils class DeviceNotAttached(qubes.exc.QubesException, KeyError): @@ -339,7 +341,7 @@ def assignments(self, persistent=None): :file:`qubes.xml`) or not. Device can also be in :file:`qubes.xml`, but be temporarily detached. - :param bool persistent: only include devices which are or are not + :param Optional[bool] persistent: only include devices which are or are not attached persistently. ''' @@ -351,24 +353,19 @@ def assignments(self, persistent=None): self._bus)) if persistent is True: # don't break app.save() - return self._set + return list(self._set) raise - result = set() - for dev, options in devices: - if dev in self._set and not persistent: - continue - if dev in self._set: - result.add(self._set.get(dev)) - elif dev not in self._set and persistent: - continue - else: - result.add( - DeviceAssignment( - backend_domain=dev.backend_domain, - ident=dev.ident, options=options, - bus=self._bus)) - if persistent is not False: - result.update(self._set) + result = [] + if persistent is not False: # None or True + result.extend(self._set) + if not persistent: # None or False + for dev, options in devices: + if dev not in self._set: + result.append( + DeviceAssignment( + backend_domain=dev.backend_domain, + ident=dev.ident, options=options, + bus=self._bus)) return result def available(self): From ff5d235565d8a44025a505b89e63485d8e105e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20=C5=A0est=C3=A1k?= Date: Tue, 18 May 2021 16:28:00 +0200 Subject: [PATCH 2/3] Fix formatting --- qubes/devices.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qubes/devices.py b/qubes/devices.py index bde2bdb94..e9a7fb442 100644 --- a/qubes/devices.py +++ b/qubes/devices.py @@ -341,8 +341,8 @@ def assignments(self, persistent=None): :file:`qubes.xml`) or not. Device can also be in :file:`qubes.xml`, but be temporarily detached. - :param Optional[bool] persistent: only include devices which are or are not - attached persistently. + :param Optional[bool] persistent: only include devices which are or are + not attached persistently. ''' try: From 7b8e09b36c83835db62e7693c2370af4df0b0863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 10 Oct 2023 01:54:36 +0200 Subject: [PATCH 3/3] Use type hint not only in a comment --- qubes/devices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qubes/devices.py b/qubes/devices.py index e9a7fb442..a277aeeb2 100644 --- a/qubes/devices.py +++ b/qubes/devices.py @@ -333,7 +333,7 @@ def persistent(self): ''' return [a.device for a in self._set] - def assignments(self, persistent=None): + def assignments(self, persistent: Optional[bool]=None): '''List assignments for devices which are (or may be) attached to the vm.