Francesco Romani has uploaded a new change for review.

Change subject: vm: make destroy on startup return earlier
......................................................................

vm: make destroy on startup return earlier

Change-Id: I618eb03783d7059ae33d7b0a02542b99c8d8199b
Signed-off-by: Francesco Romani <from...@redhat.com>
---
M lib/api/vdsmapi-schema.json
M lib/vdsm/virt/vmexitreason.py
M vdsm/virt/vm.py
3 files changed, 24 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/51/55151/1

diff --git a/lib/api/vdsmapi-schema.json b/lib/api/vdsmapi-schema.json
index 0ab6136..6fa4c2a 100644
--- a/lib/api/vdsmapi-schema.json
+++ b/lib/api/vdsmapi-schema.json
@@ -7012,6 +7012,9 @@
 #
 # @libvirt domain missing:  Failed to find the libvirt domain for the VM
 #
+# @destroyed on startup:    VM destroyed during the startup
+#                           (New in version 4.18.0)
+#
 # Since: 4.15.0
 ##
 {'enum': 'VmExitReason',
@@ -7019,7 +7022,7 @@
           'lost qemu connection', 'libvirt start failed',
           'migration succeeded', 'save state succeeded',
           'admin shutdown', 'user shutdown', 'migration failed',
-          'libvirt domain missing']}
+          'libvirt domain missing', 'destroyed on startup']}
 
 ##
 # @ExitedVmStats:
diff --git a/lib/vdsm/virt/vmexitreason.py b/lib/vdsm/virt/vmexitreason.py
index 0aec0ce..d2962bc 100644
--- a/lib/vdsm/virt/vmexitreason.py
+++ b/lib/vdsm/virt/vmexitreason.py
@@ -29,6 +29,7 @@
 USER_SHUTDOWN = 7
 MIGRATION_FAILED = 8
 LIBVIRT_DOMAIN_MISSING = 9
+DESTROYED_ON_STARTUP = 10
 
 
 exitReasons = {
@@ -41,5 +42,6 @@
     ADMIN_SHUTDOWN: 'Admin shut down from the engine',
     USER_SHUTDOWN: 'User shut down from within the guest',
     MIGRATION_FAILED: 'VM failed to migrate',
-    LIBVIRT_DOMAIN_MISSING: 'Failed to find the libvirt domain'
+    LIBVIRT_DOMAIN_MISSING: 'Failed to find the libvirt domain',
+    DESTROYED_ON_STARTUP: 'VM destroyed during the startup'
 }
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 5950d1e..bf1bc70 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -90,6 +90,9 @@
 
 DEFAULT_BRIDGE = config.get("vars", "default_bridge")
 
+
+_DESTROY_ON_STARTUP_TIMEOUT = 30  # seconds
+
 # A libvirt constant for undefined cpu quota
 _NO_CPU_QUOTA = 0
 
@@ -190,6 +193,12 @@
         self.reason = reason
 
 
+class DestroyedOnStartupError(Exception):
+    """
+    Domain destroyed during startup process.
+    """
+
+
 class Vm(object):
     """
     Used for abstracting communication between various parts of the
@@ -247,6 +256,7 @@
         self.cif = cif
         self.log = SimpleLogAdapter(self.log, {"vmId": self.conf['vmId']})
         self._destroyed = threading.Event()
+        self._destroyRequested = threading.Event()
         self._recovery_file = recovery.File(self.conf['vmId'])
         self._monitorResponse = 0
         self.memCommitted = 0
@@ -749,6 +759,9 @@
         except MigrationError:
             self.log.exception("Failed to start a migration destination vm")
             self.setDownStatus(ERROR, vmexitreason.MIGRATION_FAILED)
+        except DestroyedOnStartupError:
+            self.log.info("Domain destroyed during startup")
+            self.setDownStatus(NORMAL, vmexitreason.DESTROYED_ON_STARTUP)
         except Exception as e:
             if self.recovering:
                 self.log.info("Skipping errors on recovery", exc_info=True)
@@ -1750,6 +1763,9 @@
                                    uuidPath, name)
 
     def _domDependentInit(self):
+        if self._destroyRequested.is_set():
+            raise DestroyedOnStartupError(vmexitreason.DESTROYED_ON_STARTUP)
+
         if not self._dom.connected:
             raise MissingLibvirtDomainError(vmexitreason.LIBVIRT_START_FAILED)
 
@@ -3881,6 +3897,7 @@
 
     def destroy(self):
         self.log.debug('destroy Called')
+        self._destroyRequested.set()
         if not self._created.wait(_DESTROY_STARTUP_TIMEOT):
             self.log.warning('VM still booting, timeout reached')
             return response.error('unavail')


-- 
To view, visit https://gerrit.ovirt.org/55151
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I618eb03783d7059ae33d7b0a02542b99c8d8199b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <from...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to