backups: improve handling of dom0 devices

Do not use blk_manager if the device is already in dom0, try to detach
device only when it was mounted (otherwise it was detached already in
error handling code).
This commit is contained in:
Marek Marczykowski-Górecki 2014-01-13 05:19:43 +01:00
parent 9214fb1488
commit 07068be8ed
2 changed files with 23 additions and 19 deletions

View File

@ -155,26 +155,28 @@ def dev_combobox_activated(dialog, idx):
if dialog.dev_combobox.currentIndex() != 0: #An existing device chosen if dialog.dev_combobox.currentIndex() != 0: #An existing device chosen
dev_name = str(dialog.dev_combobox.itemData(idx).toString()) dev_name = str(dialog.dev_combobox.itemData(idx).toString())
try: if dev_name.startswith(dialog.vm.name+":"):
with dialog.blk_manager.blk_lock: # originally attached to dom0
if dev_name in dialog.blk_manager.free_devs: dev_path = "/dev/"+dev_name.split(":")[1]
if dev_name.startswith(dialog.vm.name): # originally attached to dom0 else:
dev_path = "/dev/"+dev_name.split(":")[1] try:
with dialog.blk_manager.blk_lock:
else: # originally attached to another domain, eg. usbvm if dev_name in dialog.blk_manager.free_devs:
#attach it to dom0, then treat it as an attached device #attach it to dom0, then treat it as an attached device
dialog.blk_manager.attach_device(dialog.vm, dev_name) dialog.blk_manager.attach_device(dialog.vm, dev_name)
dialog.blk_manager.update() dialog.blk_manager.update()
if dev_name in dialog.blk_manager.attached_devs: #is attached to dom0 if dev_name in dialog.blk_manager.attached_devs: #is attached to dom0
assert dialog.blk_manager.attached_devs[dev_name]['attached_to']['vm'] == dialog.vm.name assert dialog.blk_manager.attached_devs[dev_name]['attached_to']['vm'] == dialog.vm.name
dev_path = "/dev/" + dialog.blk_manager.attached_devs[dev_name]['attached_to']['frontend'] dev_path = "/dev/" + dialog.blk_manager.attached_devs[dev_name]['attached_to']['frontend']
except QubesException as ex: else:
QMessageBox.warning (None, "Error attaching selected device!", raise QubesException("device not attached?!")
"<b>Could not attach {0}.</b><br><br>ERROR: {1}".format(dev_name, ex)) except QubesException as ex:
dialog.dev_combobox.setCurrentIndex(0) #if couldn't mount - set current device to "None" QMessageBox.warning (None, "Error attaching selected device!",
dialog.prev_dev_idx = 0 "<b>Could not attach {0}.</b><br><br>ERROR: {1}".format(dev_name, ex))
return dialog.dev_combobox.setCurrentIndex(0) #if couldn't mount - set current device to "None"
dialog.prev_dev_idx = 0
return
#check if device mounted #check if device mounted
dialog.dev_mount_path = check_if_mounted(dev_path) dialog.dev_mount_path = check_if_mounted(dev_path)

View File

@ -270,17 +270,19 @@ class RestoreVMsWindow(Ui_Restore, QWizard):
def reject(self): def reject(self):
if self.dev_mount_path != None: if self.dev_mount_path != None:
umount_device(self.dev_mount_path) umount_device(self.dev_mount_path)
detach_device(self, str(self.dev_combobox.itemData( detach_device(self, str(self.dev_combobox.itemData(
self.dev_combobox.currentIndex()).toString())) self.dev_combobox.currentIndex()).toString()))
self.done(0) self.done(0)
def has_selected_dir(self): def has_selected_dir(self):
backup_location = str(self.dir_line_edit.text()) backup_location = str(self.dir_line_edit.text())
if self.appvm_combobox.currentText() == "dom0": if not backup_location:
return False
if self.appvm_combobox.currentIndex() == 0:
if os.path.isfile(backup_location) or \ if os.path.isfile(backup_location) or \
os.path.isfile(os.path.join(backup_location, 'qubes.xml')): os.path.isfile(os.path.join(backup_location, 'qubes.xml')):
return True return True
elif len(backup_location) > 0: else:
return True return True
return False return False