From: Cleber Rosa <crosa@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: kwolf@redhat.com,
"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
qemu-devel@nongnu.org,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Aleksandar Markovic" <aleksandar.qemu.devel@gmail.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Aurelien Jarno" <aurelien@aurel32.net>
Subject: Re: [PATCH v5 10/12] python/machine.py: split shutdown into hard and soft flavors
Date: Tue, 14 Jul 2020 00:13:11 -0400 [thread overview]
Message-ID: <20200714041311.GH2983508@localhost.localdomain> (raw)
In-Reply-To: <20200710050649.32434-11-jsnow@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3712 bytes --]
On Fri, Jul 10, 2020 at 01:06:47AM -0400, John Snow wrote:
> This is done primarily to avoid the 'bare except' pattern, which
> suppresses all exceptions during shutdown and can obscure errors.
>
> Replace this with a pattern that isolates the different kind of shutdown
> paradigms (_hard_shutdown and _soft_shutdown), and a new fallback shutdown
> handler (_do_shutdown) that gracefully attempts one before the other.
>
> This split now also ensures that no matter what happens,
> _post_shutdown() is always invoked.
>
> shutdown() changes in behavior such that if it attempts to do a graceful
> shutdown and is unable to, it will now always raise an exception to
> indicate this. This can be avoided by the test writer in three ways:
>
> 1. If the VM is expected to have already exited or is in the process of
> exiting, wait() can be used instead of shutdown() to clean up resources
> instead. This helps avoid race conditions in shutdown.
>
> 2. If a test writer is expecting graceful shutdown to fail, shutdown
> should be called in a try...except block.
>
> 3. If the test writer has no interest in performing a graceful shutdown
> at all, kill() can be used instead.
>
>
> Handling shutdown in this way makes it much more explicit which type of
> shutdown we want and allows the library to report problems with this
> process.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> python/qemu/machine.py | 95 +++++++++++++++++++++++++++++++++++-------
> 1 file changed, 80 insertions(+), 15 deletions(-)
>
> diff --git a/python/qemu/machine.py b/python/qemu/machine.py
> index aaa173f046..b24ce8a268 100644
> --- a/python/qemu/machine.py
> +++ b/python/qemu/machine.py
> @@ -48,6 +48,12 @@ class QEMUMachineAddDeviceError(QEMUMachineError):
> """
>
>
> +class AbnormalShutdown(QEMUMachineError):
> + """
> + Exception raised when a graceful shutdown was requested, but not performed.
> + """
> +
> +
> class MonitorResponseError(qmp.QMPError):
> """
> Represents erroneous QMP monitor reply
> @@ -365,6 +371,7 @@ def _early_cleanup(self) -> None:
> """
> Perform any cleanup that needs to happen before the VM exits.
>
> + May be invoked by both soft and hard shutdown in failover scenarios.
> Called additionally by _post_shutdown for comprehensive cleanup.
> """
> # If we keep the console socket open, we may deadlock waiting
> @@ -374,32 +381,90 @@ def _early_cleanup(self) -> None:
> self._console_socket.close()
> self._console_socket = None
>
> + def _hard_shutdown(self) -> None:
> + """
> + Perform early cleanup, kill the VM, and wait for it to terminate.
> +
> + :raise subprocess.Timeout: When timeout is exceeds 60 seconds
> + waiting for the QEMU process to terminate.
> + """
> + self._early_cleanup()
Like I commented on patch 5, I don't think the *current* type of
cleanup done is needed on a scenario like this...
> + self._popen.kill()
... as I don't remember QEMU's SIGKILL handler to be susceptible to
the race condition that motivated the closing of the console file in
the first place. But, I also can not prove it's not susceptible at
this time.
Note: I have some old patches that added tests for QEMUMachine itself.
I intend to respin them on top of your work, so we may have a clearer
understanding of the QEMU behaviors we need to handle. So, feel free
to take the prudent route here, and keep the early cleanup.
Reviewed-by: Cleber Rosa <crosa@redhat.com>
Tested-by: Cleber Rosa <crosa@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-07-14 4:14 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-10 5:06 [PATCH v5 00/12] python/machine.py: refactor shutdown John Snow
2020-07-10 5:06 ` [PATCH v5 01/12] python/machine.py: consolidate _post_shutdown() John Snow
2020-07-13 15:11 ` Cleber Rosa
2020-07-13 17:23 ` Philippe Mathieu-Daudé
2020-07-10 5:06 ` [PATCH v5 02/12] python/machine.py: Close QMP socket in cleanup John Snow
2020-07-13 9:26 ` Philippe Mathieu-Daudé
2020-07-13 15:34 ` Cleber Rosa
2020-07-10 5:06 ` [PATCH v5 03/12] python/machine.py: Add _early_cleanup hook John Snow
2020-07-13 17:22 ` Philippe Mathieu-Daudé
2020-07-13 20:30 ` Cleber Rosa
2020-07-10 5:06 ` [PATCH v5 04/12] python/machine.py: Perform early cleanup for wait() calls, too John Snow
2020-07-13 17:24 ` Philippe Mathieu-Daudé
2020-07-13 20:31 ` Cleber Rosa
2020-07-10 5:06 ` [PATCH v5 05/12] python/machine.py: Prohibit multiple shutdown() calls John Snow
2020-07-13 9:27 ` Philippe Mathieu-Daudé
2020-07-14 2:48 ` Cleber Rosa
2020-07-14 18:09 ` John Snow
2020-07-14 18:47 ` John Snow
2020-07-10 5:06 ` [PATCH v5 06/12] python/machine.py: Add a configurable timeout to shutdown() John Snow
2020-07-13 9:28 ` Philippe Mathieu-Daudé
2020-07-14 2:50 ` Cleber Rosa
2020-07-10 5:06 ` [PATCH v5 07/12] python/machine.py: Make wait() call shutdown() John Snow
2020-07-13 9:29 ` Philippe Mathieu-Daudé
2020-07-14 3:05 ` Cleber Rosa
2020-07-10 5:06 ` [PATCH v5 08/12] tests/acceptance: wait() instead of shutdown() where appropriate John Snow
2020-07-13 9:57 ` Philippe Mathieu-Daudé
2020-07-14 3:37 ` Cleber Rosa
2020-07-10 5:06 ` [PATCH v5 09/12] tests/acceptance: Don't test reboot on cubieboard John Snow
2020-07-13 9:56 ` Philippe Mathieu-Daudé
2020-07-13 15:12 ` John Snow
2020-07-13 15:15 ` Philippe Mathieu-Daudé
2020-07-14 3:41 ` Cleber Rosa
2020-07-10 5:06 ` [PATCH v5 10/12] python/machine.py: split shutdown into hard and soft flavors John Snow
2020-07-13 9:54 ` Philippe Mathieu-Daudé
2020-07-14 4:13 ` Cleber Rosa [this message]
2020-07-14 18:13 ` John Snow
2020-07-14 19:10 ` Philippe Mathieu-Daudé
2020-07-10 5:06 ` [PATCH v5 11/12] python/machine.py: re-add sigkill warning suppression John Snow
2020-07-13 9:30 ` Philippe Mathieu-Daudé
2020-07-14 4:14 ` Cleber Rosa
2020-07-10 5:06 ` [PATCH v5 12/12] python/machine.py: change default wait timeout to 3 seconds John Snow
2020-07-13 9:30 ` Philippe Mathieu-Daudé
2020-07-14 4:20 ` Cleber Rosa
2020-07-14 18:15 ` John Snow
2020-07-14 19:17 ` [PATCH v5 00/12] python/machine.py: refactor shutdown Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200714041311.GH2983508@localhost.localdomain \
--to=crosa@redhat.com \
--cc=aleksandar.qemu.devel@gmail.com \
--cc=aleksandar.rikalo@syrmia.com \
--cc=aurelien@aurel32.net \
--cc=ehabkost@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wainersm@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).