Skip to content
This repository has been archived by the owner on Apr 13, 2019. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2018-07-23…
Browse files Browse the repository at this point in the history
…-tag' into staging

qemu-ga patch queue for hard-freeze

* fix leak in qga main loop error path
* better error reporting when Windows version doesn't support fstrim

# gpg: Signature made Tue 24 Jul 2018 00:58:29 BST
# gpg:                using RSA key 3353C9CEF108B584
# gpg: Good signature from "Michael Roth <[email protected]>"
# gpg:                 aka "Michael Roth <[email protected]>"
# gpg:                 aka "Michael Roth <[email protected]>"
# Primary key fingerprint: CEAC C9E1 5534 EBAB B82D  3FA0 3353 C9CE F108 B584

* remotes/mdroth/tags/qga-pull-2018-07-23-tag:
  qga: process_event() simplification and leak fix
  qga-win: Handle fstrim for OSes lower than Win8

Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
pm215 committed Jul 24, 2018
2 parents 1a5182c + ae7da1e commit aabbca4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
13 changes: 13 additions & 0 deletions qga/commands-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,19 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
GuestFilesystemTrimResponse *resp;
HANDLE handle;
WCHAR guid[MAX_PATH] = L"";
OSVERSIONINFO osvi;
BOOL win8_or_later;

ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
win8_or_later = (osvi.dwMajorVersion > 6 ||
((osvi.dwMajorVersion == 6) &&
(osvi.dwMinorVersion >= 2)));
if (!win8_or_later) {
error_setg(errp, "fstrim is only supported for Win8+");
return NULL;
}

handle = FindFirstVolumeW(guid, ARRAYSIZE(guid));
if (handle == INVALID_HANDLE_VALUE) {
Expand Down
54 changes: 27 additions & 27 deletions qga/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,42 +600,42 @@ static void process_command(GAState *s, QDict *req)
static void process_event(JSONMessageParser *parser, GQueue *tokens)
{
GAState *s = container_of(parser, GAState, parser);
QDict *qdict;
QObject *obj;
QDict *req, *rsp;
Error *err = NULL;
int ret;

g_assert(s && parser);

g_debug("process_event: called");
qdict = qobject_to(QDict, json_parser_parse_err(tokens, NULL, &err));
if (err || !qdict) {
qobject_unref(qdict);
if (!err) {
g_warning("failed to parse event: unknown error");
error_setg(&err, QERR_JSON_PARSING);
} else {
g_warning("failed to parse event: %s", error_get_pretty(err));
}
qdict = qmp_error_response(err);
obj = json_parser_parse_err(tokens, NULL, &err);
if (err) {
goto err;
}

/* handle host->guest commands */
if (qdict_haskey(qdict, "execute")) {
process_command(s, qdict);
} else {
if (!qdict_haskey(qdict, "error")) {
qobject_unref(qdict);
g_warning("unrecognized payload format");
error_setg(&err, QERR_UNSUPPORTED);
qdict = qmp_error_response(err);
}
ret = send_response(s, qdict);
if (ret < 0) {
g_warning("error sending error response: %s", strerror(-ret));
}
req = qobject_to(QDict, obj);
if (!req) {
error_setg(&err, QERR_JSON_PARSING);
goto err;
}
if (!qdict_haskey(req, "execute")) {
g_warning("unrecognized payload format");
error_setg(&err, QERR_UNSUPPORTED);
goto err;
}

qobject_unref(qdict);
process_command(s, req);
qobject_unref(obj);
return;

err:
g_warning("failed to parse event: %s", error_get_pretty(err));
rsp = qmp_error_response(err);
ret = send_response(s, rsp);
if (ret < 0) {
g_warning("error sending error response: %s", strerror(-ret));
}
qobject_unref(rsp);
qobject_unref(obj);
}

/* false return signals GAChannel to close the current client connection */
Expand Down

0 comments on commit aabbca4

Please sign in to comment.