Merge remote-tracking branch 'origin/pr/168'
* origin/pr/168: Fixed device handling in VM settings widget
This commit is contained in:
		
						commit
						0cdbda5df9
					
				@ -45,7 +45,7 @@ class PCIDeviceListWindow(ui_devicelist.Ui_Dialog, QtGui.QDialog):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        for i in range(self.dev_list.selected_list.count()):
 | 
					        for i in range(self.dev_list.selected_list.count()):
 | 
				
			||||||
            text = self.dev_list.selected_list.item(i).text()
 | 
					            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.device_list.addItem(text)
 | 
				
			||||||
            self.ident_list[text] = ident
 | 
					            self.ident_list[text] = ident
 | 
				
			||||||
            if ident in self.no_strict_reset_list:
 | 
					            if ident in self.no_strict_reset_list:
 | 
				
			||||||
 | 
				
			|||||||
@ -919,27 +919,29 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
 | 
				
			|||||||
        self.dev_list.add_all_button.setVisible(False)
 | 
					        self.dev_list.add_all_button.setVisible(False)
 | 
				
			||||||
        self.devices_layout.addWidget(self.dev_list)
 | 
					        self.devices_layout.addWidget(self.dev_list)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        devs = []
 | 
					        dom0_devs = list(self.vm.app.domains['dom0'].devices['pci'].available())
 | 
				
			||||||
        lspci = subprocess.check_output(['/usr/sbin/lspci']).decode()
 | 
					
 | 
				
			||||||
        for dev in lspci.splitlines():
 | 
					        attached_devs = list(self.vm.devices['pci'].persistent())
 | 
				
			||||||
            devs.append((dev.rstrip(), dev.split(' ')[0]))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # pylint: disable=too-few-public-methods
 | 
					        # pylint: disable=too-few-public-methods
 | 
				
			||||||
        class DevListWidgetItem(QtGui.QListWidgetItem):
 | 
					        class DevListWidgetItem(QtGui.QListWidgetItem):
 | 
				
			||||||
            def __init__(self, name, ident, parent=None):
 | 
					            def __init__(self, dev, unknown=False, parent=None):
 | 
				
			||||||
                super(DevListWidgetItem, self).__init__(name, parent)
 | 
					                super(DevListWidgetItem, self).__init__(parent)
 | 
				
			||||||
                self.ident = ident
 | 
					                name = dev.ident.replace('_', ":") + ' ' + dev.description
 | 
				
			||||||
 | 
					                if unknown:
 | 
				
			||||||
 | 
					                    name += ' (unknown)'
 | 
				
			||||||
 | 
					                self.setText(name)
 | 
				
			||||||
 | 
					                self.dev = dev
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        persistent = [ass.ident.replace('_', ':')
 | 
					        for dev in dom0_devs:
 | 
				
			||||||
                      for ass in self.vm.devices['pci'].persistent()]
 | 
					            if dev in attached_devs:
 | 
				
			||||||
 | 
					                self.dev_list.selected_list.addItem(DevListWidgetItem(dev))
 | 
				
			||||||
        for name, ident in devs:
 | 
					 | 
				
			||||||
            if ident in persistent:
 | 
					 | 
				
			||||||
                self.dev_list.selected_list.addItem(
 | 
					 | 
				
			||||||
                    DevListWidgetItem(name, ident))
 | 
					 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                self.dev_list.available_list.addItem(
 | 
					                self.dev_list.available_list.addItem(DevListWidgetItem(dev))
 | 
				
			||||||
                    DevListWidgetItem(name, ident))
 | 
					        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\
 | 
					        if self.dev_list.selected_list.count() > 0\
 | 
				
			||||||
                and self.include_in_balancing.isChecked():
 | 
					                and self.include_in_balancing.isChecked():
 | 
				
			||||||
@ -965,44 +967,43 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtGui.QDialog):
 | 
				
			|||||||
        msg = []
 | 
					        msg = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            old = [ass.ident.replace('_', ':')
 | 
					            old_devs = list(self.vm.devices['pci'].persistent())
 | 
				
			||||||
                   for ass in self.vm.devices['pci'].persistent()]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            new = [self.dev_list.selected_list.item(i).ident
 | 
					            new_devs = [item.dev
 | 
				
			||||||
                   for i in range(self.dev_list.selected_list.count())]
 | 
					                        for item in self.dev_list.selected_list.items()]
 | 
				
			||||||
            for ident in new:
 | 
					
 | 
				
			||||||
                if ident not in old:
 | 
					            for dev in new_devs:
 | 
				
			||||||
 | 
					                if dev not in old_devs:
 | 
				
			||||||
                    options = {}
 | 
					                    options = {}
 | 
				
			||||||
                    if ident in self.new_strict_reset_list:
 | 
					                    if dev.ident in self.new_strict_reset_list:
 | 
				
			||||||
                        options['no-strict-reset'] = True
 | 
					                        options['no-strict-reset'] = True
 | 
				
			||||||
                    ass = devices.DeviceAssignment(
 | 
					                    ass = devices.DeviceAssignment(
 | 
				
			||||||
                        self.vm.app.domains['dom0'],
 | 
					                        self.vm.app.domains['dom0'],
 | 
				
			||||||
                        ident.replace(':', '_'),
 | 
					                        dev.ident, persistent=True, options=options)
 | 
				
			||||||
                        persistent=True, options=options)
 | 
					 | 
				
			||||||
                    self.vm.devices['pci'].attach(ass)
 | 
					                    self.vm.devices['pci'].attach(ass)
 | 
				
			||||||
                elif (ident in self.current_strict_reset_list) != \
 | 
					                elif (dev.ident in self.current_strict_reset_list) != \
 | 
				
			||||||
                        (ident in self.new_strict_reset_list):
 | 
					                        (dev.ident in self.new_strict_reset_list):
 | 
				
			||||||
                    current_assignment = None
 | 
					                    current_assignment = None
 | 
				
			||||||
                    for assignment in self.vm.devices['pci'].assignments(
 | 
					                    for assignment in self.vm.devices['pci'].assignments(
 | 
				
			||||||
                            persistent=True):
 | 
					                            persistent=True):
 | 
				
			||||||
                        if assignment.ident.replace("_", ":") == ident:
 | 
					                        if assignment.ident == dev.ident:
 | 
				
			||||||
                            current_assignment = assignment
 | 
					                            current_assignment = assignment
 | 
				
			||||||
                            break
 | 
					                            break
 | 
				
			||||||
                    if current_assignment is None:
 | 
					                    if current_assignment is None:
 | 
				
			||||||
                        # it would be very weird if this happened
 | 
					                        # it would be very weird if this happened
 | 
				
			||||||
                        msg.append(self.tr("Error re-assigning device ") +
 | 
					                        msg.append(self.tr("Error re-assigning device ") +
 | 
				
			||||||
                                   ident)
 | 
					                                   dev.ident)
 | 
				
			||||||
                        continue
 | 
					                        continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    self.vm.devices['pci'].detach(current_assignment)
 | 
					                    self.vm.devices['pci'].detach(current_assignment)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    current_assignment.options['no-strict-reset'] = \
 | 
					                    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)
 | 
					                    self.vm.devices['pci'].attach(current_assignment)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for ass in self.vm.devices['pci'].assignments(persistent=True):
 | 
					            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)
 | 
					                    self.vm.devices['pci'].detach(ass)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        except qubesadmin.exc.QubesException as ex:
 | 
					        except qubesadmin.exc.QubesException as ex:
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user