소스 검색

vm/dispvm: cleanup DispVM also on failed startup

If dispvm.auto_cleanup is set, cleanup it also after failed startup
(like not enough memory).

Fixes QubesOS/qubes-issues#3045
Marek Marczykowski-Górecki 6 년 전
부모
커밋
e38e227503
1개의 변경된 파일16개의 추가작업 그리고 7개의 파일을 삭제
  1. 16 7
      qubes/vm/dispvm.py

+ 16 - 7
qubes/vm/dispvm.py

@@ -137,7 +137,7 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
         '''
         with (yield from self.startup_lock):
             yield from self.storage.stop()
-            if self.auto_cleanup:
+            if self.auto_cleanup and self in self.app.domains:
                 yield from self.remove_from_disk()
                 del self.app.domains[self]
                 self.app.save()
@@ -197,10 +197,19 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
     def start(self, **kwargs):
         # pylint: disable=arguments-differ
 
-        # sanity check, if template_for_dispvm got changed in the meantime
-        if not self.template.template_for_dispvms:
-            raise qubes.exc.QubesException(
-                'template for DispVM ({}) needs to have '
-                'template_for_dispvms=True'.format(self.template.name))
+        try:
+            # sanity check, if template_for_dispvm got changed in the meantime
+            if not self.template.template_for_dispvms:
+                raise qubes.exc.QubesException(
+                    'template for DispVM ({}) needs to have '
+                    'template_for_dispvms=True'.format(self.template.name))
 
-        yield from super(DispVM, self).start(**kwargs)
+            yield from super(DispVM, self).start(**kwargs)
+        except:
+            # cleanup also on failed startup; there is potential race with
+            # self.on_domain_shutdown_coro, so check if wasn't already removed
+            if self.auto_cleanup and self in self.app.domains:
+                yield from self.remove_from_disk()
+                del self.app.domains[self]
+                self.app.save()
+            raise