qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v7 04/11] qemu.py: use poll() instead of 'return


From: Eduardo Habkost
Subject: Re: [Qemu-devel] [PATCH v7 04/11] qemu.py: use poll() instead of 'returncode'
Date: Wed, 30 Aug 2017 18:10:52 -0300
User-agent: Mutt/1.8.3 (2017-05-23)

On Fri, Aug 18, 2017 at 07:05:19PM +0200, Amador Pahim wrote:
> The 'returncode' Popen attribute is not guaranteed to be updated. It
> actually depends on a call to either poll(), wait() or communicate().
> 
> On the other hand, poll() will: "Check if child process has terminated.
> Set and return returncode attribute."
> 
> Let's use the poll() to check whether the process is running and also
> to get the updated process exit code, when the process is finished.
> 
> As consequence, the shutdown() calls to self._load_io_log()
> self._post_shutdown() are now always executed to make sure we cleanup
> even if VM is not running when the shutdown() is called.

I suggest moving the shutdown() changes to a separate patch.

> 
> Signed-off-by: Amador Pahim <address@hidden>
> ---
>  scripts/qemu.py | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/scripts/qemu.py b/scripts/qemu.py
> index 51545f7f97..774f971f69 100644
> --- a/scripts/qemu.py
> +++ b/scripts/qemu.py
> @@ -98,12 +98,12 @@ class QEMUMachine(object):
>              raise
>  
>      def is_running(self):
> -        return self._popen is not None and self._popen.returncode is None
> +        return self._popen is not None and self._popen.poll() is None
>  
>      def exitcode(self):
>          if self._popen is None:
>              return None
> -        return self._popen.returncode
> +        return self._popen.poll()
>  
>      def get_pid(self):
>          if not self.is_running():
> @@ -111,8 +111,15 @@ class QEMUMachine(object):
>          return self._popen.pid
>  
>      def _load_io_log(self):
> -        with open(self._qemu_log_path, "r") as fh:
> -            self._iolog = fh.read()
> +        '''
> +        Load the Qemu log file content (if available) into the proper
> +        instance variable
> +        '''
> +        try:
> +            with open(self._qemu_log_path, "r") as fh:
> +                self._iolog = fh.read()
> +        except IOError:
> +            pass

Is this really supposed to be included in this patch?  This
change in the _load_io_log() behavior is the most dangerous part
of this patch, and not described in the commit message at all.

I don't think it's a good idea to remove errors unconditionally
here.  The launch() code controls of the creation of the log file
completely, we don't even need to try to load the file if we know
it was not created yet.


>  
>      def _base_args(self):
>          if isinstance(self._monitor_address, tuple):
> @@ -168,8 +175,8 @@ class QEMUMachine(object):
>              if exitcode < 0:
>                  LOG.debug('qemu received signal %i: %s', -exitcode,
>                            ' '.join(self._args))
> -            self._load_io_log()
> -            self._post_shutdown()
> +        self._load_io_log()
> +        self._post_shutdown()
>  
>      underscore_to_dash = string.maketrans('_', '-')
>      def qmp(self, cmd, conv_keys=True, **args):
> -- 
> 2.13.5
> 
> 

-- 
Eduardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]