All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tomáš Golembiovský" <tgolembi@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Eric Blake" <eblake@redhat.com>,
	"Sameeh Jubran" <sjubran@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Olga Krishtal" <okrishtal@virtuozzo.com>,
	"Michael Roth" <mdroth@linux.vnet.ibm.com>,
	"Tomáš Golembiovský" <tgolembi@redhat.com>
Subject: [Qemu-devel] [PATCH v4 05/11] qga-win: refactor disk properties (bus)
Date: Thu,  4 Oct 2018 13:22:32 +0200	[thread overview]
Message-ID: <f52540791edaf07805d9acaa8b5e795e847904a7.1538652143.git.tgolembi@redhat.com> (raw)
In-Reply-To: <cover.1538652143.git.tgolembi@redhat.com>

Refactor code that queries bus type to be more generic. The function
get_disk_bus_type() has been renamed to build_guest_disk_info().
Following commit(s) will extend this function.

Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
---
 qga/commands-win32.c | 46 +++++++++++++++++++++++++++-----------------
 1 file changed, 28 insertions(+), 18 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 2a7a3af614..d7864fc65a 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -583,25 +583,29 @@ out:
     return pci;
 }
 
-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 = sizeof(buf);
 
     dev_desc = &buf;
-    dev_desc->Size = sizeof(buf);
     query.PropertyId = StorageDeviceProperty;
     query.QueryType = PropertyStandardQuery;
 
     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 = find_bus_type(dev_desc->BusType);
+    g_debug("bus type %d", disk->bus_type);
+    g_free(dev_desc);
 
-    return dev_desc->BusType;
+    return;
 }
 
 /* VSS provider works with volumes, thus there is no difference if
@@ -613,8 +617,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 = NULL;
 
     scsi_ad = &addr;
     char *name = g_strndup(guid, strlen(guid)-1);
@@ -624,22 +628,22 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
                        0, NULL);
     if (vol_h == INVALID_HANDLE_VALUE) {
         error_setg_win32(errp, GetLastError(), "failed to open volume");
-        goto out_free;
+        goto err;
     }
 
-    g_debug("getting bus type");
-    bus = get_disk_bus_type(vol_h, errp);
-    if (bus < 0) {
-        goto out_close;
+    disk = g_malloc0(sizeof(*disk));
+    get_disk_properties(vol_h, disk, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        goto err_close;
     }
 
-    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 (disk->bus_type == GUEST_DISK_BUS_TYPE_SCSI
+            || disk->bus_type == GUEST_DISK_BUS_TYPE_IDE
+            || disk->bus_type == GUEST_DISK_BUS_TYPE_RAID
 #if (_WIN32_WINNT >= 0x0600)
             /* This bus type is not supported before Windows Server 2003 SP1 */
-            || bus == BusTypeSas
+            || disk->bus_type == GUEST_DISK_BUS_TYPE_SAS
 #endif
         ) {
         /* We are able to use the same ioctls for different bus types
@@ -679,11 +683,17 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
     list = g_malloc0(sizeof(*list));
     list->value = disk;
     list->next = 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;
 }
 
 #else
-- 
2.19.0

  parent reply	other threads:[~2018-10-04 11:33 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04 11:22 [Qemu-devel] [PATCH v4 00/11] qga: report serial number and disk node Tomáš Golembiovský
2018-10-04 11:22 ` [Qemu-devel] [PATCH v4 01/11] qga-win: fix crashes when PCI info cannot be retrived Tomáš Golembiovský
2018-10-04 13:21   ` Marc-André Lureau
2018-10-09 11:07     ` Tomáš Golembiovský
2018-10-10 23:35   ` Michael Roth
2018-10-11  1:04   ` Eric Blake
2018-10-04 11:22 ` [Qemu-devel] [PATCH v4 02/11] qga-win: handle NULL values Tomáš Golembiovský
2018-10-04 13:21   ` Marc-André Lureau
2018-10-10 23:08   ` Michael Roth
2018-10-04 11:22 ` [Qemu-devel] [PATCH v4 03/11] build: rename CONFIG_QGA_NTDDDISK to CONFIG_QGA_NTDDSCSI Tomáš Golembiovský
2018-10-04 13:21   ` Marc-André Lureau
2018-10-07  9:29     ` Sameeh Jubran
2018-10-04 11:22 ` [Qemu-devel] [PATCH v4 04/11] qga-win: add debugging information Tomáš Golembiovský
2018-10-04 13:21   ` Marc-André Lureau
2018-10-04 11:22 ` Tomáš Golembiovský [this message]
2018-10-04 13:21   ` [Qemu-devel] [PATCH v4 05/11] qga-win: refactor disk properties (bus) Marc-André Lureau
2018-10-04 11:22 ` [Qemu-devel] [PATCH v4 06/11] configure: add test for libudev Tomáš Golembiovský
2018-10-04 13:21   ` Marc-André Lureau
2018-10-04 11:22 ` [Qemu-devel] [PATCH v4 07/11] qga: report disk serial number Tomáš Golembiovský
2018-10-04 13:21   ` Marc-André Lureau
2018-10-04 11:22 ` [Qemu-devel] [PATCH v4 08/11] qga-win: refactor disk info Tomáš Golembiovský
2018-10-04 11:22 ` [Qemu-devel] [PATCH v4 09/11] qga-win: handle multi-disk volumes Tomáš Golembiovský
2018-10-07 12:13   ` Sameeh Jubran
2018-10-10 14:57     ` Tomáš Golembiovský
2018-10-04 11:22 ` [Qemu-devel] [PATCH v4 10/11] qga: return disk device in guest-get-fsinfo Tomáš Golembiovský
2018-10-04 13:20   ` Marc-André Lureau
2018-10-04 11:22 ` [Qemu-devel] [PATCH v4 11/11] qga-win: demystify namespace striping Tomáš Golembiovský
2018-10-04 13:20   ` Marc-André Lureau
2018-10-07 11:03     ` Sameeh Jubran
2018-10-09 12:38     ` Tomáš Golembiovský
2018-10-10 17:19     ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f52540791edaf07805d9acaa8b5e795e847904a7.1538652143.git.tgolembi@redhat.com \
    --to=tgolembi@redhat.com \
    --cc=eblake@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=okrishtal@virtuozzo.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sjubran@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.