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

View File

@ -270,17 +270,19 @@ class RestoreVMsWindow(Ui_Restore, QWizard):
def reject(self):
if self.dev_mount_path != None:
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.done(0)
def has_selected_dir(self):
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 \
os.path.isfile(os.path.join(backup_location, 'qubes.xml')):
return True
elif len(backup_location) > 0:
else:
return True
return False