Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge tag 'qga-pull-2023-05-04' of https://github.com/kostyanf14/qemu
…into staging

qga-pull-2023-05-04

# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCgAdFiEEwsLBCepDxjwUI+uE711egWG6hOcFAmRTf4EACgkQ711egWG6
# hOdczhAAoMkw/bWZtpiEmeLIcliNVuF3gzouHRp2sBFeHCUtaE2jzmriuy4QqH81
# G+kgqdEogqv7G5Qq2LXNcbSl76eZnKbumtlj+N4XIDoukPWUmItIjuM9NYM0U84Y
# DAsj6o8Kw1W+GMBmk6AuLFNYMwv41GS6RyvH/daeYEGmFf0jYIARpeldTUxkxY86
# dfEylVPBfLjkctKfgl0h5GzRkYjmxyeisyigx4Wk8sVLvz5LLXx27sFVZ7//Rn16
# 7Ca88kzF9SUenF+ulV0HmVgR02b69w74izVII/Hh3pPkv4T2m98DeXlnHdyuc3Lb
# bWggM2pf1Yr/jUOPtscQ9IqKTdYTLKqaErVSQJYabG9lLXRerXLj8mhH/W070jzT
# hZwp+5VJzF/OykiM0PW/tI5a0Upg8/8w/LRPwuqP0nFsW5QYdAQXSFbtsUfVdPlE
# Htk66xoQTLJ2a38m5WCvaRL97psGHmVXuWq0VUByNCAlWv6EiAAbTZBimIo4FZj+
# Ps6e7Tnvhv5kai2qZ4ijxJq88n9/mv8t0s/oD/BoGQMXmNn+87bR18byY5NZWi/4
# CKk60zbmgo8fGZ/zzwk4T+48I3SLfM+wnHePYs8nrHgoqGVEUXsCdXUYifxIcpel
# Vnb1OHXN3n+U8LnleQ158oQcSVFicvwQMBkzM+mW16WMQlReRRM=
# =GvNm
# -----END PGP SIGNATURE-----
# gpg: Signature made Thu 04 May 2023 10:48:49 AM BST
# gpg:                using RSA key C2C2C109EA43C63C1423EB84EF5D5E8161BA84E7
# gpg: Good signature from "Kostiantyn Kostiuk (Upstream PR sign) <kkostiuk@redhat.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: C2C2 C109 EA43 C63C 1423  EB84 EF5D 5E81 61BA 84E7

* tag 'qga-pull-2023-05-04' of https://github.com/kostyanf14/qemu:
  qga: Fix suspend on Linux guests without systemd
  qga/commands-win32.c: Drop the check for _WIN32_WINNT >= 0x0601
  qga: test: Add tests for `merged` flag
  qga: Add `merged` variant to GuestExecCaptureOutputMode
  qga: Refactor guest-exec capture-output to take enum
  qga/linux: add usb support to guest-get-fsinfo

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed May 4, 2023
2 parents 1488ccb + 86dcb6a commit f6b761b
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 32 deletions.
18 changes: 11 additions & 7 deletions qga/commands-posix.c
Expand Up @@ -879,7 +879,9 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,
g_str_equal(driver, "sym53c8xx") ||
g_str_equal(driver, "virtio-pci") ||
g_str_equal(driver, "ahci") ||
g_str_equal(driver, "nvme"))) {
g_str_equal(driver, "nvme") ||
g_str_equal(driver, "xhci_hcd") ||
g_str_equal(driver, "ehci-pci"))) {
break;
}

Expand Down Expand Up @@ -976,6 +978,8 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,
}
} else if (strcmp(driver, "nvme") == 0) {
disk->bus_type = GUEST_DISK_BUS_TYPE_NVME;
} else if (strcmp(driver, "ehci-pci") == 0 || strcmp(driver, "xhci_hcd") == 0) {
disk->bus_type = GUEST_DISK_BUS_TYPE_USB;
} else {
g_debug("unknown driver '%s' (sysfs path '%s')", driver, syspath);
goto cleanup;
Expand Down Expand Up @@ -1918,10 +1922,10 @@ static void guest_suspend(SuspendMode mode, Error **errp)
if (systemd_supports_mode(mode, &local_err)) {
mode_supported = true;
systemd_suspend(mode, &local_err);
}

if (!local_err) {
return;
if (!local_err) {
return;
}
}

error_free(local_err);
Expand All @@ -1930,10 +1934,10 @@ static void guest_suspend(SuspendMode mode, Error **errp)
if (pmutils_supports_mode(mode, &local_err)) {
mode_supported = true;
pmutils_suspend(mode, &local_err);
}

if (!local_err) {
return;
if (!local_err) {
return;
}
}

error_free(local_err);
Expand Down
2 changes: 0 additions & 2 deletions qga/commands-win32.c
Expand Up @@ -484,15 +484,13 @@ static GuestDiskBusType win2qemu[] = {
[BusTypeSata] = GUEST_DISK_BUS_TYPE_SATA,
[BusTypeSd] = GUEST_DISK_BUS_TYPE_SD,
[BusTypeMmc] = GUEST_DISK_BUS_TYPE_MMC,
#if (_WIN32_WINNT >= 0x0601)
[BusTypeVirtual] = GUEST_DISK_BUS_TYPE_VIRTUAL,
[BusTypeFileBackedVirtual] = GUEST_DISK_BUS_TYPE_FILE_BACKED_VIRTUAL,
/*
* BusTypeSpaces currently is not suported
*/
[BusTypeSpaces] = GUEST_DISK_BUS_TYPE_UNKNOWN,
[BusTypeNvme] = GUEST_DISK_BUS_TYPE_NVME,
#endif
};

static GuestDiskBusType find_bus_type(STORAGE_BUS_TYPE bus)
Expand Down
62 changes: 57 additions & 5 deletions qga/commands.c
Expand Up @@ -270,12 +270,26 @@ static void guest_exec_child_watch(GPid pid, gint status, gpointer data)
g_spawn_close_pid(pid);
}

/** Reset ignored signals back to default. */
static void guest_exec_task_setup(gpointer data)
{
#if !defined(G_OS_WIN32)
bool has_merge = *(bool *)data;
struct sigaction sigact;

if (has_merge) {
/*
* FIXME: When `GLIB_VERSION_MIN_REQUIRED` is bumped to 2.58+, use
* g_spawn_async_with_fds() to be portable on windows. The current
* logic does not work on windows b/c `GSpawnChildSetupFunc` is run
* inside the parent, not the child.
*/
if (dup2(STDOUT_FILENO, STDERR_FILENO) != 0) {
slog("dup2() failed to merge stderr into stdout: %s",
strerror(errno));
}
}

/* Reset ignored signals back to default. */
memset(&sigact, 0, sizeof(struct sigaction));
sigact.sa_handler = SIG_DFL;

Expand Down Expand Up @@ -379,11 +393,23 @@ static gboolean guest_exec_output_watch(GIOChannel *ch,
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_SEPARATED
: 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;
Expand All @@ -396,7 +422,9 @@ 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;
bool has_merge = false;
GuestExecCaptureOutputMode output_mode;
g_autofree uint8_t *input = NULL;
size_t ninput = 0;

Expand All @@ -415,12 +443,36 @@ 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_SEPARATED:
has_output = true;
break;
#if !defined(G_OS_WIN32)
case GUEST_EXEC_CAPTURE_OUTPUT_MODE_MERGED:
has_output = true;
has_merge = true;
break;
#endif
case GUEST_EXEC_CAPTURE_OUTPUT_MODE__MAX:
/* Silence warning; impossible branch */
break;
}

ret = g_spawn_async_with_pipes(NULL, argv, envp, flags,
guest_exec_task_setup, NULL, &pid, input_data ? &in_fd : NULL,
guest_exec_task_setup, &has_merge, &pid, input_data ? &in_fd : NULL,
has_output ? &out_fd : NULL, has_output ? &err_fd : NULL, &gerr);
if (!ret) {
error_setg(errp, QERR_QGA_COMMAND_FAILED, gerr->message);
Expand Down
36 changes: 35 additions & 1 deletion qga/qapi-schema.json
Expand Up @@ -1200,6 +1200,40 @@
{ '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
# @separated: capture both stdout and stderr, but separated into
# GuestExecStatus out-data and err-data, respectively
# @merged: capture both stdout and stderr, but merge together
# into out-data. not effective on windows guests.
#
# Since: 8.0
##
{ 'enum': 'GuestExecCaptureOutputMode',
'data': [ 'none', 'stdout', 'stderr', 'separated',
{ 'name': 'merged', 'if': { 'not': 'CONFIG_WIN32' } } ] }

##
# @GuestExecCaptureOutput:
#
# Controls what guest-exec output gets captures.
#
# @flag: captures both stdout and stderr if true. Equivalent
# to GuestExecCaptureOutputMode::all. (since 2.5)
# @mode: capture mode; preferred interface
#
# Since: 8.0
##
{ 'alternate': 'GuestExecCaptureOutput',
'data': { 'flag': 'bool',
'mode': 'GuestExecCaptureOutputMode'} }

##
# @guest-exec:
#
Expand All @@ -1218,7 +1252,7 @@
##
{ 'command': 'guest-exec',
'data': { 'path': 'str', '*arg': ['str'], '*env': ['str'],
'*input-data': 'str', '*capture-output': 'bool' },
'*input-data': 'str', '*capture-output': 'GuestExecCaptureOutput' },
'returns': 'GuestExec' }


Expand Down

0 comments on commit f6b761b

Please sign in to comment.