From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org,
"Philippe Mathieu-Daudé" <philmd@mailo.com>,
"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [PATCH v2 31/39] util: guard monitor_vprintf callers with CONFIG_HMP
Date: Mon, 10 Aug 2026 19:34:13 +0100 [thread overview]
Message-ID: <anoZpbLdNBtcUYbr@redhat.com> (raw)
In-Reply-To: <20260626-qemu-no-hmp-v2-31-8af31bc54c61@redhat.com>
On Fri, Jun 26, 2026 at 01:19:32AM +0400, Marc-André Lureau wrote:
> Guard calls to monitor_vprintf in error-report and qemu-print so
> they compile without HMP. When CONFIG_HMP is not set,
> error_vprintf_mon falls back directly to stderr and qemu_vfprintf
> returns -1 for NULL streams.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> tests/unit/test-util-sockets.c | 4 +++-
> tools/qemu-vnc/stubs.c | 2 ++
> util/error-report.c | 8 +++++---
> util/qemu-print.c | 6 ++++++
> 4 files changed, 16 insertions(+), 4 deletions(-)
This patch probably isn't required any more.
With the QOM classes for montior, monitor_vprintf calls to a 'vprintf'
class virtual method, or returns -1.
So simply by virtue of HMP being compiled out, monitor_vprintf should
do the right thing.
>
> diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c
> index b9f2453e299..23ebe1e26b5 100644
> --- a/tests/unit/test-util-sockets.c
> +++ b/tests/unit/test-util-sockets.c
> @@ -73,8 +73,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
> */
> Monitor *monitor_cur(void) { return cur_mon; }
> Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); }
> -int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
> bool monitor_cur_is_qmp(void) { abort(); };
> +#ifdef CONFIG_HMP
> +int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
> +#endif
>
> #ifndef _WIN32
> static void test_socket_fd_pass_name_good(void)
> diff --git a/tools/qemu-vnc/stubs.c b/tools/qemu-vnc/stubs.c
> index a865ce85f04..f476dd6d956 100644
> --- a/tools/qemu-vnc/stubs.c
> +++ b/tools/qemu-vnc/stubs.c
> @@ -46,10 +46,12 @@ Monitor *monitor_set_cur(Coroutine *co, Monitor *mon)
> return NULL;
> }
>
> +#ifdef CONFIG_HMP
> int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
> {
> return -1;
> }
> +#endif
>
> /*
> * Link-time stubs for VMState symbols referenced by VNC code.
> diff --git a/util/error-report.c b/util/error-report.c
> index f832ad9b6b6..e2e46281455 100644
> --- a/util/error-report.c
> +++ b/util/error-report.c
> @@ -40,11 +40,13 @@ error_vprintf_mon(Monitor *cur_mon, const char *fmt, va_list ap)
> * IOW this will only print if in HMP, otherwise we
> * fallback to stderr for QMP / no-monitor scenarios.
> */
> +#ifdef CONFIG_HMP
> int ret = monitor_vprintf(cur_mon, fmt, ap);
> - if (ret == -1) {
> - ret = vfprintf(stderr, fmt, ap);
> + if (ret != -1) {
> + return ret;
> }
> - return ret;
> +#endif
> + return vfprintf(stderr, fmt, ap);
> }
>
> /*
> diff --git a/util/qemu-print.c b/util/qemu-print.c
> index 7b9591035e5..ee80000722b 100644
> --- a/util/qemu-print.c
> +++ b/util/qemu-print.c
> @@ -20,10 +20,12 @@
> */
> int qemu_vprintf(const char *fmt, va_list ap)
> {
> +#ifdef CONFIG_HMP
> Monitor *cur_mon = monitor_cur();
> if (cur_mon) {
> return monitor_vprintf(cur_mon, fmt, ap);
> }
> +#endif
> return vprintf(fmt, ap);
> }
>
> @@ -52,7 +54,11 @@ int qemu_printf(const char *fmt, ...)
> int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap)
> {
> if (!stream) {
> +#ifdef CONFIG_HMP
> return monitor_vprintf(monitor_cur(), fmt, ap);
> +#else
> + return -1;
> +#endif
> }
> return vfprintf(stream, fmt, ap);
> }
>
> --
> 2.54.0
>
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
next prev parent reply other threads:[~2026-08-10 18:35 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-25 21:19 [PATCH v2 00/39] Make HMP optional (and later standalone) Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 01/39] vl: fix -monitor none prefix matching Marc-André Lureau
2026-08-10 17:30 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 02/39] hmp: remove 'vcpu' argument from trace-event help Marc-André Lureau
2026-08-10 17:31 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 03/39] hmp: fix snapshot_blkdev argument type Marc-André Lureau
2026-08-10 17:35 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 04/39] target/i386: decouple cpu_x86_inject_mce() from Monitor Marc-André Lureau
2026-08-10 17:40 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 05/39] target/i386: return an error for invalid CPU in hmp_mce() Marc-André Lureau
2026-08-10 17:42 ` Daniel P. Berrangé
2026-08-10 20:16 ` Philippe Mathieu-Daudé
2026-06-25 21:19 ` [PATCH v2 06/39] system: move gpa2hva() to system memory unit Marc-André Lureau
2026-08-10 17:44 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 07/39] s390x: prevent crash if given invalid CPU# Marc-André Lureau
2026-08-10 17:44 ` Daniel P. Berrangé
2026-08-10 21:01 ` Philippe Mathieu-Daudé
2026-06-25 21:19 ` [PATCH v2 08/39] system: decouple qmp_inject_nmi() from Monitor Marc-André Lureau
2026-08-10 17:48 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 09/39] hmp: correct the nmi documentation Marc-André Lureau
2026-08-10 17:51 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 10/39] monitor: move HMP-only fields from Monitor to MonitorHMP Marc-André Lureau
2026-08-10 17:54 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 11/39] tests/functional: use query-version QMP command instead of HMP Marc-André Lureau
2026-08-10 17:54 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 12/39] net/qapi: add x-query-usernet command Marc-André Lureau
2026-08-10 17:56 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 13/39] python, tests: switch usernet queries from HMP to QMP Marc-André Lureau
2026-08-10 18:00 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 14/39] tests/qtest/pnv: drop unnecessary -serial mon:stdio Marc-André Lureau
2026-08-10 18:01 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 15/39] tests/qtest/qmp-test: don't depend on human-monitor-command Marc-André Lureau
2026-08-10 18:03 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 16/39] tests/qtest/numa-test: replace HMP "info numa" with QMP query-cpus-fast Marc-André Lureau
2026-08-10 18:04 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 17/39] tests/qtest/cdrom-test: replace HMP "info block" with QMP query-block Marc-André Lureau
2026-08-10 18:05 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 18/39] tests/qtest/device-introspect-test: fix test without HMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 19/39] tests/qemu-iotests/205: fix race in assertExportNotFound Marc-André Lureau
2026-08-10 18:15 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 20/39] net: add x-query-network QMP command Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 21/39] tests/qtest/netdev-socket: replace HMP with x-query-network QMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 22/39] qemu-io: propagate errors through Error API instead of printf Marc-André Lureau
2026-08-10 18:19 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 23/39] RFC: qtest: add qemu-io command to the qtest protocol Marc-André Lureau
2026-08-10 18:22 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 24/39] RFC: qtest/ide-test: convert to use qtest qemu-io command Marc-André Lureau
2026-08-10 18:22 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 25/39] block: add x-qemu-io QMP command Marc-André Lureau
2026-08-10 18:26 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 26/39] tests/qemu-iotests: add qmp_qemu_io() Marc-André Lureau
2026-08-10 18:24 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 27/39] tests/qemu-iotests: convert pause/resume_drive() to QMP Marc-André Lureau
2026-08-10 18:26 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 28/39] build-sys: add 'hmp' option Marc-André Lureau
2026-08-10 18:27 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 29/39] monitor: reject readline monitor when HMP is disabled Marc-André Lureau
2026-08-10 18:28 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 30/39] tests: skip HMP-dependent tests " Marc-André Lureau
2026-08-10 18:29 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 31/39] util: guard monitor_vprintf callers with CONFIG_HMP Marc-André Lureau
2026-08-10 18:34 ` Daniel P. Berrangé [this message]
2026-06-25 21:19 ` [PATCH v2 32/39] qapi: make HMP-specific schema entries conditional on CONFIG_HMP Marc-André Lureau
2026-08-10 18:35 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 33/39] system: guard HMP initialization paths with CONFIG_HMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 34/39] Guard HMP command implementations " Marc-André Lureau
2026-08-10 18:36 ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 35/39] target: guard MonitorDef tables " Marc-André Lureau
2026-08-10 21:44 ` Philippe Mathieu-Daudé
2026-06-25 21:19 ` [PATCH v2 36/39] hw: guard BusClass::print_dev " Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 37/39] build-sys: make HMP source files conditional on have_hmp Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 38/39] monitor: guard HMP internal helpers with CONFIG_HMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 39/39] monitor: guard HMP monitor API " Marc-André Lureau
2026-08-10 21:49 ` [PATCH v2 00/39] Make HMP optional (and later standalone) 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=anoZpbLdNBtcUYbr@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=philmd@mailo.com \
--cc=qemu-devel@nongnu.org \
/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.