From 07068be8ed327107256d429fdb0cd3339930bf38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 13 Jan 2014 05:19:43 +0100 Subject: [PATCH] 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). --- qubesmanager/backup_utils.py | 34 ++++++++++++++++++---------------- qubesmanager/restore.py | 8 +++++--- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/qubesmanager/backup_utils.py b/qubesmanager/backup_utils.py index b41e453..0e2dba4 100644 --- a/qubesmanager/backup_utils.py +++ b/qubesmanager/backup_utils.py @@ -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!", - "Could not attach {0}.

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!", + "Could not attach {0}.

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) diff --git a/qubesmanager/restore.py b/qubesmanager/restore.py index ccb7035..97f4e5c 100644 --- a/qubesmanager/restore.py +++ b/qubesmanager/restore.py @@ -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