From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Richard W.M. Jones" <rjones@redhat.com>
Cc: qemu-devel@nongnu.org, lvivier@redhat.com, farosas@suse.de,
pbonzini@redhat.com
Subject: Re: [PATCH v2 1/2] Implement -run-with exit-with-parent=on
Date: Fri, 10 Oct 2025 11:09:04 +0100 [thread overview]
Message-ID: <aOjbQITMTLHSXEYo@redhat.com> (raw)
In-Reply-To: <20251009161526.140497-2-rjones@redhat.com>
On Thu, Oct 09, 2025 at 05:12:46PM +0100, Richard W.M. Jones wrote:
> Libguestfs wants to use qemu to run a captive appliance. When the
> program linked to libguestfs exits, we want qemu to be cleaned up.
> Libguestfs goes to great lengths to do this at the moment: it either
> forks a separate process to ensure clean-up is done, or it asks
> libvirt to clean up the qemu process. However this is complicated and
> not totally reliable.
>
> On Linux, FreeBSD and macOS, there are mechanisms to ensure a signal
> or message is delivered to a process when its parent process goes
> away. The qemu test suite even uses this mechanism on Linux (see
> PR_SET_PDEATHSIG in tests/qtest/libqtest.c).
>
> In nbdkit we have long had the concept of running nbdkit captively,
> and we have the nbdkit --exit-with-parent flag to help
> (https://libguestfs.org/nbdkit-captive.1.html#EXIT-WITH-PARENT)
>
> This commit adds the same mechanism. The syntax is:
>
> qemu -run-with exit-with-parent=on [...]
>
> This is not a feature that most typical users of qemu (for running
> general purpose, long-lived VMs) should use, so it defaults to off.
>
> The exit-with-parent.[ch] files are copied from nbdkit, where they
> have a 3-clause BSD license which is compatible with qemu:
>
> https://gitlab.com/nbdkit/nbdkit/-/tree/master/common/utils?ref_type=heads
>
> Thanks: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> ---
> include/qemu/exit-with-parent.h | 57 +++++++++++++
> qemu-options.hx | 13 ++-
> system/exit-with-parent.c | 140 ++++++++++++++++++++++++++++++++
> system/meson.build | 1 +
> system/vl.c | 13 +++
> 5 files changed, 222 insertions(+), 2 deletions(-)
>
> diff --git a/include/qemu/exit-with-parent.h b/include/qemu/exit-with-parent.h
> new file mode 100644
> index 0000000000..c00b863fe9
> --- /dev/null
> +++ b/include/qemu/exit-with-parent.h
> @@ -0,0 +1,57 @@
snip
> +
> +#ifndef NBDKIT_EXIT_WITH_PARENT_H
> +#define NBDKIT_EXIT_WITH_PARENT_H
I'd suggest s/NBDKIT/QEMU/ here & at the end
> +
> +/* Test if the feature is available on the platform. */
> +static inline bool can_exit_with_parent(void)
> +{
> +#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
> + return true;
> +#else
> + return false;
> +#endif
> +}
> +
> +/*
> + * --exit-with-parent: kill the current process if the parent exits.
> + * This may return -1 on error.
> + *
> + * Note this will abort on platforms where can_exit_with_parent()
> + * returned false.
> + */
> +extern int set_exit_with_parent(void);
> +
> +#endif /* NBDKIT_EXIT_WITH_PARENT_H */
With that minor change
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2025-10-10 10:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-09 16:12 [PATCH v2 0/2] Implement -run-with exit-with-parent=on Richard W.M. Jones
2025-10-09 16:12 ` [PATCH v2 1/2] " Richard W.M. Jones
2025-10-10 10:09 ` Daniel P. Berrangé [this message]
2026-05-18 16:49 ` Thomas Huth
2026-05-18 16:54 ` Richard W.M. Jones
2026-05-18 17:18 ` Thomas Huth
2026-05-18 17:00 ` Richard W.M. Jones
2025-10-09 16:12 ` [PATCH v2 2/2] tests/qtest: Use exit-with-parent=on in qtest invocations Richard W.M. Jones
2025-10-10 10:10 ` Daniel P. Berrangé
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=aOjbQITMTLHSXEYo@redhat.com \
--to=berrange@redhat.com \
--cc=farosas@suse.de \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rjones@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.