diff mbox series

[v4,04/11] qga-win: add debugging information

Message ID f6d66487b5d9aa0e8e1c3bda856746ba58cabeae.1538652143.git.tgolembi@redhat.com
State New
Headers show
Series qga: report serial number and disk node | expand

Commit Message

Tomáš Golembiovský Oct. 4, 2018, 11:22 a.m. UTC
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áš Golembiovský <tgolembi@redhat.com>
---
 qga/commands-win32.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Marc-André Lureau Oct. 4, 2018, 1:21 p.m. UTC | #1
Hi

On Thu, Oct 4, 2018 at 3:22 PM Tomáš Golembiovský <tgolembi@redhat.com> wrote:
>
> 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áš Golembiovský <tgolembi@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  qga/commands-win32.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 49fc747298..2a7a3af614 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -89,6 +89,12 @@ static OpenFlags guest_file_open_modes[] = {
>      {"a+b", FILE_GENERIC_APPEND|GENERIC_READ, OPEN_ALWAYS  }
>  };
>
> +#define debug_error(msg) do { \
> +    char *suffix = 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;
>      }
>
> +    g_debug("enumerating devices");
>      dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA);
>      for (i = 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);
>
>          /* 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)) {
> +            debug_error("failed to get bus");
>              break;
>          }
>
> @@ -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)) {
> +            debug_error("failed to get address");
>              break;
>          }
>
> @@ -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)) {
> +            debug_error("failed to get slot");
>              break;
>          }
>
> @@ -608,6 +619,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
>      scsi_ad = &addr;
>      char *name = g_strndup(guid, strlen(guid)-1);
>
> +    g_debug("getting disk info for: %s", name);
>      vol_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
>                         0, NULL);
>      if (vol_h == INVALID_HANDLE_VALUE) {
> @@ -615,6 +627,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
>          goto out_free;
>      }
>
> +    g_debug("getting bus type");
>      bus = 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)
>
>      disk = g_malloc0(sizeof(*disk));
>      disk->bus_type = find_bus_type(bus);
> +    g_debug("bus type %d", disk->bus_type);
>      if (bus == BusTypeScsi || bus == BusTypeAta || bus == BusTypeRAID
>  #if (_WIN32_WINNT >= 0x0600)
>              /* This bus type is not supported before Windows Server 2003 SP1 */
> @@ -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=ws.10).aspx */
> +        g_debug("getting pci-controller info");
>          if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_ad,
>                              sizeof(SCSI_ADDRESS), &len, NULL)) {
>              Error *local_err = NULL;
> --
> 2.19.0
>
diff mbox series

Patch

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 49fc747298..2a7a3af614 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -89,6 +89,12 @@  static OpenFlags guest_file_open_modes[] = {
     {"a+b", FILE_GENERIC_APPEND|GENERIC_READ, OPEN_ALWAYS  }
 };
 
+#define debug_error(msg) do { \
+    char *suffix = 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;
     }
 
+    g_debug("enumerating devices");
     dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA);
     for (i = 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);
 
         /* 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)) {
+            debug_error("failed to get bus");
             break;
         }
 
@@ -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)) {
+            debug_error("failed to get address");
             break;
         }
 
@@ -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)) {
+            debug_error("failed to get slot");
             break;
         }
 
@@ -608,6 +619,7 @@  static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
     scsi_ad = &addr;
     char *name = g_strndup(guid, strlen(guid)-1);
 
+    g_debug("getting disk info for: %s", name);
     vol_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
                        0, NULL);
     if (vol_h == INVALID_HANDLE_VALUE) {
@@ -615,6 +627,7 @@  static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
         goto out_free;
     }
 
+    g_debug("getting bus type");
     bus = 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)
 
     disk = g_malloc0(sizeof(*disk));
     disk->bus_type = find_bus_type(bus);
+    g_debug("bus type %d", disk->bus_type);
     if (bus == BusTypeScsi || bus == BusTypeAta || bus == BusTypeRAID
 #if (_WIN32_WINNT >= 0x0600)
             /* This bus type is not supported before Windows Server 2003 SP1 */
@@ -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=ws.10).aspx */
+        g_debug("getting pci-controller info");
         if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_ad,
                             sizeof(SCSI_ADDRESS), &len, NULL)) {
             Error *local_err = NULL;