[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 09/14] qga-win: refactor disk properties (bus)
From: |
Tomáš Golembiovský |
Subject: |
[Qemu-devel] [PATCH v5 09/14] qga-win: refactor disk properties (bus) |
Date: |
Tue, 23 Oct 2018 13:23:18 +0200 |
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ý <address@hidden>
---
qga/commands-win32.c | 44 +++++++++++++++++++++++++++-----------------
1 file changed, 27 insertions(+), 17 deletions(-)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index a3d28d06b3..5ebacd241f 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -588,25 +588,28 @@ 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);
- return dev_desc->BusType;
+ return;
}
/* VSS provider works with volumes, thus there is no difference if
@@ -618,8 +621,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);
@@ -629,26 +632,27 @@ 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);
/* always set pci_controller as required by schema. get_pci_info() should
* report -1 values for non-PCI buses rather than fail.
*/
disk->pci_controller = get_pci_info(name, errp);
- 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
@@ -668,11 +672,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
- [Qemu-devel] [PATCH v5 00/14] qga: report serial number and disk node, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 02/14] qga: linux: report disk serial number, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 05/14] qga-win: fsinfo: pci-info: allow partial info, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 04/14] qga-win: prevent crash when executing fsinfo command, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 03/14] qga: linux: return disk device in guest-get-fsinfo, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 01/14] configure: add test for libudev, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 09/14] qga-win: refactor disk properties (bus),
Tomáš Golembiovský <=
- [Qemu-devel] [PATCH v5 06/14] *additonal fixup for NULL pci_controller field, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 11/14] qga-win: refactor disk info, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 10/14] qga-win: report disk serial number, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 07/14] build: rename CONFIG_QGA_NTDDDISK to CONFIG_QGA_NTDDSCSI, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 08/14] qga-win: add debugging information, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 12/14] qga-win: handle multi-disk volumes, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 14/14] qga-win: demystify namespace stripping, Tomáš Golembiovský, 2018/10/23
- [Qemu-devel] [PATCH v5 13/14] qga-win: return disk device in guest-get-fsinfo, Tomáš Golembiovský, 2018/10/23
- Re: [Qemu-devel] [PATCH v5 00/14] qga: report serial number and disk node, Michael Roth, 2018/10/29