backups: detach block device when finished or error occurred
This commit is contained in:
parent
5f7113e11e
commit
26d4f67963
@ -346,6 +346,8 @@ class BackupVMsWindow(Ui_Backup, QWizard):
|
|||||||
self.progress_status.setText = "Backup finished."
|
self.progress_status.setText = "Backup finished."
|
||||||
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(
|
||||||
|
self.dev_combobox.currentIndex()).toString()))
|
||||||
self.button(self.FinishButton).setEnabled(True)
|
self.button(self.FinishButton).setEnabled(True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,6 +75,13 @@ def umount_device(dev_mount_path):
|
|||||||
if button == QMessageBox.Ok:
|
if button == QMessageBox.Ok:
|
||||||
return dev_mount_path
|
return dev_mount_path
|
||||||
|
|
||||||
|
def detach_device(dialog, dev_name):
|
||||||
|
""" Detach device from dom0, if device was attached from some VM"""
|
||||||
|
if not dev_name.startswith(dialog.vm.name+":"):
|
||||||
|
with dialog.blk_manager.blk_lock:
|
||||||
|
dialog.blk_manager.detach_device(dialog.vm, dev_name)
|
||||||
|
dialog.blk_manager.update()
|
||||||
|
|
||||||
def fill_appvms_list(dialog):
|
def fill_appvms_list(dialog):
|
||||||
dialog.appvm_combobox.clear()
|
dialog.appvm_combobox.clear()
|
||||||
dialog.appvm_combobox.addItem("dom0")
|
dialog.appvm_combobox.addItem("dom0")
|
||||||
@ -126,16 +133,22 @@ def dev_combobox_activated(dialog, idx):
|
|||||||
|
|
||||||
dialog.dir_line_edit.setText("")
|
dialog.dir_line_edit.setText("")
|
||||||
|
|
||||||
|
# umount old device if any
|
||||||
if dialog.dev_mount_path != None:
|
if dialog.dev_mount_path != None:
|
||||||
dialog.dev_mount_path = umount_device(dialog.dev_mount_path)
|
dialog.dev_mount_path = umount_device(dialog.dev_mount_path)
|
||||||
if dialog.dev_mount_path != None:
|
if dialog.dev_mount_path != None:
|
||||||
dialog.dev_combobox.setCurrentIndex(dialog.prev_dev_idx)
|
dialog.dev_combobox.setCurrentIndex(dialog.prev_dev_idx)
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
detach_device(dialog,
|
||||||
|
str(dialog.dev_combobox.itemData(dialog.prev_dev_idx).toString()))
|
||||||
|
|
||||||
if dialog.dev_combobox.currentText() != "None": #An existing device chosen
|
# then attach new one
|
||||||
|
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())
|
||||||
|
|
||||||
dialog.blk_manager.blk_lock.acquire()
|
try:
|
||||||
|
with dialog.blk_manager.blk_lock:
|
||||||
if dev_name in dialog.blk_manager.free_devs:
|
if dev_name in dialog.blk_manager.free_devs:
|
||||||
if dev_name.startswith(dialog.vm.name): # originally attached to dom0
|
if dev_name.startswith(dialog.vm.name): # originally attached to dom0
|
||||||
dev_path = "/dev/"+dev_name.split(":")[1]
|
dev_path = "/dev/"+dev_name.split(":")[1]
|
||||||
@ -148,7 +161,12 @@ def dev_combobox_activated(dialog, idx):
|
|||||||
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']
|
||||||
dialog.blk_manager.blk_lock.release()
|
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
|
#check if device mounted
|
||||||
dialog.dev_mount_path = check_if_mounted(dev_path)
|
dialog.dev_mount_path = check_if_mounted(dev_path)
|
||||||
@ -157,6 +175,8 @@ def dev_combobox_activated(dialog, idx):
|
|||||||
if dialog.dev_mount_path == None:
|
if dialog.dev_mount_path == None:
|
||||||
dialog.dev_combobox.setCurrentIndex(0) #if couldn't mount - set current device to "None"
|
dialog.dev_combobox.setCurrentIndex(0) #if couldn't mount - set current device to "None"
|
||||||
dialog.prev_dev_idx = 0
|
dialog.prev_dev_idx = 0
|
||||||
|
detach_device(dialog,
|
||||||
|
str(dialog.dev_combobox.itemData(idx).toString()))
|
||||||
return
|
return
|
||||||
|
|
||||||
dialog.prev_dev_idx = idx
|
dialog.prev_dev_idx = idx
|
||||||
|
@ -259,6 +259,10 @@ class RestoreVMsWindow(Ui_Restore, QWizard):
|
|||||||
|
|
||||||
if self.dev_mount_path != None:
|
if self.dev_mount_path != None:
|
||||||
umount_device(self.dev_mount_path)
|
umount_device(self.dev_mount_path)
|
||||||
|
self.dev_mount_path = None
|
||||||
|
detach_device(self, str(self.dev_combobox.itemData(
|
||||||
|
self.dev_combobox.currentIndex()).toString()))
|
||||||
|
|
||||||
self.progress_bar.setValue(100)
|
self.progress_bar.setValue(100)
|
||||||
self.button(self.FinishButton).setEnabled(True)
|
self.button(self.FinishButton).setEnabled(True)
|
||||||
|
|
||||||
@ -274,6 +278,8 @@ 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(
|
||||||
|
self.dev_combobox.currentIndex()).toString()))
|
||||||
self.done(0)
|
self.done(0)
|
||||||
|
|
||||||
def has_selected_dir(self):
|
def has_selected_dir(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user