Daniel P. Berrangé <[email protected]> writes:
> While the data recorder is designed to dump its contents in
> response to various signals that result in a QEMU crash, it
> is also interesting to explicitly request dump.
>
> This could be simply as an adhoc debugging activity, or could
> be in response to a specific event like a guest OS panic
> notification.
>
> Signed-off-by: Daniel P. Berrangé <[email protected]>
> ---
> MAINTAINERS | 1 +
> qapi/meson.build | 1 +
> qapi/qapi-schema.json | 1 +
> qapi/tldr.json | 28 ++++++++++++++++++++++++++++
> qemu-options.hx | 2 ++
> util/tldr.c | 32 ++++++++++++++++++++++++++++++++
> 6 files changed, 65 insertions(+)
> create mode 100644 qapi/tldr.json
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 4fa68810c1e..54265d987cb 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -4780,3 +4780,4 @@ F: util/tldr.c
> F: util/tldr-internal.h
> F: include/qemu/tldr.h
> F: tests/unit/test-util-tldr.c
> +F: qapi/tldr.json
> diff --git a/qapi/meson.build b/qapi/meson.build
> index a46269b5a0c..f8aecb61284 100644
> --- a/qapi/meson.build
> +++ b/qapi/meson.build
> @@ -49,6 +49,7 @@ qapi_all_modules = [
> 'run-state',
> 'sockets',
> 'stats',
> + 'tldr',
> 'trace',
> 'transaction',
> 'vfio',
> diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json
> index b93dd68d94c..b36777970d1 100644
> --- a/qapi/qapi-schema.json
> +++ b/qapi/qapi-schema.json
> @@ -76,3 +76,4 @@
> { 'include': 'cryptodev.json' }
> { 'include': 'cxl.json' }
> { 'include': 'uefi.json' }
> +{ 'include': 'tldr.json' }
> diff --git a/qapi/tldr.json b/qapi/tldr.json
> new file mode 100644
> index 00000000000..8e2b7cda324
> --- /dev/null
> +++ b/qapi/tldr.json
> @@ -0,0 +1,28 @@
> +# -*- Mode: Python -*-
> +# vim: filetype=python
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +
> +##
> +# @QTLDRDumpOptions:
> +# Options for `tldr-dump`.
> +#
> +# @target: the fully qualified file path to dump
> +# the data recorder to
We're not dumping the data recorder, we're dumping recorded data.
> +#
> +# Since: 11.2.0
> +##
> +{ 'struct': 'QTLDRDumpOptions',
> + 'data': { 'target': 'str' } }
> +
> +##
> +# @tldr-dump:
> +# Dump the data recorder to a file
> +#
> +# Since: 11.2.0
> +#
> +# .. qmp-example::
> +#
> +# -> { "execute": "tldr-dump", "arguments": { "target": "/tmp/qemu.txt"
> } }
> +# <- { "return": {} }
> +##
> +{ 'command': 'tldr-dump', 'data': 'QTLDRDumpOptions' }
Why do you use a separate type for the arguments?
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 2f63d86b635..5f96257cef0 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -6692,6 +6692,8 @@ SRST
> recorder will be dumped to the stderr stream. If the
> ``crash-target`` parameter was given, that specifies a fully
> qualified file path to write the dump to instead of stderr.
> + The ``tldr-dump`` QMP command can also be used at any time to
> + save the captured data to an arbitrary file.
>
> The ``tldr-config`` object can be added at initial startup
> or via QMP at runtime. Once created, however, it is not
> diff --git a/util/tldr.c b/util/tldr.c
> index 13e9881bc9b..ea7c26b8e9b 100644
> --- a/util/tldr.c
> +++ b/util/tldr.c
> @@ -12,6 +12,7 @@
> #include "qom/object.h"
> #include "qom/object_interfaces.h"
> #include "qapi/error.h"
> +#include "qapi/qapi-commands-tldr.h"
>
> struct QTLDRConfig {
> Object parent;
> @@ -436,3 +437,34 @@ qtldr_crash_dump_signal(siginfo_t *si)
> close(fd);
> }
> }
> +
> +
> +/*
> + * WARNING: Code below this marker provides a QMP handler
> + * WARNING: for use in normal execution. It calls into
> + * WARNING: the common crash report outputting APIs, but
> + * WARNING: this specific method is not restricted to async
> + * WARNING: signal safe POSIX functions.
> + */
Why is this a WARNING WARNING WARNING? Looks scary, then isn't.
Put it elsewhere, so the comment isn't needed?
> +
> +
> +void
> +qmp_tldr_dump(const char *target, Error **errp)
> +{
> + int fd;
> +
> + if (!qatomic_read(&qtldr_active)) {
> + error_setg(errp, "No 'tldr-config' object has been creted");
> + return;
> + }
> +
> + fd = qemu_create(target, O_WRONLY | O_TRUNC, 0600, errp);
> + if (fd < 0) {
> + return;
> + }
> +
> + qtldr_crash_dump_internal(fd, NULL);
> +
> + qemu_fdatasync(fd);
> + close(fd);
> +}