Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/168'
Browse files Browse the repository at this point in the history
* origin/pr/168:
  Fixed device handling in VM settings widget
marmarek committed Apr 3, 2019

Verified

This commit was signed with the committer’s verified signature.
marmarek Marek Marczykowski-Górecki
2 parents 278a72d + 077bcb3 commit 0cdbda5
Showing 2 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion qubesmanager/device_list.py
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ 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).ident
ident = self.dev_list.selected_list.item(i).dev.ident
self.device_list.addItem(text)
self.ident_list[text] = ident
if ident in self.no_strict_reset_list:
65 changes: 33 additions & 32 deletions qubesmanager/settings.py
Original file line number Diff line number Diff line change
@@ -919,27 +919,29 @@ def __init_devices_tab__(self):
self.dev_list.add_all_button.setVisible(False)
self.devices_layout.addWidget(self.dev_list)

devs = []
lspci = subprocess.check_output(['/usr/sbin/lspci']).decode()
for dev in lspci.splitlines():
devs.append((dev.rstrip(), dev.split(' ')[0]))
dom0_devs = list(self.vm.app.domains['dom0'].devices['pci'].available())

attached_devs = list(self.vm.devices['pci'].persistent())

# pylint: disable=too-few-public-methods
class DevListWidgetItem(QtGui.QListWidgetItem):
def __init__(self, name, ident, parent=None):
super(DevListWidgetItem, self).__init__(name, parent)
self.ident = ident

persistent = [ass.ident.replace('_', ':')
for ass in self.vm.devices['pci'].persistent()]

for name, ident in devs:
if ident in persistent:
self.dev_list.selected_list.addItem(
DevListWidgetItem(name, ident))
def __init__(self, dev, unknown=False, parent=None):
super(DevListWidgetItem, self).__init__(parent)
name = dev.ident.replace('_', ":") + ' ' + dev.description
if unknown:
name += ' (unknown)'
self.setText(name)
self.dev = dev

for dev in dom0_devs:
if dev in attached_devs:
self.dev_list.selected_list.addItem(DevListWidgetItem(dev))
else:
self.dev_list.available_list.addItem(
DevListWidgetItem(name, ident))
self.dev_list.available_list.addItem(DevListWidgetItem(dev))
for dev in attached_devs:
if dev not in dom0_devs:
self.dev_list.selected_list.addItem(
DevListWidgetItem(dev, unknown=True))

if self.dev_list.selected_list.count() > 0\
and self.include_in_balancing.isChecked():
@@ -965,44 +967,43 @@ def __apply_devices_tab__(self):
msg = []

try:
old = [ass.ident.replace('_', ':')
for ass in self.vm.devices['pci'].persistent()]
old_devs = list(self.vm.devices['pci'].persistent())

new_devs = [item.dev
for item in self.dev_list.selected_list.items()]

new = [self.dev_list.selected_list.item(i).ident
for i in range(self.dev_list.selected_list.count())]
for ident in new:
if ident not in old:
for dev in new_devs:
if dev not in old_devs:
options = {}
if ident in self.new_strict_reset_list:
if dev.ident in self.new_strict_reset_list:
options['no-strict-reset'] = True
ass = devices.DeviceAssignment(
self.vm.app.domains['dom0'],
ident.replace(':', '_'),
persistent=True, options=options)
dev.ident, persistent=True, options=options)
self.vm.devices['pci'].attach(ass)
elif (ident in self.current_strict_reset_list) != \
(ident in self.new_strict_reset_list):
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):
if assignment.ident.replace("_", ":") == ident:
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 ") +
ident)
dev.ident)
continue

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

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

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

for ass in self.vm.devices['pci'].assignments(persistent=True):
if ass.ident.replace('_', ':') not in new:
if ass.device not in new_devs:
self.vm.devices['pci'].detach(ass)

except qubesadmin.exc.QubesException as ex:

0 comments on commit 0cdbda5

Please sign in to comment.