29
29
import sys
30
30
import traceback
31
31
from qubesadmin .tools import QubesArgumentParser
32
- from qubesadmin import devices
32
+ from qubesadmin import device_protocol
33
33
from qubesadmin import utils as admin_utils
34
34
from qubesadmin .tools import qvm_start
35
35
import qubesadmin .exc
@@ -1217,7 +1217,7 @@ def __init_devices_tab__(self):
1217
1217
dom0_devs = \
1218
1218
list (self .vm .app .domains ['dom0' ].
1219
1219
devices ['pci' ].get_exposed_devices ())
1220
- attached_devs = list (
1220
+ attached = list (
1221
1221
self .vm .devices ['pci' ].get_assigned_devices (required_only = True ))
1222
1222
except qubesadmin .exc .QubesException :
1223
1223
# no permission to access devices
@@ -1228,21 +1228,21 @@ def __init_devices_tab__(self):
1228
1228
class DevListWidgetItem (QtWidgets .QListWidgetItem ):
1229
1229
def __init__ (self , dev , unknown = False , parent = None ):
1230
1230
super ().__init__ (parent )
1231
- name = dev .ident .replace ('_' , ":" ) + ' ' + dev .description
1231
+ name = dev .port_id .replace ('_' , ":" ) + ' ' + dev .description
1232
1232
if unknown :
1233
1233
name += ' (unknown)'
1234
1234
self .setText (name )
1235
1235
self .dev = dev
1236
1236
1237
1237
for dev in dom0_devs :
1238
- if dev in attached_devs :
1238
+ if any ( attached_dev . matches ( dev ) for attached_dev in attached ) :
1239
1239
self .dev_list .selected_list .addItem (DevListWidgetItem (dev ))
1240
1240
else :
1241
1241
self .dev_list .available_list .addItem (DevListWidgetItem (dev ))
1242
- for dev in attached_devs :
1243
- if dev not in dom0_devs :
1242
+ for ass in attached :
1243
+ if not any ( ass . matches ( dev ) for dev in dom0_devs ) :
1244
1244
self .dev_list .selected_list .addItem (
1245
- DevListWidgetItem (dev , unknown = True ))
1245
+ DevListWidgetItem (ass . device , unknown = True ))
1246
1246
1247
1247
if self .dev_list .selected_list .count () > 0 \
1248
1248
and self .include_in_balancing .isChecked ():
@@ -1278,34 +1278,27 @@ def __apply_devices_tab__(self):
1278
1278
for i in range (self .dev_list .selected_list .count ())]
1279
1279
1280
1280
for dev in new_devs :
1281
- if dev not in old_devs :
1281
+ old_assignments = [old for old in old_devs
1282
+ if old .matches (dev )]
1283
+ if not old_assignments :
1282
1284
options = {}
1283
- if dev .ident in self .new_strict_reset_list :
1285
+ if dev .port_id in self .new_strict_reset_list :
1284
1286
options ['no-strict-reset' ] = True
1285
- ass = devices .DeviceAssignment (
1286
- self .vm .app .domains ['dom0' ],
1287
- dev .ident , devclass = 'pci' ,
1288
- attach_automatically = True , required = True ,
1289
- options = options )
1287
+ ass = device_protocol .DeviceAssignment .new (
1288
+ backend_domain = self .vm .app .domains ['dom0' ],
1289
+ port_id = dev .port_id ,
1290
+ devclass = 'pci' ,
1291
+ mode = 'required' ,
1292
+ options = options ,
1293
+ )
1290
1294
self .vm .devices ['pci' ].assign (ass )
1291
- elif (dev .ident in self .current_strict_reset_list ) != \
1292
- (dev .ident in self .new_strict_reset_list ):
1293
- current_assignment = None
1294
- for assignment in self .vm .devices [
1295
- 'pci' ].get_assigned_devices (required_only = True ):
1296
- if assignment .ident == dev .ident :
1297
- current_assignment = assignment
1298
- break
1299
- if current_assignment is None :
1300
- # it would be very weird if this happened
1301
- msg .append (self .tr ("Error re-assigning device " ) +
1302
- dev .ident )
1303
- continue
1304
-
1295
+ elif (dev .port_id in self .current_strict_reset_list ) != \
1296
+ (dev .port_id in self .new_strict_reset_list ):
1297
+ current_assignment = old_assignments [0 ]
1305
1298
self .vm .devices ['pci' ].unassign (current_assignment )
1306
1299
1307
1300
current_assignment .options ['no-strict-reset' ] = \
1308
- dev .ident in self .new_strict_reset_list
1301
+ dev .port_id in self .new_strict_reset_list
1309
1302
1310
1303
self .vm .devices ['pci' ].assign (current_assignment )
1311
1304
@@ -1347,7 +1340,7 @@ def define_strict_reset_devices(self):
1347
1340
required_only = True ):
1348
1341
if assignment .options .get ('no-strict-reset' , False ):
1349
1342
self .current_strict_reset_list .append (
1350
- assignment .ident .replace ('_' , ':' ))
1343
+ assignment .port_id .replace ('_' , ':' ))
1351
1344
self .new_strict_reset_list = self .current_strict_reset_list .copy ()
1352
1345
1353
1346
def strict_reset_button_pressed (self ):
0 commit comments