[Qemu-devel] [PATCH v7 09/11] qemu.py: launch vm only if it's not running

Amador Pahim posted 11 patches 8 years, 5 months ago
There is a newer version of this series
[Qemu-devel] [PATCH v7 09/11] qemu.py: launch vm only if it's not running
Posted by Amador Pahim 8 years, 5 months ago
A new call to launch() with a running VM will fall in exception and
consequently call shutdown().

This patch makes launch() to raise an exception when it's called with VM
already running.

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

diff --git a/scripts/qemu.py b/scripts/qemu.py
index 9ae65e454e..46e8ff3232 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -170,6 +170,9 @@ class QEMUMachine(object):
         self._iolog = None
         self._qemu_full_args = None
         devnull = open(os.path.devnull, 'rb')
+        if self.is_running():
+            raise QEMULaunchError('VM already running')
+
         try:
             self._pre_launch()
             self._qemu_full_args = (self._wrapper + [self._binary] +
-- 
2.13.5


Re: [Qemu-devel] [PATCH v7 09/11] qemu.py: launch vm only if it's not running
Posted by Fam Zheng 8 years, 5 months ago
On Fri, 08/18 19:05, Amador Pahim wrote:
> A new call to launch() with a running VM will fall in exception and
> consequently call shutdown().
> 
> This patch makes launch() to raise an exception when it's called with VM
> already running.
> 
> Signed-off-by: Amador Pahim <apahim@redhat.com>
> ---
>  scripts/qemu.py | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/scripts/qemu.py b/scripts/qemu.py
> index 9ae65e454e..46e8ff3232 100644
> --- a/scripts/qemu.py
> +++ b/scripts/qemu.py
> @@ -170,6 +170,9 @@ class QEMUMachine(object):
>          self._iolog = None
>          self._qemu_full_args = None
>          devnull = open(os.path.devnull, 'rb')
> +        if self.is_running():
> +            raise QEMULaunchError('VM already running')
> +
>          try:
>              self._pre_launch()
>              self._qemu_full_args = (self._wrapper + [self._binary] +
> -- 
> 2.13.5
> 

Reviewed-by: Fam Zheng <famz@redhat.com>