From nobody Wed Nov 5 16:33:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536320671544925.5353933946395; Fri, 7 Sep 2018 04:44:31 -0700 (PDT) Received: from localhost ([::1]:38017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyFBX-0002ya-U3 for importer@patchew.org; Fri, 07 Sep 2018 07:44:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyF9c-0000tU-Q5 for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fyF9Y-000488-Pn for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:24 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:55717) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fyF9Y-000434-37 for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:20 -0400 Received: by mail-wm0-f42.google.com with SMTP id f21-v6so14428247wmc.5 for ; Fri, 07 Sep 2018 04:42:17 -0700 (PDT) Received: from fiorina.redhat.com (ip-94-112-73-67.net.upcbroadband.cz. [94.112.73.67]) by smtp.gmail.com with ESMTPSA id z184-v6sm25239813wmz.0.2018.09.07.04.42.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 04:42:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xnR0KRPA31IE8XMw4s1tThS9XN1dRAldDuDCWtG3v4E=; b=ED6Hr5S9GPDaplQuIVuqjKaXyYnvBrM/Gz2tjgnDCyJdloHR7Yx79Gs5tg/Q8Qup8q iEyUO9ZQuUJvCQCciNDbNz3hD+F3PlFfg7l4MYCZ8Jr/u5DdaO/6xn5PZqHMT+b5OVvd e8XgS0WF9BCyfCQ5mtDnr3XkYUjL2HpsF/av/3i4RlF5DrPg9q6KXb8fryMla/q6X/BM kRDoG9BOY3ELUGl695WYZ/I+v39U4TYIGl2rhhUb1zwBPMdRAfOmRbvofRuEYUD3pBnf 8Y4kvnV4AVJdSx6kqOidGgJmMRHRqrjR/23jovSk729UsLkEV6DZKhINffTqPh7sd97Z OspQ== X-Gm-Message-State: APzg51A//V2RHzkhp5FFhpH7MKnetoKNFYePhMI+Gp/9/gV+fqWRe9rP GjagOdLJeXJLVJv8wRRynJmCZokAp1I= X-Google-Smtp-Source: ANB0VdZZe04ptKH1aOb5HBzquZ+vCIme33I/LM/gdDpsQhTXeXaJz5IQK94Tt81vA3w9h8R841VxTg== X-Received: by 2002:a1c:c14:: with SMTP id 20-v6mr5391217wmm.117.1536320536281; Fri, 07 Sep 2018 04:42:16 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: qemu-devel@nongnu.org Date: Fri, 7 Sep 2018 13:42:09 +0200 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.42 Subject: [Qemu-devel] [PATCH v3 1/5] qga: win32: fix crashes when PCI info cannot be retrived 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: Olga Krishtal , =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 The guest-get-fsinfo command collects also information about PCI controller where the disk is attached. When this fails for some reasons it tries to return just the partial information. However in certain cases the pointer to the structure was not initialized and was set to NULL. This breaks the serializer and leads to a crash of the guest agent. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- qga/commands-win32.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 98d9735389..9c959122d9 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -633,15 +633,32 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *guid, Error **errp) * https://technet.microsoft.com/en-us/library/ee851589(v=3Dws.10)= .aspx */ if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_a= d, sizeof(SCSI_ADDRESS), &len, NULL)) { + Error *local_err =3D NULL; disk->unit =3D addr.Lun; disk->target =3D addr.TargetId; disk->bus =3D addr.PathId; - disk->pci_controller =3D get_pci_info(name, errp); + g_debug("unit=3D%lld target=3D%lld bus=3D%lld", + disk->unit, disk->target, disk->bus); + disk->pci_controller =3D get_pci_info(name, &local_err); + + if (local_err) { + g_debug("failed to get PCI controller info: %s", + error_get_pretty(local_err)); + error_free(local_err); + } else if (disk->pci_controller !=3D NULL) { + g_debug("pci: domain=3D%lld bus=3D%lld slot=3D%lld functio= n=3D%lld", + disk->pci_controller->domain, + disk->pci_controller->bus, + disk->pci_controller->slot, + disk->pci_controller->function); + } } - /* We do not set error in this case, because we still have enough - * information about volume. */ - } else { - disk->pci_controller =3D NULL; + } + /* We do not set error in case pci_controller is NULL, because we still + * have enough information about volume. */ + if (disk->pci_controller =3D=3D NULL) { + g_debug("no PCI controller info"); + disk->pci_controller =3D g_malloc0(sizeof(GuestPCIAddress)); } =20 list =3D g_malloc0(sizeof(*list)); --=20 2.18.0 From nobody Wed Nov 5 16:33:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15363206714571011.5301540483773; Fri, 7 Sep 2018 04:44:31 -0700 (PDT) Received: from localhost ([::1]:38020 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyFBZ-00030F-Ak for importer@patchew.org; Fri, 07 Sep 2018 07:44:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyF9d-0000tV-0Y for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fyF9Z-00048V-0k for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:24 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33807) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fyF9Y-00044K-LZ for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:20 -0400 Received: by mail-wr1-f67.google.com with SMTP id g33-v6so14685892wrd.1 for ; Fri, 07 Sep 2018 04:42:18 -0700 (PDT) Received: from fiorina.redhat.com (ip-94-112-73-67.net.upcbroadband.cz. [94.112.73.67]) by smtp.gmail.com with ESMTPSA id z184-v6sm25239813wmz.0.2018.09.07.04.42.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 04:42:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ny5FRgrtFOZqR2U3WjBxnfir1MQtLIZlWrybGTPwMtM=; b=Eu/dcA+mn+ziaQAqk9Q5TuP5dUMMFRPSN/okc+vKLRKimlpkioInA0tsjZaYinPPji T5maQuZFvU9I5nfhq0cFKYgO4Nfzg1jOqmgV2qmS56qNYWbtjyYzljkXgI5zeSU0j91P jhMBXq6qMH8z0dVleCIzCJfqiv7S6pEh5h9LaOCvHJCKay+NDsVcSr/MWECAt+prhAWS IJ/TbhV27f6JcQvL2eHMG8dJYIR3hTvXT5wiFD9Phrd2L4/8ZAJKevVcR4C2ROzJ2vaX G5fGy40LdByMTbuVh0QHOYhtZrvYWInBlFDFo2+D14bEBfX3XkH6EGYr5sRKgf1ybbOY /89g== X-Gm-Message-State: APzg51CbQdmQeSy2bNmA2/+DxQBp2QcmGbBQWJosJLm+6Em0vsu3PqG+ 1J/6kw0H1rek3WVcHdJG3jMvPk4QZxI= X-Google-Smtp-Source: ANB0VdawKctLd1ByfU1NhDE7dGDI4mms2R/LQEQGZ3HtN419tB6KdrRZnZA2brq9r3MmVev6oK1Z9Q== X-Received: by 2002:adf:f0c8:: with SMTP id x8-v6mr6235956wro.49.1536320537559; Fri, 07 Sep 2018 04:42:17 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: qemu-devel@nongnu.org Date: Fri, 7 Sep 2018 13:42:10 +0200 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.221.67 Subject: [Qemu-devel] [PATCH v3 2/5] build: rename CONFIG_QGA_NTDDDISK to CONFIG_QGA_NTDDSCSI 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: Olga Krishtal , =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 There was inconsistency between commits: 50cbebb9a3 configure: add configure check for ntdddisk.h a3ef3b2272 qga: added bus type and disk location path The first commit added #define CONFIG_QGA_NTDDDISK but the second commit expected the name to be CONFIG_QGA_NTDDSCSI. As a result the code in second patch was never used. Renaming the option to CONFIG_QGA_NTDDSCSI to match the name of header file that is being checked for. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 58862d2ae8..0f168607e8 100755 --- a/configure +++ b/configure @@ -6201,7 +6201,7 @@ if test "$mingw32" =3D "yes" ; then echo "WIN_SDK=3D\"$win_sdk\"" >> $config_host_mak fi if test "$guest_agent_ntddscsi" =3D "yes" ; then - echo "CONFIG_QGA_NTDDDISK=3Dy" >> $config_host_mak + echo "CONFIG_QGA_NTDDSCSI=3Dy" >> $config_host_mak fi if test "$guest_agent_msi" =3D "yes"; then echo "QEMU_GA_MSI_ENABLED=3Dyes" >> $config_host_mak --=20 2.18.0 From nobody Wed Nov 5 16:33:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536320672669322.2011325064368; Fri, 7 Sep 2018 04:44:32 -0700 (PDT) Received: from localhost ([::1]:38019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyFBY-0002za-Vf for importer@patchew.org; Fri, 07 Sep 2018 07:44:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36688) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyF9d-0000tW-5l for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fyF9Z-00048j-3f for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:25 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:53157) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fyF9Y-00046e-OU for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:20 -0400 Received: by mail-wm0-f53.google.com with SMTP id y139-v6so14323940wmc.2 for ; Fri, 07 Sep 2018 04:42:20 -0700 (PDT) Received: from fiorina.redhat.com (ip-94-112-73-67.net.upcbroadband.cz. [94.112.73.67]) by smtp.gmail.com with ESMTPSA id z184-v6sm25239813wmz.0.2018.09.07.04.42.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 04:42:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8pl2VA6Cid++Qn2KS9lC9ILyRJ2b8EWTQPL7DYjPfo8=; b=AHY+XxFmayW0tb2gAEhGcSlR2XKf7cJ1VmKfqmJ7fbOZzoYRzPzjlWgX2F/hGJ2pVE 4HB5Y3COnsnG1tnStuf3IKGehRsZuaiJrCK17ePlUWF4rjfzqYiaUdPeZ0busoigutF7 0TBmqMEqagz6UfR38DckTqISw2VCW0H3bfcFFXTa2ybqupkdFUk1tpvMqVNrr9C2bePx 4rX/kBxzxV0YTOT8Uj2VAEn/kuVWX+rzr4drdlJnkGkfswR1BZ4I1CQLVWbCUD1Bkose iFEetCXDJEmhqBUCMOPU1KPMiGzfcgb4ONJXJ93L1LXXgrNwKuqB/+hTuM8Zd8RR8Atr C3kA== X-Gm-Message-State: APzg51DZpiaIBAIh5nx4yGEZkjXuRVmUo3MutEIf4qlmLEfJIzEtOgcM r8PVCxnKImm1IBVTx76VJJSrDS/treE= X-Google-Smtp-Source: ANB0VdbYC4a0MqyXLjdyHFZWyrHmCa91lixfS7QYAbygF56vGvEScWFerWq3Zy+QqsW80sPbOfKBAg== X-Received: by 2002:a1c:4d09:: with SMTP id o9-v6mr5175028wmh.134.1536320539078; Fri, 07 Sep 2018 04:42:19 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: qemu-devel@nongnu.org Date: Fri, 7 Sep 2018 13:42:11 +0200 Message-Id: <6614d7912a3ce65158ff17f977fd9b7c1aa45559.1536320522.git.tgolembi@redhat.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.53 Subject: [Qemu-devel] [PATCH v3 3/5] qga: win32: add debugging information 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: Olga Krishtal , =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 The windows code generaly lacks debug information (compared to posix code). This patch adds some related to HW info in guest-get-fsinfo command. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- qga/commands-win32.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 9c959122d9..e16c58275e 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -89,6 +89,12 @@ static OpenFlags guest_file_open_modes[] =3D { {"a+b", FILE_GENERIC_APPEND|GENERIC_READ, OPEN_ALWAYS } }; =20 +#define g_debug_err(msg) do { \ + char *suffix =3D g_win32_error_message(GetLastError()); \ + g_debug("%s: %s", (msg), suffix); \ + g_free(suffix); \ +} while(0) + static OpenFlags *find_open_flag(const char *mode_str) { int mode; @@ -498,6 +504,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error = **errp) goto out; } =20 + g_debug("enumerating devices"); dev_info_data.cbSize =3D sizeof(SP_DEVINFO_DATA); for (i =3D 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++)= { DWORD addr, bus, slot, func, dev, data, size2; @@ -522,6 +529,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error = **errp) if (g_strcmp0(buffer, dev_name)) { continue; } + 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 @@ -530,6 +538,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error = **errp) */ if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_BUSNUMBER, &data, (PBYTE)&bus, size, NULL)) { + g_debug_err("failed to get bus"); break; } =20 @@ -537,6 +546,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error = **errp) * transformed into device function and number */ if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_ADDRESS, &data, (PBYTE)&addr, size, NULL)) { + g_debug_err("failed to get address"); break; } =20 @@ -544,6 +554,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error = **errp) * This number is typically a user-perceived slot number. */ if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_UI_NUMBER, &data, (PBYTE)&slot, size, NULL)) { + g_debug_err("failed to get slot"); break; } =20 @@ -608,6 +619,7 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) scsi_ad =3D &addr; char *name =3D g_strndup(guid, strlen(guid)-1); =20 + g_debug("getting disk info for: %s", name); vol_h =3D CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (vol_h =3D=3D INVALID_HANDLE_VALUE) { @@ -615,6 +627,7 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) goto out_free; } =20 + g_debug("getting bus type"); bus =3D get_disk_bus_type(vol_h, errp); if (bus < 0) { goto out_close; @@ -622,6 +635,7 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) =20 disk =3D g_malloc0(sizeof(*disk)); disk->bus_type =3D find_bus_type(bus); + g_debug("bus type %d", disk->bus_type); if (bus =3D=3D BusTypeScsi || bus =3D=3D BusTypeAta || bus =3D=3D BusT= ypeRAID #if (_WIN32_WINNT >=3D 0x0600) /* This bus type is not supported before Windows Server 2003 S= P1 */ @@ -631,6 +645,7 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, 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"); if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_a= d, sizeof(SCSI_ADDRESS), &len, NULL)) { Error *local_err =3D NULL; --=20 2.18.0 From nobody Wed Nov 5 16:33:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536320819976830.0775071198984; Fri, 7 Sep 2018 04:46:59 -0700 (PDT) Received: from localhost ([::1]:38037 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyFE2-0004uT-TA for importer@patchew.org; Fri, 07 Sep 2018 07:46:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36710) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyF9e-0000ts-On for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fyF9a-0004AX-Jt for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:26 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:37980) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fyF9a-00049q-99 for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:22 -0400 Received: by mail-wm0-f44.google.com with SMTP id t25-v6so14296280wmi.3 for ; Fri, 07 Sep 2018 04:42:22 -0700 (PDT) Received: from fiorina.redhat.com (ip-94-112-73-67.net.upcbroadband.cz. [94.112.73.67]) by smtp.gmail.com with ESMTPSA id z184-v6sm25239813wmz.0.2018.09.07.04.42.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 04:42:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z+RgIiLmkHxRecpFDD5pjxCKiIK0Hw1NMVMZCifrFaY=; b=DM/ylk+syL5MhpqLim3/SR8GA8InavUjdpiLLvRcPza6st2Dhf/HdFRh0ul+eodOAJ Dtzq9HsJrifeI2n8dtk7RwXfSV/v/NwoKdJskoD1qw7I3IAlmGehJxWk3hiY0am112rJ tJBVL80RWZ0eoQt/T15FuuiacDMqrlrIPquPAWeb5y/ExUPJX4TWxXJtZE3NZqU9XSiP CEHvAdvmo5CDuh0mp+dm99AJA/SeiHrh/qD4sXt/kKVqqq3JT0H2XNzhJbnxDVTkfivS /Cvg/QmoRsKTQ9Qhp70Q29sBHal38cOHRvB3x8m+GH8oZeMF4kDEVQv4Up2wOu70vgoh zzgA== X-Gm-Message-State: APzg51DzIy9wLT6Hr0xvI3fSKHQE4XjpwKBvM9pJHF86eQL8gYQ0qt0P nU76ONHyJ6cyIW3kDifo70a5UNtZWdM= X-Google-Smtp-Source: ANB0VdbRcC9GnMg7tql8r4X0Z5T3WiClu0mvCiDQ1kdPK2ZmcWNDjG5xudRqzhh0A9CKE0SAYELDKQ== X-Received: by 2002:a1c:1bc2:: with SMTP id b185-v6mr5416335wmb.160.1536320540647; Fri, 07 Sep 2018 04:42:20 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: qemu-devel@nongnu.org Date: Fri, 7 Sep 2018 13:42:12 +0200 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.44 Subject: [Qemu-devel] [PATCH v3 4/5] qga: report disk serial number 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: Olga Krishtal , =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 The feature is implemented for Windows and Linux. Reporting of serial number on Linux depends on libudev. Example from Linux: { "name": "dm-2", "mountpoint": "/", ... "disk": [ { "serial": "SAMSUNG_MZ7LN512HCHP-000L1_S1ZKNXAG822493", ... } ], } Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- configure | 22 ++++++++++++++ qga/Makefile.objs | 1 + qga/commands-posix.c | 22 ++++++++++++++ qga/commands-win32.c | 71 ++++++++++++++++++++++++++++++++------------ qga/qapi-schema.json | 4 ++- 5 files changed, 100 insertions(+), 20 deletions(-) diff --git a/configure b/configure index 0f168607e8..ac24cb3975 100755 --- a/configure +++ b/configure @@ -477,6 +477,7 @@ libxml2=3D"" docker=3D"no" debug_mutex=3D"no" libpmem=3D"" +libudev=3D"no" =20 # cross compilers defaults, can be overridden with --cross-cc-ARCH cross_cc_aarch64=3D"aarch64-linux-gnu-gcc" @@ -873,6 +874,7 @@ Linux) vhost_vsock=3D"yes" QEMU_INCLUDES=3D"-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QE= MU_INCLUDES" supported_os=3D"yes" + libudev=3D"yes" ;; esac =20 @@ -5676,6 +5678,20 @@ if test "$libnfs" !=3D "no" ; then fi fi =20 +########################################## +# Do we have libudev +if test "$libudev" !=3D "no" ; then + if $pkg_config libudev; then + libudev=3D"yes" + libudev_libs=3D$($pkg_config --libs libudev) + else + if test "$libudev" =3D "yes" ; then + feature_not_found "libudev" "Install systemd development files" + fi + libudev=3D"no" + fi +fi + # Now we've finished running tests it's OK to add -Werror to the compiler = flags if test "$werror" =3D "yes"; then QEMU_CFLAGS=3D"-Werror $QEMU_CFLAGS" @@ -6100,6 +6116,7 @@ echo "VxHS block device $vxhs" echo "capstone $capstone" echo "docker $docker" echo "libpmem support $libpmem" +echo "libudev $libudev" =20 if test "$sdl_too_old" =3D "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support" @@ -6944,6 +6961,11 @@ if test "$docker" !=3D "no"; then echo "HAVE_USER_DOCKER=3Dy" >> $config_host_mak fi =20 +if test "$libudev" !=3D "no"; then + echo "CONFIG_LIBUDEV=3Dy" >> $config_host_mak + echo "LIBUDEV_LIBS=3D$libudev_libs" >> $config_host_mak +fi + # use included Linux headers if test "$linux" =3D "yes" ; then mkdir -p linux-headers diff --git a/qga/Makefile.objs b/qga/Makefile.objs index ed08c5917c..80e6bb3c2e 100644 --- a/qga/Makefile.objs +++ b/qga/Makefile.objs @@ -1,3 +1,4 @@ +commands-posix.o-libs :=3D $(LIBUDEV_LIBS) qga-obj-y =3D commands.o guest-agent-command-state.o main.o qga-obj-$(CONFIG_POSIX) +=3D commands-posix.o channel-posix.o qga-obj-$(CONFIG_WIN32) +=3D commands-win32.o channel-win32.o service-win3= 2.o diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 37e8a2d791..37fedd123b 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -47,6 +47,7 @@ extern char **environ; #include #include #include +#include =20 #ifdef FIFREEZE #define CONFIG_FSFREEZE @@ -872,6 +873,10 @@ static void build_guest_fsinfo_for_real_device(char co= nst *syspath, GuestDiskAddressList *list =3D NULL; bool has_ata =3D false, has_host =3D false, has_tgt =3D false; char *p, *q, *driver =3D NULL; +#ifdef CONFIG_LIBUDEV + struct udev *udev =3D NULL; + struct udev_device *udevice =3D NULL; +#endif =20 p =3D strstr(syspath, "/devices/pci"); if (!p || sscanf(p + 12, "%*x:%*x/%x:%x:%x.%x%n", @@ -936,6 +941,21 @@ static void build_guest_fsinfo_for_real_device(char co= nst *syspath, list =3D g_malloc0(sizeof(*list)); list->value =3D disk; =20 +#ifdef CONFIG_LIBUDEV + udev =3D udev_new(); + udevice =3D udev_device_new_from_syspath(udev, syspath); + if (udev =3D=3D NULL || udevice =3D=3D NULL) { + g_debug("failed to query udev"); + } else { + const char *serial; + serial =3D udev_device_get_property_value(udevice, "ID_SERIAL"); + if (serial !=3D NULL && *serial !=3D 0) { + disk->serial =3D g_strdup(serial); + disk->has_serial =3D true; + } + } +#endif + if (strcmp(driver, "ata_piix") =3D=3D 0) { /* a host per ide bus, target*:0::0 */ if (!has_host || !has_tgt) { @@ -1003,6 +1023,8 @@ cleanup: qapi_free_GuestDiskAddressList(list); } g_free(driver); + udev_unref(udev); + udev_device_unref(udevice); } =20 static void build_guest_fsinfo_for_device(char const *devpath, diff --git a/qga/commands-win32.c b/qga/commands-win32.c index e16c58275e..fa186154a8 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -583,25 +583,53 @@ out: return pci; } =20 -static int get_disk_bus_type(HANDLE vol_h, Error **errp) +static void get_disk_properties(HANDLE vol_h, GuestDiskAddress *disk, + Error **errp) { STORAGE_PROPERTY_QUERY query; STORAGE_DEVICE_DESCRIPTOR *dev_desc, buf; DWORD received; + ULONG size =3D sizeof(buf); =20 dev_desc =3D &buf; - dev_desc->Size =3D sizeof(buf); query.PropertyId =3D StorageDeviceProperty; query.QueryType =3D PropertyStandardQuery; =20 if (!DeviceIoControl(vol_h, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(STORAGE_PROPERTY_QUERY), dev_desc, - dev_desc->Size, &received, NULL)) { + size, &received, NULL)) { error_setg_win32(errp, GetLastError(), "failed to get bus type"); - return -1; + return; + } + disk->bus_type =3D find_bus_type(dev_desc->BusType); + g_debug("bus type %d", disk->bus_type); + + /* Query once more. Now with long enough buffer. */ + size =3D dev_desc->Size; + dev_desc =3D g_malloc0(size); + if (!DeviceIoControl(vol_h, IOCTL_STORAGE_QUERY_PROPERTY, &query, + sizeof(STORAGE_PROPERTY_QUERY), dev_desc, + size, &received, NULL)) { + error_setg_win32(errp, GetLastError(), "failed to get serial numbe= r"); + goto out_free; + } + if (dev_desc->SerialNumberOffset > 0) { + if (dev_desc->SerialNumberOffset >=3D received) { + error_setg(errp, "offset outside the buffer"); + goto out_free; + } + const char *serial =3D (char *)dev_desc + dev_desc->SerialNumberOf= fset; + size_t len =3D received - dev_desc->SerialNumberOffset; + if (*serial !=3D 0) { + disk->serial =3D g_strndup(serial, len); + disk->has_serial =3D true; + g_debug("serial number %s", disk->serial); + } } +out_free: + g_free(dev_desc); =20 - return dev_desc->BusType; + return; } =20 /* VSS provider works with volumes, thus there is no difference if @@ -613,8 +641,8 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) GuestDiskAddress *disk; SCSI_ADDRESS addr, *scsi_ad; DWORD len; - int bus; HANDLE vol_h; + Error *local_err =3D NULL; =20 scsi_ad =3D &addr; char *name =3D g_strndup(guid, strlen(guid)-1); @@ -624,22 +652,22 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *guid, Error **errp) 0, NULL); if (vol_h =3D=3D INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to open volume"); - goto out_free; + goto err; } =20 - g_debug("getting bus type"); - bus =3D get_disk_bus_type(vol_h, errp); - if (bus < 0) { - goto out_close; + disk =3D g_malloc0(sizeof(*disk)); + get_disk_properties(vol_h, disk, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto err_close; } =20 - disk =3D g_malloc0(sizeof(*disk)); - disk->bus_type =3D find_bus_type(bus); - g_debug("bus type %d", disk->bus_type); - if (bus =3D=3D BusTypeScsi || bus =3D=3D BusTypeAta || bus =3D=3D BusT= ypeRAID + if (disk->bus_type =3D=3D GUEST_DISK_BUS_TYPE_SCSI + || disk->bus_type =3D=3D GUEST_DISK_BUS_TYPE_IDE + || disk->bus_type =3D=3D GUEST_DISK_BUS_TYPE_RAID #if (_WIN32_WINNT >=3D 0x0600) /* This bus type is not supported before Windows Server 2003 S= P1 */ - || bus =3D=3D BusTypeSas + || disk->bus_type =3D=3D GUEST_DISK_BUS_TYPE_SAS #endif ) { /* We are able to use the same ioctls for different bus types @@ -679,11 +707,16 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *guid, Error **errp) list =3D g_malloc0(sizeof(*list)); list->value =3D disk; list->next =3D NULL; -out_close: CloseHandle(vol_h); -out_free: - g_free(name); return list; + +err_close: + g_free(disk); + CloseHandle(vol_h); +err: + g_free(name); + + return NULL; } =20 #else diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index dfbc4a5e32..3bcda6257e 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -834,13 +834,15 @@ # @bus: bus id # @target: target id # @unit: unit id +# @serial: serial number (since: 3.1) # # Since: 2.2 ## { 'struct': 'GuestDiskAddress', 'data': {'pci-controller': 'GuestPCIAddress', 'bus-type': 'GuestDiskBusType', - 'bus': 'int', 'target': 'int', 'unit': 'int'} } + 'bus': 'int', 'target': 'int', 'unit': 'int', + '*serial': 'str'} } =20 ## # @GuestFilesystemInfo: --=20 2.18.0 From nobody Wed Nov 5 16:33:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536320818612174.9042148730399; Fri, 7 Sep 2018 04:46:58 -0700 (PDT) Received: from localhost ([::1]:38036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyFE1-0004uN-Hl for importer@patchew.org; Fri, 07 Sep 2018 07:46:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyF9g-0000vS-19 for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fyF9b-0004BU-QE for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:27 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:50803) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fyF9b-0004Ap-JC for qemu-devel@nongnu.org; Fri, 07 Sep 2018 07:42:23 -0400 Received: by mail-wm0-f67.google.com with SMTP id s12-v6so14473712wmc.0 for ; Fri, 07 Sep 2018 04:42:23 -0700 (PDT) Received: from fiorina.redhat.com (ip-94-112-73-67.net.upcbroadband.cz. [94.112.73.67]) by smtp.gmail.com with ESMTPSA id z184-v6sm25239813wmz.0.2018.09.07.04.42.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 04:42:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RftnKltFhwuP6R629aoH79l3ckMGlV3RUfjayNzzB4Y=; b=izavvCgwfy1aKxUdZyVfhXgVFN6tSe+sJxDfoB2JFCF03rjVqO/mMcWYgd65eocZMd 9b52/6cyioLdHSalD59tjBKAQ9rtJp8LHyhBuzYzYombQKYbxTYzKil+ftpiqRn9LQPP +baCmUPC2JPsf/+s1IyYU2ZFVe6e5vxiNxf+cbrXw/heLeEVPwFTnGOPJn6D28aAisPj +99IH4vllvti+9f6P95UMKqGE1fe5SRe1T6foNzgp79GX1EzziJioTyQkvrFp6Kvx5fn 9KduhZZH17yP/vr2w9YUEo0c8AZFA3PxcBynkGQWXlWMQn4fa2GnWJJEdp7qi7rRJAj0 FvzA== X-Gm-Message-State: APzg51Duf8/xUi7KN1GV7bdTb+dlx1vvFdKG9UpDPgvpEiT7uiT/H0U9 QHd35goyAi96ssXjVrqjN06FYSyWIKQ= X-Google-Smtp-Source: ANB0VdZB2/7shPB7pIHkiTBg7v257GnrYeRAg9muEson4VNmhnIVYq8rmcfMedy6B2v/3AdNiC3UAg== X-Received: by 2002:a1c:4c0c:: with SMTP id z12-v6mr5365208wmf.57.1536320541938; Fri, 07 Sep 2018 04:42:21 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: qemu-devel@nongnu.org Date: Fri, 7 Sep 2018 13:42:13 +0200 Message-Id: <88c65dd59a7bbf55ad055447cccf4be39fcb824b.1536320522.git.tgolembi@redhat.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.67 Subject: [Qemu-devel] [PATCH v3 5/5] qga: return disk device in guest-get-fsinfo 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: Olga Krishtal , =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Report device node of the disk. It is implemented for Linux (needs udev) and Windows. The node is reported e.g. as "/dev/sda2" on Linux and as "\\?\PhysicalDriveX" on Windows. As part of this effort the Windows code was changed to probe disk extents and return list of all disks. Originally only first disk of composite volume was returned. Note that the patch changes get_pci_info() from one state of brokenness into a different state of brokenness. In other words it still does not do what it's supposed to do (see comment in code). If anyone knows how to fix it, please step in. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- qga/commands-posix.c | 7 +- qga/commands-win32.c | 163 +++++++++++++++++++++++++++++++++++-------- qga/qapi-schema.json | 3 +- 3 files changed, 142 insertions(+), 31 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 37fedd123b..d0d6ba49cb 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -947,7 +947,12 @@ static void build_guest_fsinfo_for_real_device(char co= nst *syspath, if (udev =3D=3D NULL || udevice =3D=3D NULL) { g_debug("failed to query udev"); } else { - const char *serial; + const char *devnode, *serial; + devnode =3D udev_device_get_devnode(udevice); + if (devnode !=3D NULL) { + disk->dev =3D g_strdup(devnode); + disk->has_dev =3D true; + } serial =3D udev_device_get_property_value(udevice, "ID_SERIAL"); if (serial !=3D NULL && *serial !=3D 0) { disk->serial =3D g_strdup(serial); diff --git a/qga/commands-win32.c b/qga/commands-win32.c index fa186154a8..2cde6bd0af 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -477,9 +477,26 @@ static GuestDiskBusType find_bus_type(STORAGE_BUS_TYPE= 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); + =20 static GuestPCIAddress *get_pci_info(char *guid, Error **errp) { @@ -497,7 +514,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error = **errp) goto out; } =20 - dev_info =3D SetupDiGetClassDevs(&GUID_DEVINTERFACE_VOLUME, 0, 0, + dev_info =3D SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (dev_info =3D=3D INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to get devices tree= "); @@ -632,31 +649,24 @@ out_free: return; } =20 -/* VSS provider works with volumes, thus there is no difference if - * the volume consist of spanned disks. Info about the first disk in the - * volume is returned for the spanned disk group (LVM) */ -static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **err= p) +static void get_single_disk_info(GuestDiskAddress *disk, Error **errp) { - GuestDiskAddressList *list =3D NULL; - GuestDiskAddress *disk; SCSI_ADDRESS addr, *scsi_ad; DWORD len; - HANDLE vol_h; + HANDLE disk_h; Error *local_err =3D NULL; =20 scsi_ad =3D &addr; - char *name =3D g_strndup(guid, strlen(guid)-1); =20 - g_debug("getting disk info for: %s", name); - vol_h =3D CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, + g_debug("getting disk info for: %s", disk->dev); + disk_h =3D CreateFile(disk->dev, 0, FILE_SHARE_READ, NULL, OPEN_EXISTI= NG, 0, NULL); - if (vol_h =3D=3D INVALID_HANDLE_VALUE) { - error_setg_win32(errp, GetLastError(), "failed to open volume"); - goto err; + if (disk_h =3D=3D INVALID_HANDLE_VALUE) { + error_setg_win32(errp, GetLastError(), "failed to open disk"); + return; } =20 - disk =3D g_malloc0(sizeof(*disk)); - get_disk_properties(vol_h, disk, &local_err); + get_disk_properties(disk_h, disk, &local_err); if (local_err) { error_propagate(errp, local_err); goto err_close; @@ -674,20 +684,20 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *guid, Error **errp) * according to Microsoft docs * https://technet.microsoft.com/en-us/library/ee851589(v=3Dws.10)= .aspx */ g_debug("getting pci-controller info"); - if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_a= d, + if (DeviceIoControl(disk_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_= ad, sizeof(SCSI_ADDRESS), &len, NULL)) { - Error *local_err =3D NULL; disk->unit =3D addr.Lun; disk->target =3D addr.TargetId; disk->bus =3D addr.PathId; g_debug("unit=3D%lld target=3D%lld bus=3D%lld", disk->unit, disk->target, disk->bus); - disk->pci_controller =3D get_pci_info(name, &local_err); + disk->pci_controller =3D get_pci_info(disk->dev, &local_err); =20 if (local_err) { g_debug("failed to get PCI controller info: %s", error_get_pretty(local_err)); error_free(local_err); + local_err =3D NULL; } else if (disk->pci_controller !=3D NULL) { g_debug("pci: domain=3D%lld bus=3D%lld slot=3D%lld functio= n=3D%lld", disk->pci_controller->domain, @@ -704,19 +714,107 @@ static GuestDiskAddressList *build_guest_disk_info(c= har *guid, Error **errp) disk->pci_controller =3D g_malloc0(sizeof(GuestPCIAddress)); } =20 - list =3D g_malloc0(sizeof(*list)); - list->value =3D disk; - list->next =3D NULL; - CloseHandle(vol_h); - return list; - err_close: + CloseHandle(disk_h); + return; +} + +static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **err= p) +{ + Error *local_err =3D NULL; + GuestDiskAddressList *list =3D NULL, *cur_item =3D NULL; + GuestDiskAddress *disk =3D NULL; + int i; + HANDLE vol_h; + DWORD size; + PVOLUME_DISK_EXTENTS extents =3D NULL; + + /* strip final backslash */ + char *name =3D g_strndup(guid, strlen(guid)-1); + + g_debug("opening %s", name); + vol_h =3D CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, + 0, NULL); + if (vol_h =3D=3D INVALID_HANDLE_VALUE) { + error_setg_win32(errp, GetLastError(), "failed to open volume"); + goto out; + } + + /* Get list of extents */ + g_debug("getting disk extents"); + 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)) { + 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( + vol_h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, + 0, extents, size, NULL, NULL)) { + error_setg_win32(errp, GetLastError(), "failed to get disk= extents"); + return NULL; + } + } else if (last_err =3D=3D ERROR_INVALID_FUNCTION) { + /* Possibly CD-ROM or a shared drive. Try to pass the volume */ + g_debug("volume not on disk"); + disk =3D g_malloc0(sizeof(GuestDiskAddress)); + disk->has_dev =3D true; + disk->dev =3D g_strdup(name); + get_single_disk_info(disk, &local_err); + if (local_err) { + g_debug("failed to get disk info, ignoring error: %s", + error_get_pretty(local_err)); + error_free(local_err); + goto out; + } + list =3D g_malloc0(sizeof(*list)); + list->value =3D disk; + disk =3D NULL; + list->next =3D NULL; + goto out; + } else { + error_setg_win32(errp, GetLastError(), "failed to get disk ext= ents"); + goto out; + } + } + g_debug("Number of extents: %lu", extents->NumberOfDiskExtents); + + /* Go through each extent */ + for (i =3D 0; i < extents->NumberOfDiskExtents; i++) { + disk =3D g_malloc0(sizeof(GuestDiskAddress)); + + /* Disk numbers directly correspond to numbers used in UNCs + * See documentation for DISK_EXTENT: + * https://docs.microsoft.com/en-us/windows/desktop/api/winioctl/n= s-winioctl-_disk_extent + */ + disk->has_dev =3D true; + disk->dev =3D g_strdup_printf("\\\\?\\PhysicalDrive%lu", + extents->Extents[i].DiskNumber); + + get_single_disk_info(disk, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + cur_item =3D g_malloc0(sizeof(*list)); + cur_item->value =3D disk; + disk =3D NULL; + cur_item->next =3D list; + list =3D cur_item; + } + + +out: + g_free(extents); g_free(disk); - CloseHandle(vol_h); -err: g_free(name); =20 - return NULL; + return list; } =20 #else @@ -783,6 +881,12 @@ static GuestFilesystemInfo *build_guest_fsinfo(char *g= uid, Error **errp) } fs->type =3D g_strdup(fs_name); fs->disk =3D build_guest_disk_info(guid, errp); + if (fs->disk =3D=3D NULL) { + g_free(fs); + fs =3D NULL; + goto free; + } + free: g_free(mnt_point); return fs; @@ -803,7 +907,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **e= rrp) do { GuestFilesystemInfo *info =3D build_guest_fsinfo(guid, errp); if (info =3D=3D NULL) { - continue; + goto out; } new =3D g_malloc(sizeof(*ret)); new->value =3D info; @@ -815,6 +919,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **e= rrp) error_setg_win32(errp, GetLastError(), "failed to find next volume= "); } =20 +out: FindVolumeClose(vol_h); return ret; } diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 3bcda6257e..c6725b3ec8 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -835,6 +835,7 @@ # @target: target id # @unit: unit id # @serial: serial number (since: 3.1) +# @dev: device node (POSIX) or device UNC (Windows) (since: 3.1) # # Since: 2.2 ## @@ -842,7 +843,7 @@ 'data': {'pci-controller': 'GuestPCIAddress', 'bus-type': 'GuestDiskBusType', 'bus': 'int', 'target': 'int', 'unit': 'int', - '*serial': 'str'} } + '*serial': 'str', '*dev': 'str'} } =20 ## # @GuestFilesystemInfo: --=20 2.18.0