Skip to content

Commit

Permalink
q-dev: implements new device api
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Mar 19, 2024
1 parent f701e83 commit c15bc0f
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions qubesmanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,10 @@ def update_virt_mode_list(self):
devs_attached = self.dev_list.selected_list.count() != 0
else:
try:
devs_attached = bool(list(self.vm.devices['pci'].persistent()))
devs_attached = bool(list(
self.vm.devices['pci'].get_assigned_devices(
required_only=True))
)
except qubesadmin.exc.QubesException:
devs_attached = False

Expand Down Expand Up @@ -1183,8 +1186,10 @@ def __init_devices_tab__(self):

try:
dom0_devs = \
list(self.vm.app.domains['dom0'].devices['pci'].available())
attached_devs = list(self.vm.devices['pci'].persistent())
list(self.vm.app.domains['dom0'].
devices['pci'].get_exposed_devices())
attached_devs = list(
self.vm.devices['pci'].get_assigned_devices(required_only=True))
except qubesadmin.exc.QubesException:
# no permission to access devices
self.tabWidget.setTabEnabled(self.tabs_indices['devices'], False)
Expand Down Expand Up @@ -1237,7 +1242,8 @@ def __apply_devices_tab__(self):
return msg

try:
old_devs = list(self.vm.devices['pci'].persistent())
old_devs = list(
self.vm.devices['pci'].get_assigned_devices(required_only=True))

new_devs = [self.dev_list.selected_list.item(i).dev
for i in range(self.dev_list.selected_list.count())]
Expand All @@ -1249,13 +1255,15 @@ def __apply_devices_tab__(self):
options['no-strict-reset'] = True
ass = devices.DeviceAssignment(
self.vm.app.domains['dom0'],
dev.ident, persistent=True, options=options)
self.vm.devices['pci'].attach(ass)
dev.ident, devclass='pci',
attach_automatically=True, required=True,
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'].assignments(
persistent=True):
for assignment in self.vm.devices[
'pci'].get_assigned_devices(required_only=True):
if assignment.ident == dev.ident:
current_assignment = assignment
break
Expand All @@ -1265,16 +1273,17 @@ def __apply_devices_tab__(self):
dev.ident)
continue

self.vm.devices['pci'].detach(current_assignment)
self.vm.devices['pci'].unassign(current_assignment)

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

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

for ass in self.vm.devices['pci'].assignments(persistent=True):
for ass in self.vm.devices['pci'].get_assigned_devices(
required_only=True):
if ass.device not in new_devs:
self.vm.devices['pci'].detach(ass)
self.vm.devices['pci'].unassign(ass)

except qubesadmin.exc.QubesException as ex:
if utils.is_debug():
Expand Down Expand Up @@ -1305,7 +1314,8 @@ def update_pvh_dont_support_devs(self):
self.pvh_dont_support_devs.setVisible(False)

def define_strict_reset_devices(self):
for assignment in self.vm.devices['pci'].assignments():
for assignment in self.vm.devices['pci'].get_assigned_devices(
required_only=True):
if assignment.options.get('no-strict-reset', False):
self.current_strict_reset_list.append(
assignment.ident.replace('_', ':'))
Expand Down

0 comments on commit c15bc0f

Please sign in to comment.