diff --git a/qubes/api/admin.py b/qubes/api/admin.py index 5a6f31e5..ea6e5b0e 100644 --- a/qubes/api/admin.py +++ b/qubes/api/admin.py @@ -1130,19 +1130,20 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI): self.fire_event_for_permission() - if not self.dest.is_halted(): - raise qubes.exc.QubesVMNotHaltedError(self.dest) + with (yield from self.dest.startup_lock): + if not self.dest.is_halted(): + raise qubes.exc.QubesVMNotHaltedError(self.dest) - if self.dest.installed_by_rpm: - raise qubes.exc.QubesVMInUseError(self.dest, \ - "VM installed by package manager: " + self.dest.name) + if self.dest.installed_by_rpm: + raise qubes.exc.QubesVMInUseError(self.dest, + "VM installed by package manager: " + self.dest.name) - del self.app.domains[self.dest] - try: - yield from self.dest.remove_from_disk() - except: # pylint: disable=bare-except - self.app.log.exception('Error while removing VM \'%s\' files', - self.dest.name) + del self.app.domains[self.dest] + try: + yield from self.dest.remove_from_disk() + except: # pylint: disable=bare-except + self.app.log.exception('Error while removing VM \'%s\' files', + self.dest.name) self.app.save() diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index e1df0dc8..a42cc032 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1008,6 +1008,9 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): ''' with (yield from self.startup_lock): + # check if domain wasn't removed in the meantime + if self not in self.app.domains: + raise qubes.exc.QubesVMNotFoundError(self.name) # Intentionally not used is_running(): eliminate also "Paused", # "Crashed", "Halting" if self.get_power_state() != 'Halted':