From patchwork Tue Jul 24 00:01:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 948172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gDLOpCwL"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41ZJbK5lKZz9s3N for ; Tue, 24 Jul 2018 10:07:57 +1000 (AEST) Received: from localhost ([::1]:37384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhkrr-0002So-7C for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2018 20:07:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhkr7-0002RM-UL for qemu-devel@nongnu.org; Mon, 23 Jul 2018 20:07:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhkr4-0005B5-Pf for qemu-devel@nongnu.org; Mon, 23 Jul 2018 20:07:09 -0400 Received: from mail-oi0-x244.google.com ([2607:f8b0:4003:c06::244]:44349) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhkr4-0005Ar-KD for qemu-devel@nongnu.org; Mon, 23 Jul 2018 20:07:06 -0400 Received: by mail-oi0-x244.google.com with SMTP id s198-v6so4378267oih.11 for ; Mon, 23 Jul 2018 17:07:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=WL82KUHwurTq5cKzoN01viEOk8ThxEts57LsixCspiY=; b=gDLOpCwL5zUndz6eAWcfqd6eyQrN7Y8UfyKG7bNiANnJWeEfE5mOOOTZF6YR4rHVUB uyo6gon/IAzzrGsKMIn20L7xUkYtgHqZQ8VZbW+7rJw70d9xiWab08BaOZqlhuWgZiyC IDdU4Aib3ObX6m7uSzHetf/Wolv39oPKjgT/+//T284fpWYjbM8RvjJ9YlF9ATCIKxon NEFvtaEfJykjgS6S0R7dbQVCwjRM9rBKiuciryfh/AVQLMDe9cEDV9/KDhz6ZOZoeG52 paIKITeBiYyDHCR+GJsRblQLUzeRLOk8iTi3g+GjysV0FAeSk3Ev2scgeE9nvepbrY7x ePpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=WL82KUHwurTq5cKzoN01viEOk8ThxEts57LsixCspiY=; b=mdABjsR793ilGYFB/IveAnuQBhpjV/He1bQ5WgjPqv8HE04v4/noF0nLvGKKSDbAs3 HzNGbit4U9NvNHks/fPsSj+6gWR0twgY3Nh2dxi7mWme1v4skGEPDx00fqTLM2IMwWTn 8Hb/cSvvYlQvewgv7m4tPz2k+cGN8A5jo+Zs5ttymZbA1N7NQA0m4agzOtoVDuA4rFWA iMTSupAchy+fGAXPc9QEheezz+rUQ3XYcX27paD6q8oDDlmeqgYEr3yXLjja7yusXVAM LqysSNiqM8pVBOlnFz8HVlnV+b32v5Ob2amkgHEvMRlvWcPMjo9JpNCMfE/EowTmirkk GUWw== X-Gm-Message-State: AOUpUlH5Hgw0EY9WkOg6UQjgcnwpK/G2K8G9ZBhzcKDdSODux6WJIxPU juW89YU/IqpSrCT//czGRW4P+OlJnlnO+w== X-Google-Smtp-Source: AAOMgpdZKLha8885JVKCGnbsPPjZYxcPS9Vvip1W5ZDo/B/9vZZn2EZq66pWcC96gBYok/6TzZRNfQ== X-Received: by 2002:aca:698c:: with SMTP id e134-v6mr1060508oic.302.1532390825539; Mon, 23 Jul 2018 17:07:05 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id m62-v6sm27426197oik.30.2018.07.23.17.07.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 17:07:04 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2018 19:01:25 -0500 Message-Id: <20180724000126.21787-2-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180724000126.21787-1-mdroth@linux.vnet.ibm.com> References: <20180724000126.21787-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::244 Subject: [Qemu-devel] [PULL for-3.0 1/2] qga-win: Handle fstrim for OSes lower than Win8 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sameeh Jubran , peter.maydell@linaro.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Sameeh Jubran The defrag.exe tool which is used for executing the fstrim command on Windows doesn't support retrim for OSes lower than Win8. This commit handles this case and returns a suitable error. Output of fstrim before this commit: {"execute":"guest-fstrim"} {"return": {"paths": [{"path": "C:\\", "error": "An invalid command line option was specified. (0x89000008)"}, {"path": "F:\\", "error": "An invalid command line option was specified. (0x89000008)"}, {"path": "S:\\", "error": "An invalid command line option was specified. (0x89000008)"}]}} Reported on: https://bugzilla.redhat.com/show_bug.cgi?id=1594113 Signed-off-by: Sameeh Jubran * use alternative version query code proposed by Sameeh * fix up version check logic * avoid CamelCase variable names when possible Signed-off-by: Michael Roth --- qga/commands-win32.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 318d760a74..98d9735389 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -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) { From patchwork Tue Jul 24 00:01:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 948174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UbYa2sB8"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41ZJfJ1HSSz9s3N for ; Tue, 24 Jul 2018 10:10:32 +1000 (AEST) Received: from localhost ([::1]:37395 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhkuL-0004we-SH for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2018 20:10:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhkr8-0002Ri-GA for qemu-devel@nongnu.org; Mon, 23 Jul 2018 20:07:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhkr7-0005Bs-Ey for qemu-devel@nongnu.org; Mon, 23 Jul 2018 20:07:10 -0400 Received: from mail-oi0-x236.google.com ([2607:f8b0:4003:c06::236]:44119) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhkr7-0005Bi-8m; Mon, 23 Jul 2018 20:07:09 -0400 Received: by mail-oi0-x236.google.com with SMTP id s198-v6so4378406oih.11; Mon, 23 Jul 2018 17:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BlTqQNzTGnUvx1nWGVm7uw7tFph9z2w0/atXggq4/q0=; b=UbYa2sB8Nmanl4/A+A+c2P1JJRfZ4vvyGBnmI7y65p8uw7lv9mhQVG0+SAxm1gszd5 pVuEJ1a9CONPCLT/pWZ7KnoMsh3Zargn9dxfe+rP4HJpRJE3Fk0zoMtUVdPHbMPv7/ae wOx2AdUl2UOhA+Zr646Tsq1lRTCBpzuXNNoiHh2iqb8MxHPTavKxeBlbQAEMowJPX6cH WSR4+hjczZs9dsDIjl4NbQ7trXFbRagLTrRPhWPxW9kMSrMRIOGRJTSO5N/aeaQdjPLT ZdfCklwL+52ua5ujfSO6/rcoilM5zkTJqj5DbC9Qyom5536OLc60z4D4zUy89JUNfkkc Nhmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BlTqQNzTGnUvx1nWGVm7uw7tFph9z2w0/atXggq4/q0=; b=Jbi4CRV4yJvMdG4kLoVVD3HPiya4U2aw6kY/VAEhdudc+wwZT30wvz5aNoHvuKX4K6 NO3PoOb8AcdrN57RN4B1nUhrsaBhF8Qe6BrohQMImTDhkR5VHfFZipAQRPYWfUE5nK7M +/HGVEKmXo17e7juRDFlJTTlqzh6TUyjD7bwLbUik6YRnwGd7FHwGoCGSPdReejzT4+d 94rLjglPXOBiaXeiIBC/6ZlGAsFNdOZREs3Lh2MY2+H6L+SrxpIVDvpQ2PJVbSCHMYfT MeyIHwli1o31D5PIUbaS+90O0+SC4WHJoE8JbgGCYRuVGIsN0gJLqCXOpxIBHD1K7aH7 7geg== X-Gm-Message-State: AOUpUlFCH0UziWDPqCXY3Y1rkFUHsIWO+jgoRRKuwuAHSDi5LEzRxdF+ Dq6ElgQ6h67AOgkA8E4nzGsXru1dWujGzw== X-Google-Smtp-Source: AAOMgpdA6KMBGGpC2gxC3gftmdLxd+B8tqtYoc0J660RfT6QGAqPx373G5KauMghqsaHFpRUFx39yA== X-Received: by 2002:aca:4e50:: with SMTP id c77-v6mr907544oib.254.1532390828085; Mon, 23 Jul 2018 17:07:08 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id s124-v6sm7131606oia.51.2018.07.23.17.07.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 17:07:06 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2018 19:01:26 -0500 Message-Id: <20180724000126.21787-3-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180724000126.21787-1-mdroth@linux.vnet.ibm.com> References: <20180724000126.21787-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::236 Subject: [Qemu-devel] [PULL for-3.0 2/2] qga: process_event() simplification and leak fix X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-stable@nongnu.org, =?utf-8?q?Marc-Andr?= =?utf-8?b?w6kgTHVyZWF1?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau json_parser_parse_err() may return something else than a QDict, in which case we loose the object. Let's keep track of the original object to avoid leaks. When an error occurs, "qdict" contains the response, but we still check the "execute" key there. Untangle a bit this code, by having a clear error path. CC: Michael Roth Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster Cc: qemu-stable@nongnu.org Signed-off-by: Michael Roth --- qga/main.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/qga/main.c b/qga/main.c index 537cc0e162..87372d40ef 100644 --- a/qga/main.c +++ b/qga/main.c @@ -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 */