diff mbox series

[v8,13/13] qemu.py: don't launch again before shutdown()

Message ID 20170901112829.2571-14-apahim@redhat.com
State New
Headers show
Series scripts/qemu.py fixes and cleanups | expand

Commit Message

Amador Pahim Sept. 1, 2017, 11:28 a.m. UTC
If a VM is launched, files are created and a cleanup is required before
a new launch. This cleanup is executed by shutdown(), so shutdown() must
be called even if the VM is manually terminated (i.e. using kill).

This patch creates a control to make sure launch() will not be executed
again if shutdown() is not called after the previous launch().

Signed-off-by: Amador Pahim <apahim@redhat.com>
---
 scripts/qemu.py | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Fam Zheng Sept. 5, 2017, 3:22 a.m. UTC | #1
On Fri, 09/01 13:28, Amador Pahim wrote:
> If a VM is launched, files are created and a cleanup is required before
> a new launch. This cleanup is executed by shutdown(), so shutdown() must
> be called even if the VM is manually terminated (i.e. using kill).
> 
> This patch creates a control to make sure launch() will not be executed
> again if shutdown() is not called after the previous launch().
> 
> Signed-off-by: Amador Pahim <apahim@redhat.com>
> ---
>  scripts/qemu.py | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/scripts/qemu.py b/scripts/qemu.py
> index 363f649a7e..05fca4d268 100644
> --- a/scripts/qemu.py
> +++ b/scripts/qemu.py
> @@ -52,6 +52,7 @@ class QEMUMachine(object):
>          self._debug = debug
>          self._qemu_full_args = None
>          self._created_files = []
> +        self._pending_shutdown = False

The name is very poor, it can be confused as "user requested a shutdown but the
action is pending for some reason". Maybe "self._launched"?

Fam

>  
>      # This can be used to add an unused monitor instance.
>      def add_monitor_telnet(self, ip, port):
> @@ -168,10 +169,14 @@ class QEMUMachine(object):
>          if self.is_running():
>              raise QEMUMachineError('VM already running')
>  
> +        if self._pending_shutdown:
> +            raise QEMUMachineError('Shutdown pending after previous launch')
> +
>          self._iolog = None
>          self._qemu_full_args = None
>          try:
>              self._launch()
> +            self._pending_shutdown = True
>          except:
>              self.shutdown()
>  
> @@ -217,6 +222,8 @@ class QEMUMachine(object):
>                  command = ''
>              LOG.warn(msg, exitcode, command)
>  
> +        self._pending_shutdown = False
> +
>      underscore_to_dash = string.maketrans('_', '-')
>      def qmp(self, cmd, conv_keys=True, **args):
>          '''Invoke a QMP command and return the result dict'''
> -- 
> 2.13.5
> 
>
diff mbox series

Patch

diff --git a/scripts/qemu.py b/scripts/qemu.py
index 363f649a7e..05fca4d268 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -52,6 +52,7 @@  class QEMUMachine(object):
         self._debug = debug
         self._qemu_full_args = None
         self._created_files = []
+        self._pending_shutdown = False
 
     # This can be used to add an unused monitor instance.
     def add_monitor_telnet(self, ip, port):
@@ -168,10 +169,14 @@  class QEMUMachine(object):
         if self.is_running():
             raise QEMUMachineError('VM already running')
 
+        if self._pending_shutdown:
+            raise QEMUMachineError('Shutdown pending after previous launch')
+
         self._iolog = None
         self._qemu_full_args = None
         try:
             self._launch()
+            self._pending_shutdown = True
         except:
             self.shutdown()
 
@@ -217,6 +222,8 @@  class QEMUMachine(object):
                 command = ''
             LOG.warn(msg, exitcode, command)
 
+        self._pending_shutdown = False
+
     underscore_to_dash = string.maketrans('_', '-')
     def qmp(self, cmd, conv_keys=True, **args):
         '''Invoke a QMP command and return the result dict'''