From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Daniel Xu <dxu@dxuuu.xyz>
Cc: kkostiuk@redhat.com, michael.roth@amd.com,
marcandre.lureau@gmail.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v4 1/3] qga: Refactor guest-exec capture-output to take enum
Date: Thu, 9 Mar 2023 09:29:34 +0000 [thread overview]
Message-ID: <ZAmm/p8t39c0b9XN@redhat.com> (raw)
In-Reply-To: <59f4f17ac2cbe719fa4f571a1c373c36597b12a3.1678314204.git.dxu@dxuuu.xyz>
On Wed, Mar 08, 2023 at 03:49:39PM -0700, Daniel Xu wrote:
> Previously capture-output was an optional boolean flag that either
> captured all output or captured none. While this is OK in most cases, it
> lacks flexibility for more advanced capture cases, such as wanting to
> only capture stdout.
>
> This commits refactors guest-exec qapi to take an enum for capture mode
> instead while preserving backwards compatibility.
>
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> ---
> qga/commands.c | 37 ++++++++++++++++++++++++++++++++++---
> qga/qapi-schema.json | 32 +++++++++++++++++++++++++++++++-
> 2 files changed, 65 insertions(+), 4 deletions(-)
>
> diff --git a/qga/commands.c b/qga/commands.c
> index 172826f8f8..5504fc5b8c 100644
> --- a/qga/commands.c
> +++ b/qga/commands.c
> @@ -379,11 +379,23 @@ close:
> return false;
> }
>
> +static GuestExecCaptureOutputMode ga_parse_capture_output(
> + GuestExecCaptureOutput *capture_output)
> +{
> + if (!capture_output)
> + return GUEST_EXEC_CAPTURE_OUTPUT_MODE_NONE;
> + else if (capture_output->type == QTYPE_QBOOL)
> + return capture_output->u.flag ? GUEST_EXEC_CAPTURE_OUTPUT_MODE_ALL
> + : GUEST_EXEC_CAPTURE_OUTPUT_MODE_NONE;
> + else
> + return capture_output->u.mode;
> +}
> +
> GuestExec *qmp_guest_exec(const char *path,
> bool has_arg, strList *arg,
> bool has_env, strList *env,
> const char *input_data,
> - bool has_capture_output, bool capture_output,
> + GuestExecCaptureOutput *capture_output,
> Error **errp)
> {
> GPid pid;
> @@ -396,7 +408,8 @@ GuestExec *qmp_guest_exec(const char *path,
> gint in_fd, out_fd, err_fd;
> GIOChannel *in_ch, *out_ch, *err_ch;
> GSpawnFlags flags;
> - bool has_output = (has_capture_output && capture_output);
> + bool has_output = false;
> + GuestExecCaptureOutputMode output_mode;
> g_autofree uint8_t *input = NULL;
> size_t ninput = 0;
>
> @@ -415,8 +428,26 @@ GuestExec *qmp_guest_exec(const char *path,
>
> flags = G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD |
> G_SPAWN_SEARCH_PATH_FROM_ENVP;
> - if (!has_output) {
> +
> + output_mode = ga_parse_capture_output(capture_output);
> + switch (output_mode) {
> + case GUEST_EXEC_CAPTURE_OUTPUT_MODE_NONE:
> flags |= G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL;
> + break;
> + case GUEST_EXEC_CAPTURE_OUTPUT_MODE_STDOUT:
> + has_output = true;
> + flags |= G_SPAWN_STDERR_TO_DEV_NULL;
> + break;
> + case GUEST_EXEC_CAPTURE_OUTPUT_MODE_STDERR:
> + has_output = true;
> + flags |= G_SPAWN_STDOUT_TO_DEV_NULL;
> + break;
> + case GUEST_EXEC_CAPTURE_OUTPUT_MODE_ALL:
> + has_output = true;
> + break;
> + case GUEST_EXEC_CAPTURE_OUTPUT_MODE__MAX:
> + /* Silence warning; impossible branch */
> + break;
> }
>
> ret = g_spawn_async_with_pipes(NULL, argv, envp, flags,
> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> index 796434ed34..4ef585da5d 100644
> --- a/qga/qapi-schema.json
> +++ b/qga/qapi-schema.json
> @@ -1200,6 +1200,36 @@
> { 'struct': 'GuestExec',
> 'data': { 'pid': 'int'} }
>
> +##
> +# @GuestExecCaptureOutputMode:
> +#
> +# An enumeration of guest-exec capture modes.
> +#
> +# @none: do not capture any output
> +# @stdout: only capture stdout
> +# @stderr: only capture stderr
> +# @all: capture both stdout and stderr
Functionally fine. A minor naming thought.... How about we call
this '@separated' and tweak the docs
@separated: capture both stdout and stderr separately
Then in your in next patch you introduce
@merged: capture both stdout and stderr merged
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:[~2023-03-09 9:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-08 22:49 [PATCH v4 0/3] qga: Support merging output streams in guest-exec Daniel Xu
2023-03-08 22:49 ` [PATCH v4 1/3] qga: Refactor guest-exec capture-output to take enum Daniel Xu
2023-03-09 9:29 ` Daniel P. Berrangé [this message]
2023-03-09 16:50 ` Daniel Xu
2023-03-08 22:49 ` [PATCH v4 2/3] qga: Add `all-merge` variant to GuestExecCaptureOutputMode Daniel Xu
2023-03-08 22:49 ` [PATCH v4 3/3] qga: test: Add tests for `all-merge` flag Daniel Xu
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=ZAmm/p8t39c0b9XN@redhat.com \
--to=berrange@redhat.com \
--cc=dxu@dxuuu.xyz \
--cc=kkostiuk@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=michael.roth@amd.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 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).