From nobody Sat May 4 08:36:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552926580954618.1564788247631; Mon, 18 Mar 2019 09:29:40 -0700 (PDT) Received: from localhost ([127.0.0.1]:44238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v8s-0004Ia-0M for importer@patchew.org; Mon, 18 Mar 2019 12:29:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v4O-00011z-3f for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:25:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5v4M-0002nz-Bj for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:59 -0400 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]:44873) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h5v4K-0002fY-T6 for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:57 -0400 Received: by mail-oi1-x232.google.com with SMTP id i21so10159146oib.11 for ; Mon, 18 Mar 2019 09:24:41 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id 97sm4140371otc.25.2019.03.18.09.24.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 09:24:38 -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=vBTLXof2Oy/O1BGjPzpumorX4yGxsWY9VNbwNaAQrIo=; b=LIu5gkoU+SEH8x98alGhZ7mO2YYJf/i+7ivKHqHNv060hG4BsR2QxQC7MzxIqNIVTC 2qjwBKfzd9MHLyFQa/p8I7H9ZAU7Sw3q78p1LAsOjhss2lZiAkaZLU4AhWWWz53qWghf rQQl6JVq+nDyiRo+K9Ir/c80yxMIFoZ+RMlTIjQ1E+7FGzkoWdKKkCi04/QtvSJ9mRks hETNBllHDO6gBinPOhJ4R58KuMCfJ6uz/37n5p5yS2ZpH8NDaqlSmWAb7A8lAOpYMwe8 sHGCJId9MwJOQAsjjXkTLylX2u7+46bzCTb9U1JujJhs1EPTa3u7jecT8+33N+5yWWS5 XkPA== 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=vBTLXof2Oy/O1BGjPzpumorX4yGxsWY9VNbwNaAQrIo=; b=pu9O5VqXO0s1eWkm1qlN5+A9Z36jIvowuNCFjt7EbLKVYa5phNBNmeKMYk9ClQXcug je3QK0+rRpiQ7WTaFP/9iloc/ga3Jiky3iaLewDXJ9hPYUolzVAJL/8MLvwk8e0N3p8q rXTz9PoMYMrsvs9CaWUbGMefUsCv+INgKfxxFjfBqsiwTB6Fj7PnpudWIZk0Evr1Vqr/ M8+XAIzSJdqHyiEq59Bq7uzrrGXRhdXYGT9VfwOO0vy7bPLFXi0P9A9+K7eDN5iHaYHi eZSuNThb3ZaALrXlGYaWpOVhMXi1OrNJmtH6M4BRgKx0yDNfrFmfX0CHcLKMEC66W99X RbHQ== X-Gm-Message-State: APjAAAXoYyWFqQ5cmS6mm2115Ux+fQjC+TPaMaZh11jfUEyZQe2+gQHo ToBccE6k9NZj1v/sqo8bezkgpF3e X-Google-Smtp-Source: APXvYqw0m533893X8Kg48Ffkt5MeEEiGSvXqDdPF/9pVICav0Nl+m1g1fp3HGl8n/2CC7sj5hB569Q== X-Received: by 2002:aca:c7d3:: with SMTP id x202mr5022689oif.48.1552926279797; Mon, 18 Mar 2019 09:24:39 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 11:24:04 -0500 Message-Id: <20190318162410.10183-2-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> References: <20190318162410.10183-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:4864:20::232 Subject: [Qemu-devel] [PULL for-4.0 1/7] qga: update docs with systemd suspend support info 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, Daniel Henrique Barboza Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza Commit 067927d62e ("qga: systemd hibernate/suspend/hybrid-sleep support") failed to update qapi-schema.json after adding systemd hibernate/suspend/hybrid-sleep capabilities to guest-suspend-* QGA commands. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Eric Blake Signed-off-by: Michael Roth --- qga/qapi-schema.json | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index a4ff5b8fc9..fb4605cc19 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -532,12 +532,12 @@ # # Suspend guest to disk. # -# This command tries to execute the scripts provided by the pm-utils packa= ge. -# If it's not available, the suspend operation will be performed by manual= ly -# writing to a sysfs file. +# This command attempts to suspend the guest using three strategies, in th= is +# order: # -# For the best results it's strongly recommended to have the pm-utils -# package installed in the guest. +# - systemd hibernate +# - pm-utils (via pm-hibernate) +# - manual write into sysfs # # This command does NOT return a response on success. There is a high chan= ce # the command succeeded if the VM exits with a zero exit status or, when @@ -560,12 +560,12 @@ # # Suspend guest to ram. # -# This command tries to execute the scripts provided by the pm-utils packa= ge. -# If it's not available, the suspend operation will be performed by manual= ly -# writing to a sysfs file. +# This command attempts to suspend the guest using three strategies, in th= is +# order: # -# For the best results it's strongly recommended to have the pm-utils -# package installed in the guest. +# - systemd suspend +# - pm-utils (via pm-suspend) +# - manual write into sysfs # # IMPORTANT: guest-suspend-ram requires working wakeup support in # QEMU. You should check QMP command query-current-machine returns @@ -594,7 +594,10 @@ # # Save guest state to disk and suspend to ram. # -# This command requires the pm-utils package to be installed in the guest. +# This command attempts to suspend the guest by executing, in this order: +# +# - systemd hybrid-sleep +# - pm-utils (via pm-suspend-hybrid) # # IMPORTANT: guest-suspend-hybrid requires working wakeup support in # QEMU. You should check QMP command query-current-machine returns --=20 2.17.1 From nobody Sat May 4 08:36:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552926449231942.671538665177; Mon, 18 Mar 2019 09:27:29 -0700 (PDT) Received: from localhost ([127.0.0.1]:44214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v6b-0002J6-H4 for importer@patchew.org; Mon, 18 Mar 2019 12:27:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v4O-00011y-3c for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:25:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5v4M-0002oM-CR for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:59 -0400 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:42372) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h5v4K-0002gD-T5 for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:57 -0400 Received: by mail-ot1-x341.google.com with SMTP id i5so14943362oto.9 for ; Mon, 18 Mar 2019 09:24:43 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id j131sm4368541oia.37.2019.03.18.09.24.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 09:24:40 -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=7lbwilNWaryPZcO65bG6VtO/wYPNsbLhIBvLHSH9WqA=; b=iXfBjuNGTlSXWwDR6O+L3l6tYtgmeUr/Ae6LlbGJwQQENmvVSJp+oBl48hhyd/BnR7 aPlwVZeUszlEmd59dVJHCbYwt+vBnJCtZfAxZtYULR/GKz/NuosZUxdP5SJCiWejYB7z FDY8VVUPbdyZJXfIffB65D03KyifEik6jJ6XuZfV82bW5OAPs/vw3ukXhL85IPN+FuMm IPAKB09Qx4rAHSUyygmoGDOtR1QNRlCdG/NKDBKyShmcLNOEk1qWD4QCw5RB7XO0ARmH uSb5IXPAdwIQR+8Hj95xtR0p8qCnzCpOcqAVWPj5Gyqgxcy5CUxhUKy7MBjVsejxK6mZ 40lg== 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=7lbwilNWaryPZcO65bG6VtO/wYPNsbLhIBvLHSH9WqA=; b=FsqpK0/03ASu2l2afiPV0L6gYarNr5G6pqIY37vknMoUWC4oROvr87ZGlTO/QeUiZC q5kHXpkJW3fYtLkyCaaZ/0gX8uc6PEG7EddocZ4OhS6CHBisU9qBPQsZ+xANBiWCFTB7 WNc/riaPfWwZ90HbWAtvE07ThORGghcLIUGdbqy50kGj8F3yUjMnS+sSkQufR8vJumWk 7nITS9+dteRBJR2FQFepgBjUFLRKiD38CmHehl6/L04dLTfpX0ikyWN41eiZT3useUYi +ARIxhhLrh5xF50OVjZ4EdE04UxdaHzlp0l1c5i8nXD2wIEmWVxVNgudyBIklt6pPOy8 XQww== X-Gm-Message-State: APjAAAU3T5VCU/fOJfPqzhJWjh9T6fPmBbBxG7led6W5ODmgwrYZyhz/ TPBJ5LlK0Fp+3BtL5l1tidCoC0fk X-Google-Smtp-Source: APXvYqzmRQGfKw+ZGjMR/58qTH1VrCKckQfCx6Oy7sieLhZCR2zRfWzk844tuL0BZ44+bTGPHesZig== X-Received: by 2002:a9d:7d82:: with SMTP id j2mr7568357otn.270.1552926281659; Mon, 18 Mar 2019 09:24:41 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 11:24:05 -0500 Message-Id: <20190318162410.10183-3-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> References: <20190318162410.10183-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:4864:20::341 Subject: [Qemu-devel] [PULL for-4.0 2/7] qga-win: Adding support for Windows Server 2019 get-osinfo command 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: Bishara AbuHattoum , peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Bishara AbuHattoum Since Windows Server 2016, Microsoft stopped upgrading the major and minor versions of their new Windows Server product, so, the current functionality of checking major and minor version numbers to determine the Windows Server version wont work as expected. The implemented solution here is to use the build number in addition to the major and minor version numbers of the product to determine the Windows Server product version. The final build number of Windows Server 2016 is 14939, and the final build number of Windows Server 2019 is 17764, so any Windows Server product that has the major version of 10 and minor version of 0 with a build number lower or equal to 14939 will resemble 2016 and if the build number is lower or equal to 17763 will resemble 2019. Reference: https://techcommunity.microsoft.com/t5/Windows-Server-Insiders/Windows-Serv= er-2019-version-info/m-p/293112/highlight/true#M859 Signed-off-by: Bishara AbuHattoum Signed-off-by: Michael Roth --- qga/commands-win32.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 989b93e702..fb48463885 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1941,12 +1941,24 @@ static ga_matrix_lookup_t const WIN_VERSION_MATRIX[= 2][8] =3D { { 6, 1, "Microsoft Windows Server 2008 R2", "2008r2"}, { 6, 2, "Microsoft Windows Server 2012", "2012"}, { 6, 3, "Microsoft Windows Server 2012 R2", "2012r2"}, - {10, 0, "Microsoft Windows Server 2016", "2016"}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0} } }; =20 +typedef struct _ga_win_10_0_server_t { + int final_build; + char const *version; + char const *version_id; +} ga_win_10_0_server_t; + +static ga_win_10_0_server_t const WIN_10_0_SERVER_VERSION_MATRIX[3] =3D { + {14393, "Microsoft Windows Server 2016", "2016"}, + {17763, "Microsoft Windows Server 2019", "2019"}, + {0, 0} +}; + static void ga_get_win_version(RTL_OSVERSIONINFOEXW *info, Error **errp) { typedef NTSTATUS(WINAPI * rtl_get_version_t)( @@ -1971,10 +1983,23 @@ static char *ga_get_win_name(OSVERSIONINFOEXW const= *os_version, bool id) { DWORD major =3D os_version->dwMajorVersion; DWORD minor =3D os_version->dwMinorVersion; + DWORD build =3D os_version->dwBuildNumber; int tbl_idx =3D (os_version->wProductType !=3D VER_NT_WORKSTATION); ga_matrix_lookup_t const *table =3D WIN_VERSION_MATRIX[tbl_idx]; + ga_win_10_0_server_t const *win_10_0_table =3D WIN_10_0_SERVER_VERSION= _MATRIX; while (table->version !=3D NULL) { - if (major =3D=3D table->major && minor =3D=3D table->minor) { + if (major =3D=3D 10 && minor =3D=3D 0 && tbl_idx) { + while (win_10_0_table->version !=3D NULL) { + if (build <=3D win_10_0_table->final_build) { + if (id) { + return g_strdup(win_10_0_table->version_id); + } else { + return g_strdup(win_10_0_table->version); + } + } + win_10_0_table++; + } + } else if (major =3D=3D table->major && minor =3D=3D table->minor)= { if (id) { return g_strdup(table->version_id); } else { --=20 2.17.1 From nobody Sat May 4 08:36:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552926449233886.2232988807924; Mon, 18 Mar 2019 09:27:29 -0700 (PDT) Received: from localhost ([127.0.0.1]:44216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v6d-0002Kw-7F for importer@patchew.org; Mon, 18 Mar 2019 12:27:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v4O-00011x-0J for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:25:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5v4M-0002nm-B2 for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:59 -0400 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]:34801) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h5v4K-0002hG-T7; Mon, 18 Mar 2019 12:24:57 -0400 Received: by mail-ot1-x32d.google.com with SMTP id r19so14987458otn.1; Mon, 18 Mar 2019 09:24:45 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id l63sm4285066oia.47.2019.03.18.09.24.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 09:24:42 -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=NKLGoySNmAyPmaOt5Xv7iUV/w5WslgbC7ZUlbmSKGoE=; b=o9VzBSqVKUskU6f4NmZDjP59EJ8XppknMpNY/U4Z4n0JraNPSro/MDObluda2ChqSK wJ+EECiiDWH8ny/tXSoQRuBlA104iKNYveFLfnFTFa2kCbfAsNEyjK7LjSMj22Lcx5Cb sW6yG4ffVSJ7rMEtTeX4BFGaxzykfSNc0FXCD90WfZV8N0OjiHzYY4vFMhaeX7WR4I1M i18b0BeuDRSxmwM+it7Wl8bzLnpHaJqgGTPr5fLTLNJkGLpd8Pmcdv9Cdr2/GUIfZZUk Y57WRK6ega9NEW8sOMzvfaS9NZOKzSVt5suktUoPIFPaIyJmVSFRIz5TuM7YkcDzRUkj 8tQA== 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=NKLGoySNmAyPmaOt5Xv7iUV/w5WslgbC7ZUlbmSKGoE=; b=ZU1HLsinOCkgbuFQj8DYoWTpU+UhEXPsNqENoJxRfi9ckBgMc+LCKQ73D02/RI+k+v 2mXjK5cdl0qQhrEAJBMWVhEp0WW//QpTvoP+cDQgFpYJizMFof0q54I8+NK+BiWJJW34 cpKswKeVEcgwJhmgmxMTZjpSI2e5lN2ujeTpHOC6kXbjJ/pnTr2LRTdAVz/us2tBcV+H mFlQp0ve+NwTAc9SpWeKnIjNKSAJD6VWXReVAUYe9AoFi73CVyPAWt41NXXmvM21pebe OwLZtgyBFcHTwykGEQcCX53B/cBAuN8grFJtP5x4O4181M2DNyxkN8XnSVXWU7owcZRp RATQ== X-Gm-Message-State: APjAAAWpaCzM6Po+43LtgHnkG30ptjV+qzeT0/i1+fXQEhKycGg/Gak+ mKSPQERekAvs8k8frwCS1RHgnGSd X-Google-Smtp-Source: APXvYqz/zorGmql/2E88gEdEbOtj3KuqwuqqwEnVCsu0xy/3gENf4NG21aztiRsgbWBcmQDV7167rA== X-Received: by 2002:a9d:5e8:: with SMTP id 95mr7234998otd.196.1552926284573; Mon, 18 Mar 2019 09:24:44 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 11:24:06 -0500 Message-Id: <20190318162410.10183-4-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> References: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::32d Subject: [Qemu-devel] [PULL for-4.0 3/7] qga-win: include glib when building VSS DLL 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Commit 3ebee3b191e defined assert() as g_assert(), but when we build the VSS DLL component of QGA (to handle fsfreeze) we do not include glib, which results in breakage when building with VSS support enabled. Fix this by including glib (along with the -lintl and -lws2_32 dependencies it brings). Since the VSS DLL is built statically, this introduces an additional dependency on static glib and supporting libs for the mingw environment (possibly why we didn't include glib originally), but VSS support already has very specific prerequisites so it shouldn't affect too many build environments. Since the VSS DLL code does use qemu/osdep.h, this should also help avoid future breakages and possibly allow for some clean ups in current VSS code. Suggested-by: Daniel P. Berrang=C3=A9 Cc: Daniel P. Berrang=C3=A9 Cc: qemu-stable@nongnu.org Signed-off-by: Michael Roth --- qga/vss-win32/Makefile.objs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qga/vss-win32/Makefile.objs b/qga/vss-win32/Makefile.objs index 23d08da225..dad9d1b0ba 100644 --- a/qga/vss-win32/Makefile.objs +++ b/qga/vss-win32/Makefile.objs @@ -5,7 +5,7 @@ qga-vss-dll-obj-y +=3D requester.o provider.o install.o obj-qga-vss-dll-obj-y =3D $(addprefix $(obj)/, $(qga-vss-dll-obj-y)) $(obj-qga-vss-dll-obj-y): QEMU_CXXFLAGS =3D $(filter-out -Wstrict-prototyp= es -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-styl= e-definition -Wredundant-decls -fstack-protector-all -fstack-protector-stro= ng, $(QEMU_CFLAGS)) -Wno-unknown-pragmas -Wno-delete-non-virtual-dtor =20 -$(obj)/qga-vss.dll: LDFLAGS =3D -shared -Wl,--add-stdcall-alias,--enable-s= tdcall-fixup -lole32 -loleaut32 -lshlwapi -luuid -static +$(obj)/qga-vss.dll: LDFLAGS =3D -shared -Wl,--add-stdcall-alias,--enable-s= tdcall-fixup -lglib-2.0 -lole32 -loleaut32 -lshlwapi -luuid -lintl -lws2_32= -static $(obj)/qga-vss.dll: $(obj-qga-vss-dll-obj-y) $(SRC_PATH)/$(obj)/qga-vss.def $(call quiet-command,$(CXX) -o $@ $(qga-vss-dll-obj-y) $(SRC_PATH)/qga/vs= s-win32/qga-vss.def $(CXXFLAGS) $(LDFLAGS),"LINK","$(TARGET_DIR)$@") =20 --=20 2.17.1 From nobody Sat May 4 08:36:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552926577096354.2519782405295; Mon, 18 Mar 2019 09:29:37 -0700 (PDT) Received: from localhost ([127.0.0.1]:44236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v8o-0004GO-4K for importer@patchew.org; Mon, 18 Mar 2019 12:29:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v4O-00012I-CV for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:25:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5v4M-0002op-Sv for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:59 -0400 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]:40840) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h5v4L-0002iQ-DQ for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:58 -0400 Received: by mail-ot1-x32d.google.com with SMTP id x8so14949373otg.7 for ; Mon, 18 Mar 2019 09:24:48 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id a4sm4313571otc.21.2019.03.18.09.24.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 09:24:45 -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=4k0SORvKcq6nsbn8gpIa+ie+lDkBiMb8LNB7esc1SaM=; b=jDtViEG0hgDDo9TesFOqRDwB0UmKEynjK/xtnnu5KzAkzmab1+U5Xou2NaOOoJ+HIb 7Vu6dIwSJtrpPq8PNiZs8yoBS/7bvUKC7kApTB5O9+jyZPhRXd55yRBP+LMbbfikDKnP aPnDUkOorZ84i7wAO2P5MoyG4LL/M06jtHBjC8HdQU6/b2Pnn5uBAtvaTCBKwSjambLe 32CQco8213KhLgTz3iD8rPWAlU2uQhiTMAs1cZUgTiVRi/LD6X4+qyF/B319NYWKSQ4J iU/yHz6LPM+qI4JkpFF8wQledjSqT0ffRM/gEeo27/r6Lc2BLqT4C1BVwVlFwCtrxwmO cbYA== 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=4k0SORvKcq6nsbn8gpIa+ie+lDkBiMb8LNB7esc1SaM=; b=oDXeBPPxw+rTZ8yyW1G9istWmQUY2IqIn+7x08Cs74WPHzid6lsR0N+XXTT+qNeIJT uvosTrQBWLfRmxjmYfvhWbiIfTUzsVOGhz7q0tTAil76RDf9vv37BnNjxgOU7q6Phxz2 s6Edy0avJ5pdK8VTwKtPL+mK0x486xVj7YSLM64KkcjkRyviAq2ewjt7+FvFgrjqSN4I 0esJLoLIpqbU5p33z5ENV5txOEH/3Roi83ahAT5HqBy3pUdkd/FqYUo2MbDg75J9G2gW +9qv85IcOYkCH9Ps8njaF6YCgoW1EjvHiaFS3NMqgnNrfsZoaaU7rTV13LRHQTzlmVz+ /HOg== X-Gm-Message-State: APjAAAXFic6TRslfshwlR1xcvKdxICCwLKEavc8IJf25PWtTzP8CMZ8i NkFrZ9edzKxm8DxD6zPnLB81LIPV X-Google-Smtp-Source: APXvYqz3rAOXII0mgVbRiGhsfcxyP40Spg4J+1Pbv7gmK4glw5X/SJfq+WQJ+IV5w5ITwT3ItPgnVg== X-Received: by 2002:a9d:6191:: with SMTP id g17mr3801530otk.291.1552926287128; Mon, 18 Mar 2019 09:24:47 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 11:24:07 -0500 Message-Id: <20190318162410.10183-5-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> References: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::32d Subject: [Qemu-devel] [PULL for-4.0 4/7] qga-win: fix VSS build breakage due to unintended gnu99 C++ flag 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Commit 7be41675f7c set -std=3Dgnu99 for C code via QEMU_CFLAGS. Currently we generate a "custom" QEMU_CXXFLAGS for VSS DLL C++ build by filtering out some options from QEMU_CFLAGS and adding some others. Since we don't filter out -std=3Dgnu99 currently this breaks builds when VSS support is enabled. We could keep the existing approach, filter out -std=3Dgnu99 from QEMU_CFLAGS, and add -std=3Dgnu++98, like configure currently does for QEMU_CXXFLAGS, but as it turns out our resulting QEMU_CXXFLAGS would be exactly what configure already generates, just with these filtered out: -fstack-protector-all -fstack-protector-strong and these added: -Wno-unknown-pragmas -Wno-delete-non-virtual-dtor So fix the issue by re-using configure-generated QEMU_CXXFLAGS and just handling these specific changes. Signed-off-by: Michael Roth Reviewed-by: Daniel P. Berrang=C3=A9 --- qga/vss-win32/Makefile.objs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qga/vss-win32/Makefile.objs b/qga/vss-win32/Makefile.objs index dad9d1b0ba..fd3ba1896b 100644 --- a/qga/vss-win32/Makefile.objs +++ b/qga/vss-win32/Makefile.objs @@ -3,7 +3,7 @@ qga-vss-dll-obj-y +=3D requester.o provider.o install.o =20 obj-qga-vss-dll-obj-y =3D $(addprefix $(obj)/, $(qga-vss-dll-obj-y)) -$(obj-qga-vss-dll-obj-y): QEMU_CXXFLAGS =3D $(filter-out -Wstrict-prototyp= es -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-styl= e-definition -Wredundant-decls -fstack-protector-all -fstack-protector-stro= ng, $(QEMU_CFLAGS)) -Wno-unknown-pragmas -Wno-delete-non-virtual-dtor +$(obj-qga-vss-dll-obj-y): QEMU_CXXFLAGS :=3D $(filter-out -fstack-protecto= r-all -fstack-protector-strong, $(QEMU_CXXFLAGS)) -Wno-unknown-pragmas -Wno= -delete-non-virtual-dtor =20 $(obj)/qga-vss.dll: LDFLAGS =3D -shared -Wl,--add-stdcall-alias,--enable-s= tdcall-fixup -lglib-2.0 -lole32 -loleaut32 -lshlwapi -luuid -lintl -lws2_32= -static $(obj)/qga-vss.dll: $(obj-qga-vss-dll-obj-y) $(SRC_PATH)/$(obj)/qga-vss.def --=20 2.17.1 From nobody Sat May 4 08:36:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552926691507245.56048817026897; Mon, 18 Mar 2019 09:31:31 -0700 (PDT) Received: from localhost ([127.0.0.1]:44281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5vAe-0005gq-AC for importer@patchew.org; Mon, 18 Mar 2019 12:31:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v4P-00012j-2I for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:25:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5v4M-0002oG-Bo for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:25:00 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]:39961) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h5v4K-0002j7-T1 for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:57 -0400 Received: by mail-oi1-x22b.google.com with SMTP id k11so13532496oic.7 for ; Mon, 18 Mar 2019 09:24:50 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id o84sm1526237oib.21.2019.03.18.09.24.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 09:24:48 -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=uAE7O7/pMcSAVK6ZKGYFhAM2oZUvPTw5he81ymdeeUo=; b=OsenleDxBrQYHinEyyEl4htBY3oOgNPcel8o3c3Vg0dtpL6zmRiJYVFrRDJOtwhOQL EpweHhkF4Qv294l29APl1bYZG4Vz2Q7vLENwq2OK1tgq+ZiSOd+iJbauldviyOEXkBbA FLdDmhAaZfOW4FM8qwSQMGS8XU8J2iwpHjJag/nyPOioVvSXFCJyHChs/jJik677/gKP SshnL3AG56DVNCconbHLCAbi4A6bkNBY18wZlGH6AJPXdlsJL+/U1xP1Iun+6qUY+Ec8 ucxpGGUdFhHhapvN0fdk4l4aKQkmusvNz7PShE4nvZpx6a31w4/yIJrj7Vw0bWym2byV nk5g== 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=uAE7O7/pMcSAVK6ZKGYFhAM2oZUvPTw5he81ymdeeUo=; b=bA7J1hUElSBR9x16vMSADTcuHkFbdV7IQkfJlVi3Knd84cNiPxeEbA0e+kk1UlmgHe OqSelafTZgPi9PG/kxVWshIzVdDrLGZkAK+RLLOT1jv9YzYkJgzwKezYSZruZ+TPAAss DTvcrHdaLQ7cAMxmllGxfnAdSvkM1uQLjI5JUFHSjmpCo/wUUDOg6hWDBkyJcQUKBqwd qDnQtvyPrAfYfPeeYTgtFt+iLhB5BhDpeG3CA6KTe0+TgngiOK1FknaS69ASoEb2wKJK 4e5VIBOZJ3LVq53smfKPUq8ouEqJ5OClle9Nmv4C3f7N3WUZf3+GKz24xMGwWF7sjEsw qEcw== X-Gm-Message-State: APjAAAUvIk6k1/ghe6IdMDNtM+D5n9l88bmtrDeaZgTzFd8yAQ4plfLZ iYSsjhzVGAAlOu4HnyWp5xm61oqG X-Google-Smtp-Source: APXvYqz4ych6TNIOSGzzuwSlyOhp6juLujhmAhH1+k7+4ulLi13UpWUFuz3qZoTEPD2gkvhq7c99kA== X-Received: by 2002:aca:3687:: with SMTP id d129mr9836880oia.51.1552926289154; Mon, 18 Mar 2019 09:24:49 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 11:24:08 -0500 Message-Id: <20190318162410.10183-6-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> References: <20190318162410.10183-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:4864:20::22b Subject: [Qemu-devel] [PULL for-4.0 5/7] qga: Fix guest-get-fsinfo PCI address collection in Windows 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, Matt Hines Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Matt Hines The Windows QEMU guest agent erroneously tries to collect PCI information directly from the physical drive. However, windows stores SCSI/IDE informat= ion with the drive and PCI information with the underlying storage controller This changes get_pci_info to use the physical drive's underlying storage controller to get PCI information. * Additionally Fixes incorrect size being passed to DeviceIoControl when getting volume extents. Can occasionally crash the guest agent Signed-off-by: Matt Hines *fix up some checkpatch warnings *fix domain reporting and add some sanity checks for debug Signed-off-by: Michael Roth --- configure | 2 +- qga/commands-win32.c | 317 ++++++++++++++++++++++++++++--------------- 2 files changed, 211 insertions(+), 108 deletions(-) diff --git a/configure b/configure index 7071f52584..02ea221272 100755 --- a/configure +++ b/configure @@ -4934,7 +4934,7 @@ int main(void) { EOF if compile_prog "" "" ; then guest_agent_ntddscsi=3Dyes - libs_qga=3D"-lsetupapi $libs_qga" + libs_qga=3D"-lsetupapi -lcfgmgr32 $libs_qga" fi fi =20 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index fb48463885..d40d61f605 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #endif #include @@ -485,56 +486,29 @@ static GuestDiskBusType find_bus_type(STORAGE_BUS_TYP= E bus) return win2qemu[(int)bus]; } =20 -/* XXX: The following function is BROKEN! - * - * It does not work and probably has never worked. When we query for list = of - * disks we get cryptic names like "\Device\0000001d" instead of - * "\PhysicalDriveX" or "\HarddiskX". Whether the names can be translated = one - * way or the other for comparison is an open question. - * - * When we query volume names (the original version) we are able to match = those - * but then the property queries report error "Invalid function". (duh!) - */ - -/* -DEFINE_GUID(GUID_DEVINTERFACE_VOLUME, - 0x53f5630dL, 0xb6bf, 0x11d0, 0x94, 0xf2, - 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b); -*/ DEFINE_GUID(GUID_DEVINTERFACE_DISK, 0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b); +DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT, + 0x2accfe60L, 0xc130, 0x11d2, 0xb0, 0x82, + 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b); =20 - -static GuestPCIAddress *get_pci_info(char *guid, Error **errp) +static GuestPCIAddress *get_pci_info(int number, Error **errp) { HDEVINFO dev_info; SP_DEVINFO_DATA dev_info_data; - DWORD size =3D 0; + SP_DEVICE_INTERFACE_DATA dev_iface_data; + HANDLE dev_file; int i; - char dev_name[MAX_PATH]; - char *buffer =3D NULL; GuestPCIAddress *pci =3D NULL; - char *name =3D NULL; bool partial_pci =3D false; + pci =3D g_malloc0(sizeof(*pci)); pci->domain =3D -1; pci->slot =3D -1; pci->function =3D -1; pci->bus =3D -1; =20 - if (g_str_has_prefix(guid, "\\\\.\\") || - g_str_has_prefix(guid, "\\\\?\\")) { - name =3D g_strdup(guid + 4); - } else { - name =3D g_strdup(guid); - } - - if (!QueryDosDevice(name, dev_name, ARRAY_SIZE(dev_name))) { - error_setg_win32(errp, GetLastError(), "failed to get dos device n= ame"); - goto out; - } - dev_info =3D SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (dev_info =3D=3D INVALID_HANDLE_VALUE) { @@ -544,90 +518,220 @@ static GuestPCIAddress *get_pci_info(char *guid, Err= or **errp) =20 g_debug("enumerating devices"); dev_info_data.cbSize =3D sizeof(SP_DEVINFO_DATA); + dev_iface_data.cbSize =3D sizeof(SP_DEVICE_INTERFACE_DATA); for (i =3D 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++)= { - DWORD addr, bus, slot, data, size2; - int func, dev; - while (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, - SPDRP_PHYSICAL_DEVICE_OBJECT_N= AME, - &data, (PBYTE)buffer, size, - &size2)) { - size =3D MAX(size, size2); - if (GetLastError() =3D=3D ERROR_INSUFFICIENT_BUFFER) { - g_free(buffer); - /* Double the size to avoid problems on - * W2k MBCS systems per KB 888609. - * https://support.microsoft.com/en-us/kb/259695 */ - buffer =3D g_malloc(size * 2); - } else { + PSP_DEVICE_INTERFACE_DETAIL_DATA pdev_iface_detail_data =3D NULL; + STORAGE_DEVICE_NUMBER sdn; + char *parent_dev_id =3D NULL; + HDEVINFO parent_dev_info; + SP_DEVINFO_DATA parent_dev_info_data; + DWORD j; + DWORD size =3D 0; + + g_debug("getting device path"); + if (SetupDiEnumDeviceInterfaces(dev_info, &dev_info_data, + &GUID_DEVINTERFACE_DISK, 0, + &dev_iface_data)) { + while (!SetupDiGetDeviceInterfaceDetail(dev_info, &dev_iface_d= ata, + pdev_iface_detail_data, + size, &size, + &dev_info_data)) { + if (GetLastError() =3D=3D ERROR_INSUFFICIENT_BUFFER) { + pdev_iface_detail_data =3D g_malloc(size); + pdev_iface_detail_data->cbSize =3D + sizeof(*pdev_iface_detail_data); + } else { + error_setg_win32(errp, GetLastError(), + "failed to get device interfaces"); + goto free_dev_info; + } + } + + dev_file =3D CreateFile(pdev_iface_detail_data->DevicePath, 0, + FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, + NULL); + g_free(pdev_iface_detail_data); + + if (!DeviceIoControl(dev_file, IOCTL_STORAGE_GET_DEVICE_NUMBER, + NULL, 0, &sdn, sizeof(sdn), &size, NULL))= { + CloseHandle(dev_file); error_setg_win32(errp, GetLastError(), - "failed to get device name"); + "failed to get device slot number"); goto free_dev_info; } - } =20 - if (g_strcmp0(buffer, dev_name)) { - continue; + CloseHandle(dev_file); + if (sdn.DeviceNumber !=3D number) { + continue; + } + } else { + error_setg_win32(errp, GetLastError(), + "failed to get device interfaces"); + goto free_dev_info; } - g_debug("found device %s", dev_name); =20 - /* There is no need to allocate buffer in the next functions. The = size - * is known and ULONG according to - * https://support.microsoft.com/en-us/kb/253232 - * https://msdn.microsoft.com/en-us/library/windows/hardware/ff543= 095(v=3Dvs.85).aspx - */ - if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, - SPDRP_BUSNUMBER, &data, (PBYTE)&bus, size, NULL)) { - debug_error("failed to get bus"); - bus =3D -1; - partial_pci =3D true; + g_debug("found device slot %d. Getting storage controller", number= ); + { + CONFIGRET cr; + DEVINST dev_inst, parent_dev_inst; + ULONG dev_id_size =3D 0; + + size =3D 0; + while (!SetupDiGetDeviceInstanceId(dev_info, &dev_info_data, + parent_dev_id, size, &size)= ) { + if (GetLastError() =3D=3D ERROR_INSUFFICIENT_BUFFER) { + parent_dev_id =3D g_malloc(size); + } else { + error_setg_win32(errp, GetLastError(), + "failed to get device instance ID"); + goto out; + } + } + + /* + * CM API used here as opposed to + * SetupDiGetDeviceProperty(..., DEVPKEY_Device_Parent, ...) + * which exports are only available in mingw-w64 6+ + */ + cr =3D CM_Locate_DevInst(&dev_inst, parent_dev_id, 0); + if (cr !=3D CR_SUCCESS) { + g_error("CM_Locate_DevInst failed with code %lx", cr); + error_setg_win32(errp, GetLastError(), + "failed to get device instance"); + goto out; + } + cr =3D CM_Get_Parent(&parent_dev_inst, dev_inst, 0); + if (cr !=3D CR_SUCCESS) { + g_error("CM_Get_Parent failed with code %lx", cr); + error_setg_win32(errp, GetLastError(), + "failed to get parent device instance"); + goto out; + } + + cr =3D CM_Get_Device_ID_Size(&dev_id_size, parent_dev_inst, 0); + if (cr !=3D CR_SUCCESS) { + g_error("CM_Get_Device_ID_Size failed with code %lx", cr); + error_setg_win32(errp, GetLastError(), + "failed to get parent device ID length"); + goto out; + } + + ++dev_id_size; + if (dev_id_size > size) { + g_free(parent_dev_id); + parent_dev_id =3D g_malloc(dev_id_size); + } + + cr =3D CM_Get_Device_ID(parent_dev_inst, parent_dev_id, dev_id= _size, + 0); + if (cr !=3D CR_SUCCESS) { + g_error("CM_Get_Device_ID failed with code %lx", cr); + error_setg_win32(errp, GetLastError(), + "failed to get parent device ID"); + goto out; + } } =20 - /* The function retrieves the device's address. This value will be - * transformed into device function and number */ - if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, - SPDRP_ADDRESS, &data, (PBYTE)&addr, size, NULL)) { - debug_error("failed to get address"); - addr =3D -1; - partial_pci =3D true; + g_debug("querying storage controller %s for PCI information", + parent_dev_id); + parent_dev_info =3D + SetupDiGetClassDevs(&GUID_DEVINTERFACE_STORAGEPORT, parent_dev= _id, + NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFAC= E); + g_free(parent_dev_id); + + if (parent_dev_info =3D=3D INVALID_HANDLE_VALUE) { + error_setg_win32(errp, GetLastError(), + "failed to get parent device"); + goto out; } =20 - /* This call returns UINumber of DEVICE_CAPABILITIES structure. - * This number is typically a user-perceived slot number. */ - if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, - SPDRP_UI_NUMBER, &data, (PBYTE)&slot, size, NULL)) { - debug_error("failed to get slot"); - slot =3D -1; - partial_pci =3D true; + parent_dev_info_data.cbSize =3D sizeof(SP_DEVINFO_DATA); + if (!SetupDiEnumDeviceInfo(parent_dev_info, 0, &parent_dev_info_da= ta)) { + error_setg_win32(errp, GetLastError(), + "failed to get parent device data"); + goto out; } =20 - /* SetupApi gives us the same information as driver with - * IoGetDeviceProperty. According to Microsoft - * https://support.microsoft.com/en-us/kb/253232 - * FunctionNumber =3D (USHORT)((propertyAddress) & 0x0000FFFF); - * DeviceNumber =3D (USHORT)(((propertyAddress) >> 16) & 0x0000FFF= F); - * SPDRP_ADDRESS is propertyAddress, so we do the same.*/ - - if (partial_pci) { - pci->domain =3D -1; - pci->slot =3D -1; - pci->function =3D -1; - pci->bus =3D -1; - } else { - func =3D ((int) addr =3D=3D -1) ? -1 : addr & 0x0000FFFF; - dev =3D ((int) addr =3D=3D -1) ? -1 : (addr >> 16) & 0x0000FFF= F; - pci->domain =3D dev; - pci->slot =3D (int) slot; - pci->function =3D func; - pci->bus =3D (int) bus; + for (j =3D 0; + SetupDiEnumDeviceInfo(parent_dev_info, j, &parent_dev_info_da= ta); + j++) { + DWORD addr, bus, ui_slot, type; + int func, slot; + + /* + * There is no need to allocate buffer in the next functions. = The + * size is known and ULONG according to + * https://msdn.microsoft.com/en-us/library/windows/hardware/f= f543095(v=3Dvs.85).aspx + */ + if (!SetupDiGetDeviceRegistryProperty( + parent_dev_info, &parent_dev_info_data, SPDRP_BUSNUMBER, + &type, (PBYTE)&bus, size, NULL)) { + debug_error("failed to get PCI bus"); + bus =3D -1; + partial_pci =3D true; + } + + /* + * The function retrieves the device's address. This value wil= l be + * transformed into device function and number + */ + if (!SetupDiGetDeviceRegistryProperty( + parent_dev_info, &parent_dev_info_data, SPDRP_ADDRESS, + &type, (PBYTE)&addr, size, NULL)) { + debug_error("failed to get PCI address"); + addr =3D -1; + partial_pci =3D true; + } + + /* + * This call returns UINumber of DEVICE_CAPABILITIES structure. + * This number is typically a user-perceived slot number. + */ + if (!SetupDiGetDeviceRegistryProperty( + parent_dev_info, &parent_dev_info_data, SPDRP_UI_NUMBE= R, + &type, (PBYTE)&ui_slot, size, NULL)) { + debug_error("failed to get PCI slot"); + ui_slot =3D -1; + partial_pci =3D true; + } + + /* + * SetupApi gives us the same information as driver with + * IoGetDeviceProperty. According to Microsoft: + * + * FunctionNumber =3D (USHORT)((propertyAddress) & 0x0000FFF= F) + * DeviceNumber =3D (USHORT)(((propertyAddress) >> 16) & 0x0= 000FFFF) + * SPDRP_ADDRESS is propertyAddress, so we do the same. + * + * https://docs.microsoft.com/en-us/windows/desktop/api/setupa= pi/nf-setupapi-setupdigetdeviceregistrypropertya + */ + if (partial_pci) { + pci->domain =3D -1; + pci->slot =3D -1; + pci->function =3D -1; + pci->bus =3D -1; + continue; + } else { + func =3D ((int)addr =3D=3D -1) ? -1 : addr & 0x0000FFFF; + slot =3D ((int)addr =3D=3D -1) ? -1 : (addr >> 16) & 0x000= 0FFFF; + if ((int)ui_slot !=3D slot) { + g_debug("mismatch with reported slot values: %d vs %d", + (int)ui_slot, slot); + } + pci->domain =3D 0; + pci->slot =3D (int)ui_slot; + pci->function =3D func; + pci->bus =3D (int)bus; + break; + } } + SetupDiDestroyDeviceInfoList(parent_dev_info); break; } =20 free_dev_info: SetupDiDestroyDeviceInfoList(dev_info); out: - g_free(buffer); - g_free(name); return pci; } =20 @@ -685,7 +789,8 @@ out_free: return; } =20 -static void get_single_disk_info(GuestDiskAddress *disk, Error **errp) +static void get_single_disk_info(int disk_number, + GuestDiskAddress *disk, Error **errp) { SCSI_ADDRESS addr, *scsi_ad; DWORD len; @@ -714,7 +819,7 @@ static void get_single_disk_info(GuestDiskAddress *disk= , Error **errp) * if that doesn't hold since that suggests some other unexpected * breakage */ - disk->pci_controller =3D get_pci_info(disk->dev, &local_err); + disk->pci_controller =3D get_pci_info(disk_number, &local_err); if (local_err) { error_propagate(errp, local_err); goto err_close; @@ -728,7 +833,7 @@ static void get_single_disk_info(GuestDiskAddress *disk= , Error **errp) /* We are able to use the same ioctls for different bus types * according to Microsoft docs * https://technet.microsoft.com/en-us/library/ee851589(v=3Dws.10)= .aspx */ - g_debug("getting pci-controller info"); + g_debug("getting SCSI info"); if (DeviceIoControl(disk_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_= ad, sizeof(SCSI_ADDRESS), &len, NULL)) { disk->unit =3D addr.Lun; @@ -776,12 +881,10 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *guid, Error **errp) size =3D sizeof(VOLUME_DISK_EXTENTS); extents =3D g_malloc0(size); if (!DeviceIoControl(vol_h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, - 0, extents, size, NULL, NULL)) { + 0, extents, size, &size, NULL)) { DWORD last_err =3D GetLastError(); if (last_err =3D=3D ERROR_MORE_DATA) { /* Try once more with big enough buffer */ - size =3D sizeof(VOLUME_DISK_EXTENTS) - + extents->NumberOfDiskExtents*sizeof(DISK_EXTENT); g_free(extents); extents =3D g_malloc0(size); if (!DeviceIoControl( @@ -797,7 +900,7 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) disk =3D g_malloc0(sizeof(GuestDiskAddress)); disk->has_dev =3D true; disk->dev =3D g_strdup(name); - get_single_disk_info(disk, &local_err); + get_single_disk_info(0xffffffff, disk, &local_err); if (local_err) { g_debug("failed to get disk info, ignoring error: %s", error_get_pretty(local_err)); @@ -831,9 +934,9 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) */ disk->has_dev =3D true; disk->dev =3D g_strdup_printf("\\\\.\\PhysicalDrive%lu", - extents->Extents[i].DiskNumber); + extents->Extents[i].DiskNumber); =20 - get_single_disk_info(disk, &local_err); + get_single_disk_info(extents->Extents[i].DiskNumber, disk, &local_= err); if (local_err) { error_propagate(errp, local_err); goto out; --=20 2.17.1 From nobody Sat May 4 08:36:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552926687747120.45791180999515; Mon, 18 Mar 2019 09:31:27 -0700 (PDT) Received: from localhost ([127.0.0.1]:44279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5vAa-0005eG-Ph for importer@patchew.org; Mon, 18 Mar 2019 12:31:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v4P-00012h-0s for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:25:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5v4N-0002pA-9X for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:25:00 -0400 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]:35373) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h5v4M-0002jt-Ac for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:58 -0400 Received: by mail-oi1-x229.google.com with SMTP id j132so10536449oib.2 for ; Mon, 18 Mar 2019 09:24:52 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id 92sm3482917oti.60.2019.03.18.09.24.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 09:24:50 -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=9D7JmcIkrFbqgo2VtPTrz7/UFxQ8TMolyp60ZWb90yo=; b=uK8+Tm1buTCcdxkSb53z2xbb5KlTcdEzIb5LEma0g6Uzga5WvCzHeK0bNu0SswlvW9 PbQRKLzqaW4/lJemMl4LfFWyakf+XOX6ZibFUAgYPKu53RO6pnhUINVPC6pG4MKEv1AW JAvZbJ86xCxlykmInjpF7pY0k2tIn+T2ytUzuOu8rTjsKwqiJFq6czOhL1r5oh9sQsia ZpIH6bDgZoURmidZuVjmCJ9CBYIsJYIWDGv7VrgrLlcOC4yU7dj7EIwjKv6EW2d14HRS ApzQ1Jy1rfx8r9uTjt6Aodp90zp94bF6d0owcHyuCy4ItDENl06Tjy8ZZQP4lVELDZdB A1Cw== 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=9D7JmcIkrFbqgo2VtPTrz7/UFxQ8TMolyp60ZWb90yo=; b=TeXDi0c5vWbq/87REcTvxa7BZJKv3h/3reA1OhUOGZvHdlny9oImGM3UDg3ZmeCPPk +w351DQmB1Fb2XtlEEnhzBhbkb+rR0lfjv20lAG6sPVmpVs15yFq7xRUw4OOKtPnV57f az7davZsHqyVXnLQNnlNLSaWUj0nI+enF9n+jFfwClw8Olf4OXcDRRpIUe2zPS/lF3OS hyH2mTvQsCGV8eLTZWwpWACWSh0M4jiGMewzwhihRnE0oLQgpnGUh7wxoOS6/SMViQ42 mJ2cTekByXrffhiI2u2inFXU2RFNSv8reZbFRKpUwY7l84qJF/fb7VjSOSMVN331ABB4 bImQ== X-Gm-Message-State: APjAAAVcg8WosuotRdSGeiC0Q7/sGqvpfAWC5oWS9b6/cMmusvfrYFSu ZlhDUPDYj2+9FVVM3jxiRGmTrmSs X-Google-Smtp-Source: APXvYqwR3f4ZJ7rbdljzFq0stseNE7jhQ2o2GQbjzuMnd6x31VkVOMbCAsf4aZX+Dq9Wd8J3Shxa8w== X-Received: by 2002:aca:d4d8:: with SMTP id l207mr1186572oig.29.1552926291260; Mon, 18 Mar 2019 09:24:51 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 11:24:09 -0500 Message-Id: <20190318162410.10183-7-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> References: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::229 Subject: [Qemu-devel] [PULL for-4.0 6/7] qga: process_event() simplification 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, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Simplify the code around qmp_dispatch(): - rely on qmp_dispatch/check_obj() for message checking - have a single send_response() point - constify send_response() argument It changes a couple of error messages: * When @req isn't a dictionary, from Invalid JSON syntax to QMP input must be a JSON object * When @req lacks member "execute", from this feature or command is not currently supported to QMP input lacks member 'execute' CC: Michael Roth Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Michael Roth Reviewed-by: Eric Blake --- qga/main.c | 47 +++++++++-------------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/qga/main.c b/qga/main.c index 87a0711c14..c0d77c79c4 100644 --- a/qga/main.c +++ b/qga/main.c @@ -523,15 +523,15 @@ fail: #endif } =20 -static int send_response(GAState *s, QDict *payload) +static int send_response(GAState *s, const QDict *rsp) { const char *buf; QString *payload_qstr, *response_qstr; GIOStatus status; =20 - g_assert(payload && s->channel); + g_assert(rsp && s->channel); =20 - payload_qstr =3D qobject_to_json(QOBJECT(payload)); + payload_qstr =3D qobject_to_json(QOBJECT(rsp)); if (!payload_qstr) { return -EINVAL; } @@ -557,53 +557,24 @@ static int send_response(GAState *s, QDict *payload) return 0; } =20 -static void process_command(GAState *s, QDict *req) -{ - QDict *rsp; - int ret; - - g_assert(req); - g_debug("processing command"); - rsp =3D qmp_dispatch(&ga_commands, QOBJECT(req), false); - if (rsp) { - ret =3D send_response(s, rsp); - if (ret < 0) { - g_warning("error sending response: %s", strerror(-ret)); - } - qobject_unref(rsp); - } -} - /* handle requests/control events coming in over the channel */ static void process_event(void *opaque, QObject *obj, Error *err) { GAState *s =3D opaque; - QDict *req, *rsp; + QDict *rsp; int ret; =20 g_debug("process_event: called"); assert(!obj !=3D !err); if (err) { - goto err; - } - req =3D qobject_to(QDict, obj); - if (!req) { - error_setg(&err, "Input must be a JSON object"); - goto err; - } - if (!qdict_haskey(req, "execute")) { - g_warning("unrecognized payload format"); - error_setg(&err, QERR_UNSUPPORTED); - goto err; + rsp =3D qmp_error_response(err); + goto end; } =20 - process_command(s, req); - qobject_unref(obj); - return; + g_debug("processing command"); + rsp =3D qmp_dispatch(&ga_commands, obj, false); =20 -err: - g_warning("failed to parse event: %s", error_get_pretty(err)); - rsp =3D qmp_error_response(err); +end: ret =3D send_response(s, rsp); if (ret < 0) { g_warning("error sending error response: %s", strerror(-ret)); --=20 2.17.1 From nobody Sat May 4 08:36:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552926449274520.0695272747006; Mon, 18 Mar 2019 09:27:29 -0700 (PDT) Received: from localhost ([127.0.0.1]:44218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v6f-0002Lt-28 for importer@patchew.org; Mon, 18 Mar 2019 12:27:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5v4O-00012H-CY for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:25:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5v4M-0002oD-Bn for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:59 -0400 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]:43122) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h5v4K-0002kj-TK for qemu-devel@nongnu.org; Mon, 18 Mar 2019 12:24:57 -0400 Received: by mail-ot1-x333.google.com with SMTP id u15so4833676otq.10 for ; Mon, 18 Mar 2019 09:24:55 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id c16sm4055989otl.70.2019.03.18.09.24.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 09:24:52 -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=dNmqkhWd37hmbpmXko8Rbz2l4qYvKu/K6fAkh1eNWTk=; b=leCMu/j9XpsQBwFnUK3KkRrvSDATBql8nVIcQxjgNnrAt0FM1HWHDWqQtprPhjnTYp LxnFUlVLHUgPga3hE5vOoRyOz3FrVjyOor4+Z1q/wkpTxxgYkRaDtpzAdk2/EsFMttIi +fdKIiYyG7GsmSOCOUi2AHTXZYHtmpVH7OsG1CdRPmmHrCpAWOlEcXS/qFfCuai4G0ip LI37JtXUoW/GVlNv3KB0c0jblSBE7mgXDKD/BmjXwwSMer8L5eXvDvEZzmr9I36F0/wR n83FmB9WW2BsY8kCG7EzYp2uKeeBQhd+MrM3MKGPnN1cTEDaEJ/Zyyy2vL2OA2GGBca5 CWyg== 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=dNmqkhWd37hmbpmXko8Rbz2l4qYvKu/K6fAkh1eNWTk=; b=H7pjt89k9L3YCmjBA15UuJdvCpTCV/cjDSUZJToy5MNg3qLK4ZVj2k5GDGoA2vdebO RRjcfwDYg+DtgeYTYezI3RiX7URiw5iKwi7skK0aEc6Azjkq8BhDU9wHp5MgWa/yskdr suWpvhkJIW3rarLauxUNvSLlSnLYiyxYwlARay2KsR9VffMp24PiaZysVtYA2XFx92zh ZQFqvyNdK3r1Ljm9iBnCluwdBmVAHdus9o9TMBi2FpCnX0sK1KCFCyUWHgfmw1n2CXS1 Wn/h+0QQ908Bhsubnbt2pWeP4YG1MxTZfV9PcBWNmuXi3flfdpf1dBU/XjGUbTVuMQ03 aOdw== X-Gm-Message-State: APjAAAUfYojfsVPlMZ1V36QHipGIzrhMWxJcyjWnQPOjr1P2Px5MBKIX jONn5rCaAWASaRgr56NgK5vNiG5W X-Google-Smtp-Source: APXvYqyhbn5CucnibPYIlFUrQgRIpsOBMquzg8PVghoYDIgwEeRSfamNZThGO0LDeJ+YvjSGUqM6Ww== X-Received: by 2002:a9d:760a:: with SMTP id k10mr11095717otl.367.1552926293490; Mon, 18 Mar 2019 09:24:53 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 11:24:10 -0500 Message-Id: <20190318162410.10183-8-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> References: <20190318162410.10183-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::333 Subject: [Qemu-devel] [PULL for-4.0 7/7] qmp: common 'id' handling & make QGA conform to QMP spec 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, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Let qmp_dispatch() copy the 'id' field. That way any qmp client will conform to the specification, including QGA. Furthermore, it simplifies the work for qemu monitor. CC: Michael Roth Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster Signed-off-by: Michael Roth --- monitor.c | 33 ++++++++++++--------------------- qapi/qmp-dispatch.c | 10 ++++++++-- tests/test-qga.c | 13 +++++-------- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/monitor.c b/monitor.c index 72061d5bae..4807bbe811 100644 --- a/monitor.c +++ b/monitor.c @@ -250,8 +250,6 @@ QEMUBH *qmp_dispatcher_bh; struct QMPRequest { /* Owner of the request */ Monitor *mon; - /* "id" field of the request */ - QObject *id; /* * Request object to be handled or Error to be reported * (exactly one of them is non-null) @@ -353,7 +351,6 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *r= eadline_func, =20 static void qmp_request_free(QMPRequest *req) { - qobject_unref(req->id); qobject_unref(req->req); error_free(req->err); g_free(req); @@ -4108,18 +4105,14 @@ static int monitor_can_read(void *opaque) * Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP. * Nothing is emitted then. */ -static void monitor_qmp_respond(Monitor *mon, QDict *rsp, QObject *id) +static void monitor_qmp_respond(Monitor *mon, QDict *rsp) { if (rsp) { - if (id) { - qdict_put_obj(rsp, "id", qobject_ref(id)); - } - qmp_send_response(mon, rsp); } } =20 -static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id) +static void monitor_qmp_dispatch(Monitor *mon, QObject *req) { Monitor *old_mon; QDict *rsp; @@ -4144,7 +4137,7 @@ static void monitor_qmp_dispatch(Monitor *mon, QObjec= t *req, QObject *id) } } =20 - monitor_qmp_respond(mon, rsp, id); + monitor_qmp_respond(mon, rsp); qobject_unref(rsp); } =20 @@ -4208,13 +4201,15 @@ static void monitor_qmp_bh_dispatcher(void *data) mon->qmp.qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1; qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); if (req_obj->req) { - trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: = ""); - monitor_qmp_dispatch(mon, req_obj->req, req_obj->id); + QDict *qdict =3D qobject_to(QDict, req_obj->req); + QObject *id =3D qdict ? qdict_get(qdict, "id") : NULL; + trace_monitor_qmp_cmd_in_band(qobject_get_try_str(id) ?: ""); + monitor_qmp_dispatch(mon, req_obj->req); } else { assert(req_obj->err); rsp =3D qmp_error_response(req_obj->err); req_obj->err =3D NULL; - monitor_qmp_respond(mon, rsp, NULL); + monitor_qmp_respond(mon, rsp); qobject_unref(rsp); } =20 @@ -4239,8 +4234,7 @@ static void handle_qmp_command(void *opaque, QObject = *req, Error *err) =20 qdict =3D qobject_to(QDict, req); if (qdict) { - id =3D qobject_ref(qdict_get(qdict, "id")); - qdict_del(qdict, "id"); + id =3D qdict_get(qdict, "id"); } /* else will fail qmp_dispatch() */ =20 if (req && trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) { @@ -4251,17 +4245,14 @@ static void handle_qmp_command(void *opaque, QObjec= t *req, Error *err) =20 if (qdict && qmp_is_oob(qdict)) { /* OOB commands are executed immediately */ - trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(id) - ?: ""); - monitor_qmp_dispatch(mon, req, id); + trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(id) ?: ""); + monitor_qmp_dispatch(mon, req); qobject_unref(req); - qobject_unref(id); return; } =20 req_obj =3D g_new0(QMPRequest, 1); req_obj->mon =3D mon; - req_obj->id =3D id; req_obj->req =3D req; req_obj->err =3D err; =20 @@ -4281,7 +4272,7 @@ static void handle_qmp_command(void *opaque, QObject = *req, Error *err) =20 /* * Put the request to the end of queue so that requests will be - * handled in time order. Ownership for req_obj, req, id, + * handled in time order. Ownership for req_obj, req, * etc. will be delivered to the handler side. */ assert(mon->qmp.qmp_requests->length < QMP_REQ_QUEUE_LEN_MAX); diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 1d922e04f7..5f812bb9f2 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -58,6 +58,8 @@ static QDict *qmp_dispatch_check_obj(const QObject *reque= st, bool allow_oob, "QMP input member 'arguments' must be an object= "); return NULL; } + } else if (!strcmp(arg_name, "id")) { + continue; } else { error_setg(errp, "QMP input member '%s' is unexpected", arg_name); @@ -165,11 +167,11 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *re= quest, bool allow_oob) { Error *err =3D NULL; - QObject *ret; + QDict *dict =3D qobject_to(QDict, request); + QObject *ret, *id =3D dict ? qdict_get(dict, "id") : NULL; QDict *rsp; =20 ret =3D do_qmp_dispatch(cmds, request, allow_oob, &err); - if (err) { rsp =3D qmp_error_response(err); } else if (ret) { @@ -180,5 +182,9 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *requ= est, rsp =3D NULL; } =20 + if (rsp && id) { + qdict_put_obj(rsp, "id", qobject_ref(id)); + } + return rsp; } diff --git a/tests/test-qga.c b/tests/test-qga.c index 3d6377436a..891aa3d322 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -225,18 +225,15 @@ static void test_qga_ping(gconstpointer fix) qobject_unref(ret); } =20 -static void test_qga_invalid_id(gconstpointer fix) +static void test_qga_id(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret, *error; - const char *class; + QDict *ret; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}"); g_assert_nonnull(ret); - - error =3D qdict_get_qdict(ret, "error"); - class =3D qdict_get_try_str(error, "class"); - g_assert_cmpstr(class, =3D=3D, "GenericError"); + qmp_assert_no_error(ret); + g_assert_cmpint(qdict_get_int(ret, "id"), =3D=3D, 1); =20 qobject_unref(ret); } @@ -992,7 +989,7 @@ int main(int argc, char **argv) g_test_add_data_func("/qga/file-ops", &fix, test_qga_file_ops); g_test_add_data_func("/qga/file-write-read", &fix, test_qga_file_write= _read); g_test_add_data_func("/qga/get-time", &fix, test_qga_get_time); - g_test_add_data_func("/qga/invalid-id", &fix, test_qga_invalid_id); + g_test_add_data_func("/qga/id", &fix, test_qga_id); g_test_add_data_func("/qga/invalid-oob", &fix, test_qga_invalid_oob); g_test_add_data_func("/qga/invalid-cmd", &fix, test_qga_invalid_cmd); g_test_add_data_func("/qga/invalid-args", &fix, test_qga_invalid_args); --=20 2.17.1