Fix block attach/detach

This commit is contained in:
Marek Marczykowski-Górecki 2015-04-14 23:11:12 +02:00
parent 9a22de3432
commit 8a91c90cf8
2 changed files with 15 additions and 16 deletions

View File

@ -122,6 +122,7 @@ class QubesBlockDevicesManager():
def __make_entry__(self, k, dev, att):
size_str = qubesutils.bytes_to_kmg(dev['size'])
entry = { 'dev': dev['device'],
'dev_obj': dev,
'backend_name': dev['vm'],
'desc': dev['desc'],
'mode': dev['mode'],
@ -130,14 +131,12 @@ class QubesBlockDevicesManager():
return entry
def attach_device(self, vm, dev):
backend_vm_name = self.free_devs[dev]['backend_name']
mode = self.free_devs[dev]['mode']
backend_vm = self.qvm_collection.get_vm_by_name(backend_vm_name)
if self.tray_message_func:
self.tray_message_func("{0} - attaching {1}"
.format(vm.name, dev), msecs=3000)
qubesutils.block_attach(self.qvm_collection, vm, backend_vm,
self.free_devs[dev], mode=mode)
qubesutils.block_attach(self.qvm_collection, vm,
self.free_devs[dev]['dev_obj'], mode=mode)
def detach_device(self, vm, dev_name):
frontend = self.attached_devs[dev_name]['attached_to']['frontend']

View File

@ -663,7 +663,9 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow):
rows_with_blk = []
self.blk_manager.blk_lock.acquire()
for d in self.blk_manager.attached_devs:
rows_with_blk.append( self.blk_manager.attached_devs[d]['attached_to']['vm'])
rows_with_blk.append(
self.blk_manager.attached_devs[d]['attached_to'][
'vm'].qid)
self.blk_manager.blk_lock.release()
if (not self.table.isColumnHidden(self.columns_indices['Size']) ) and self.counter % 60 == 0 or out_of_schedule:
@ -683,7 +685,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow):
cur_cpu_load = 0
if rows_with_blk != None:
if vm_row.vm.name in rows_with_blk:
if vm_row.vm.qid in rows_with_blk:
blk_visible = True
else:
blk_visible = False
@ -1440,10 +1442,13 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow):
self.blk_menu.setEnabled(True)
self.blk_manager.blk_lock.acquire()
if len(self.blk_manager.attached_devs) > 0 :
if len(self.blk_manager.attached_devs) > 0:
for d in self.blk_manager.attached_devs:
if self.blk_manager.attached_devs[d]['attached_to']['vm'] == vm.name:
text = "Detach " + d + " " + unicode(self.blk_manager.attached_devs[d]['size']) + " " + self.blk_manager.attached_devs[d]['desc']
if self.blk_manager.attached_devs[d]['attached_to'][
'vm'].qid == vm.qid:
text = "Detach " + d + " " + unicode(
self.blk_manager.attached_devs[d]['size']) + " " + \
self.blk_manager.attached_devs[d]['desc']
action = self.blk_menu.addAction(QIcon(":/remove.png"), text)
action.setData(QVariant(d))
@ -1564,9 +1569,7 @@ class QubesTrayIcon(QSystemTrayIcon):
self.blk_manager.blk_lock.acquire()
if len(self.blk_manager.attached_devs) > 0 :
for d in self.blk_manager.attached_devs:
vm = self.blk_manager.qvm_collection.get_vm_by_name(
self.blk_manager.attached_devs[d]['attached_to']['vm']
)
vm = self.blk_manager.attached_devs[d]['attached_to']['vm']
text = "Detach %s %s (%s) from %s" % (
d,
self.blk_manager.attached_devs[d]['desc'],
@ -1611,10 +1614,7 @@ class QubesTrayIcon(QSystemTrayIcon):
@pyqtSlot('QAction *')
def dettach_device_triggered(self, action):
dev = str(action.data().toString())
vm = self.blk_manager.qvm_collection.get_vm_by_name(
self.blk_manager.attached_devs[dev]['attached_to']['vm']
)
vm = self.blk_manager.attached_devs[dev]['attached_to']['vm']
self.blk_manager.blk_lock.acquire()
try: