Skip to content

Commit

Permalink
Merge branch 'qdev'
Browse files Browse the repository at this point in the history
* qdev:
  Adjust pylint mockups for device_protocol.py
  q-dev: Fix detecting already assigned devices on setting apply
  q-dev: fix detecting attached devices in settings
  q-dev: use simplify DeviceAssignment creation
  q-dev: direct import of device_protocol classes
  q-dev: implements device_id
  • Loading branch information
marmarek committed Nov 17, 2024
2 parents 291421e + a7b52bd commit d2e0eeb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
6 changes: 3 additions & 3 deletions qubesmanager/device_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def fill_device_list(self):

for i in range(self.dev_list.selected_list.count()):
text = self.dev_list.selected_list.item(i).text()
ident = self.dev_list.selected_list.item(i).dev.ident
port_id = self.dev_list.selected_list.item(i).dev.port_id
self.device_list.addItem(text)
self.ident_list[text] = ident
if ident in self.no_strict_reset_list:
self.ident_list[text] = port_id
if port_id in self.no_strict_reset_list:
self.device_list.item(self.device_list.count()-1).setSelected(
True)

Expand Down
53 changes: 23 additions & 30 deletions qubesmanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import sys
import traceback
from qubesadmin.tools import QubesArgumentParser
from qubesadmin import devices
from qubesadmin import device_protocol
from qubesadmin import utils as admin_utils
from qubesadmin.tools import qvm_start
import qubesadmin.exc
Expand Down Expand Up @@ -1217,7 +1217,7 @@ def __init_devices_tab__(self):
dom0_devs = \
list(self.vm.app.domains['dom0'].
devices['pci'].get_exposed_devices())
attached_devs = list(
attached = list(
self.vm.devices['pci'].get_assigned_devices(required_only=True))
except qubesadmin.exc.QubesException:
# no permission to access devices
Expand All @@ -1228,21 +1228,21 @@ def __init_devices_tab__(self):
class DevListWidgetItem(QtWidgets.QListWidgetItem):
def __init__(self, dev, unknown=False, parent=None):
super().__init__(parent)
name = dev.ident.replace('_', ":") + ' ' + dev.description
name = dev.port_id.replace('_', ":") + ' ' + dev.description
if unknown:
name += ' (unknown)'
self.setText(name)
self.dev = dev

for dev in dom0_devs:
if dev in attached_devs:
if any(attached_dev.matches(dev) for attached_dev in attached):
self.dev_list.selected_list.addItem(DevListWidgetItem(dev))
else:
self.dev_list.available_list.addItem(DevListWidgetItem(dev))
for dev in attached_devs:
if dev not in dom0_devs:
for ass in attached:
if not any(ass.matches(dev) for dev in dom0_devs):
self.dev_list.selected_list.addItem(
DevListWidgetItem(dev, unknown=True))
DevListWidgetItem(ass.device, unknown=True))

if self.dev_list.selected_list.count() > 0\
and self.include_in_balancing.isChecked():
Expand Down Expand Up @@ -1278,34 +1278,27 @@ def __apply_devices_tab__(self):
for i in range(self.dev_list.selected_list.count())]

for dev in new_devs:
if dev not in old_devs:
old_assignments = [old for old in old_devs
if old.matches(dev)]
if not old_assignments:
options = {}
if dev.ident in self.new_strict_reset_list:
if dev.port_id in self.new_strict_reset_list:
options['no-strict-reset'] = True
ass = devices.DeviceAssignment(
self.vm.app.domains['dom0'],
dev.ident, devclass='pci',
attach_automatically=True, required=True,
options=options)
ass = device_protocol.DeviceAssignment.new(
backend_domain=self.vm.app.domains['dom0'],
port_id=dev.port_id,
devclass='pci',
mode='required',
options=options,
)
self.vm.devices['pci'].assign(ass)
elif (dev.ident in self.current_strict_reset_list) != \
(dev.ident in self.new_strict_reset_list):
current_assignment = None
for assignment in self.vm.devices[
'pci'].get_assigned_devices(required_only=True):
if assignment.ident == dev.ident:
current_assignment = assignment
break
if current_assignment is None:
# it would be very weird if this happened
msg.append(self.tr("Error re-assigning device ") +
dev.ident)
continue

elif (dev.port_id in self.current_strict_reset_list) != \
(dev.port_id in self.new_strict_reset_list):
current_assignment = old_assignments[0]
self.vm.devices['pci'].unassign(current_assignment)

current_assignment.options['no-strict-reset'] = \
dev.ident in self.new_strict_reset_list
dev.port_id in self.new_strict_reset_list

self.vm.devices['pci'].assign(current_assignment)

Expand Down Expand Up @@ -1347,7 +1340,7 @@ def define_strict_reset_devices(self):
required_only=True):
if assignment.options.get('no-strict-reset', False):
self.current_strict_reset_list.append(
assignment.ident.replace('_', ':'))
assignment.port_id.replace('_', ':'))
self.new_strict_reset_list = self.current_strict_reset_list.copy()

def strict_reset_button_pressed(self):
Expand Down
17 changes: 17 additions & 0 deletions test-packages/qubesadmin/device_protocol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### mock qubesadmin.devices module

class DeviceAssignment(object):

@classmethod
def new(
cls,
backend_domain,
port_id: str,
devclass: str,
device_id: Optional[str] = None,
*,
frontend_domain = None,
options=None,
mode = "manual",
) -> "DeviceAssignment":
pass
4 changes: 0 additions & 4 deletions test-packages/qubesadmin/devices.py

This file was deleted.

0 comments on commit d2e0eeb

Please sign in to comment.