diff mbox series

[v2,18/22] python/qemu/machine: add kill() method

Message ID 20200217150246.29180-19-vsementsov@virtuozzo.com
State New
Headers show
Series Fix error handling during bitmap postcopy | expand

Commit Message

Vladimir Sementsov-Ogievskiy Feb. 17, 2020, 3:02 p.m. UTC
Add method to hard-kill vm, without any quit commands.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 python/qemu/machine.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Andrey Shinkevich Feb. 19, 2020, 5 p.m. UTC | #1
On 17/02/2020 18:02, Vladimir Sementsov-Ogievskiy wrote:
> Add method to hard-kill vm, without any quit commands.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>   python/qemu/machine.py | 12 +++++++++---
>   1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/python/qemu/machine.py b/python/qemu/machine.py
> index 183d8f3d38..9918e0d8aa 100644
> --- a/python/qemu/machine.py
> +++ b/python/qemu/machine.py
> @@ -341,7 +341,7 @@ class QEMUMachine(object):
>           self._load_io_log()
>           self._post_shutdown()
>   
> -    def shutdown(self, has_quit=False):
> +    def shutdown(self, has_quit=False, hard=False):
>           """
>           Terminate the VM and clean up
>           """
> @@ -353,7 +353,9 @@ class QEMUMachine(object):
>               self._console_socket = None
>   
>           if self.is_running():
> -            if self._qmp:
> +            if hard:
> +                self._popen.kill()
> +            elif self._qmp:
>                   try:
>                       if not has_quit:
>                           self._qmp.cmd('quit')
> @@ -366,7 +368,8 @@ class QEMUMachine(object):
>           self._post_shutdown()
>   
>           exitcode = self.exitcode()
> -        if exitcode is not None and exitcode < 0:
> +        if exitcode is not None and exitcode < 0 and \
> +                not (exitcode == -9 and hard):
>               msg = 'qemu received signal %i: %s'
>               if self._qemu_full_args:
>                   command = ' '.join(self._qemu_full_args)
> @@ -376,6 +379,9 @@ class QEMUMachine(object):
>   
>           self._launched = False
>   
> +    def kill(self):
> +        self.shutdown(hard=True)
> +
>       def set_qmp_monitor(self, enabled=True):
>           """
>           Set the QMP monitor.
> 

It would be reasonable to number this patch the last but one, that's 
right before a usage in the patch that follows.

Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Philippe Mathieu-Daudé May 29, 2020, 10:09 a.m. UTC | #2
On 2/17/20 4:02 PM, Vladimir Sementsov-Ogievskiy wrote:
> Add method to hard-kill vm, without any quit commands.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  python/qemu/machine.py | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)

Thanks, applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next
diff mbox series

Patch

diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 183d8f3d38..9918e0d8aa 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -341,7 +341,7 @@  class QEMUMachine(object):
         self._load_io_log()
         self._post_shutdown()
 
-    def shutdown(self, has_quit=False):
+    def shutdown(self, has_quit=False, hard=False):
         """
         Terminate the VM and clean up
         """
@@ -353,7 +353,9 @@  class QEMUMachine(object):
             self._console_socket = None
 
         if self.is_running():
-            if self._qmp:
+            if hard:
+                self._popen.kill()
+            elif self._qmp:
                 try:
                     if not has_quit:
                         self._qmp.cmd('quit')
@@ -366,7 +368,8 @@  class QEMUMachine(object):
         self._post_shutdown()
 
         exitcode = self.exitcode()
-        if exitcode is not None and exitcode < 0:
+        if exitcode is not None and exitcode < 0 and \
+                not (exitcode == -9 and hard):
             msg = 'qemu received signal %i: %s'
             if self._qemu_full_args:
                 command = ' '.join(self._qemu_full_args)
@@ -376,6 +379,9 @@  class QEMUMachine(object):
 
         self._launched = False
 
+    def kill(self):
+        self.shutdown(hard=True)
+
     def set_qmp_monitor(self, enabled=True):
         """
         Set the QMP monitor.