On Fri, Jun 26, 2026 at 01:19:24AM +0400, Marc-André Lureau wrote:
> Add a "qemu-io" command to the qtest protocol so that tests can issue
> block layer I/O commands without going through the HMP monitor's
> "human-monitor-command" QMP, or use QMP at all.
> 
> Unfortunately, many tests will prefer to use QMP as they also monitor
> and log other events. It's easier if it is pipelined in the same stream.
> 
> Signed-off-by: Marc-André Lureau <[email protected]>
> ---
>  tests/qtest/libqtest.h | 11 +++++++++++
>  system/qtest.c         | 14 ++++++++++++++
>  tests/qtest/libqtest.c | 14 ++++++++++++++
>  3 files changed, 39 insertions(+)
> 
> diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
> index 45217fb8dc0..58491ca53ab 100644
> --- a/tests/qtest/libqtest.h
> +++ b/tests/qtest/libqtest.h
> @@ -424,6 +424,17 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...) 
> G_GNUC_PRINTF(2, 3);
>  char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
>      G_GNUC_PRINTF(2, 0);
>  
> +/**
> + * qtest_qemu_io:
> + * @s: #QTestState instance to operate on.
> + * @device: block device node-name or BlockBackend name.
> + * @fmt: qemu-io command to send, formats arguments like sprintf().
> + *
> + * Send a qemu-io command via the qtest protocol.
> + */
> +void qtest_qemu_io(QTestState *s, const char *device,
> +                   const char *fmt, ...) G_GNUC_PRINTF(3, 4);
> +
>  void qtest_module_load(QTestState *s, const char *prefix, const char 
> *libname);
>  
>  /**
> diff --git a/system/qtest.c b/system/qtest.c
> index fd37bcbfaab..f7f2636854b 100644
> --- a/system/qtest.c
> +++ b/system/qtest.c
> @@ -33,6 +33,7 @@
>  #include "qom/object_interfaces.h"
>  #include "qom/qom-qobject.h"
>  #include "qobject/qobject.h"
> +#include "qapi-commands-block.h"
>  
>  #define MAX_IRQ 256
>  
> @@ -800,6 +801,19 @@ static void qtest_process_command(CharFrontend *chr, 
> gchar **words)
>          }
>          g_slist_free(list);
>          qtest_send(chr, "OK\n");
> +    } else if (strcmp(words[0], "qemu-io") == 0) {
> +        const char *io_dev;
> +        g_autofree char *io_cmd = NULL;
> +        Error *err = NULL;
> +
> +        g_assert(words[1] && words[2]);
> +        io_dev = words[1];
> +        io_cmd = g_strjoinv(" ", &words[2]);
> +
> +        qmp_x_qemu_io(io_dev, NULL, io_cmd, &err);

This function isn't defined until patch 25 AFAICT, so need to re-order.

> +        qtest_sendf(chr, err ? "FAIL %s\n" : "OK\n",
> +                    err ? error_get_pretty(err) : NULL);
> +        error_free(err);
>      } else if (process_command_cb && process_command_cb(chr, words)) {
>          /* Command got consumed by the callback handler */
>      } else {
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 4e22c66b754..eccffd3a0c2 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -1012,6 +1012,20 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...)
>      return ret;
>  }
>  
> +void qtest_qemu_io(QTestState *s, const char *device,
> +                   const char *fmt, ...)
> +{
> +    va_list ap;
> +    g_autofree char *cmd = NULL;
> +
> +    va_start(ap, fmt);
> +    cmd = g_strdup_vprintf(fmt, ap);
> +    va_end(ap);
> +
> +    qtest_sendf(s, "qemu-io %s %s\n", device, cmd);
> +    qtest_rsp(s);
> +}
> +
>  const char *qtest_get_arch(void)
>  {
>      /*
> 
> -- 
> 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 :|


Reply via email to