Skip to contentSkip to conversation

qga: disk and volume info for Windows guest

PATCH In review Denis V. Lunev 4 participants 14 messages May 2, 2015 – Jun 16, 2015

lore
Share & tools
lore
#1 lore raw

PATCH 1/4 qga: added empty qmp_quest_get_fsinfo functionality.

From: Olga Krishtal <[email protected]>

We need qmp_quest_get_fsinfo togather with vss-provider, which works with volumes. The call to this function is implemented via FindFirst/NextVolumes. Moreover volumes in Windows OS are filesystem unit, so it will be more effective to work with them rather with devices.

---
 qga/commands-win32.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)
qga/commands-win32.c +31 -3
index 3ef0549..1a82ec9 100644
@@ -382,12 +382,40 @@ static void guest_file_init(void)
     QTAILQ_INIT(&guest_file_state.filehandles);
 }
 
-GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp)
+static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp)
 {
-    error_set(errp, QERR_UNSUPPORTED);
     return NULL;
 }
 
+GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp)
+{
+    HANDLE vol_h;
+    GuestFilesystemInfoList *new, *ret = NULL;
+    char guid[256];
+    bool res = false;
+
+    vol_h = FindFirstVolume(guid, sizeof(guid));
+    if (vol_h == INVALID_HANDLE_VALUE) {
+        error_setg_win32(errp, GetLastError(), "failed to find any volume");
+        return NULL;
+    }
+
+    do {
+        new = g_malloc(sizeof(*ret));
+        new->value = build_guest_fsinfo(guid, errp);
+        new->next = ret;
+        ret = new;
+        res = FindNextVolume(vol_h, guid, sizeof(guid));
+    } while (res);
+
+    if (GetLastError() != ERROR_NO_MORE_FILES) {
+        error_setg_win32(errp, GetLastError(), "failed to find next volume");
+    }
+
+    FindVolumeClose(vol_h);
+    return ret;
+}
+
 /*
  * Return status of freeze/thaw
  */
@@ -712,7 +740,7 @@ GList *ga_command_blacklist_init(GList *blacklist)
         "guest-set-user-password",
         "guest-get-memory-blocks", "guest-set-memory-blocks",
         "guest-get-memory-block-size",
-        "guest-fsfreeze-freeze-list", "guest-get-fsinfo",
+        "guest-fsfreeze-freeze-list",
         "guest-fstrim", NULL};
     char **p = (char **)list_unsupported;
 
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/4 qga: added mountpoint and filesystem type for single

In reply to Denis V. Lunev

From: Olga Krishtal <[email protected]>

We should use GetVolumeXXX api to work with volumes. This will help us to resolve the situation with volumes without drive letter, i.e. when the volume is mounted as a folder. This case is called mounted folder. This volume is a regular mounted volume from all other points of view. The information about non mounted volume is reported as System Reserved. This volume is not mounted and thus it is not writable.

GuestDiskAddressList API is not used as operations are performed with volumess rather when with disks. This means that spanned disk will be counted and handled as a single volume. It is worth to note that the information about every disk in the volume can be queried via IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS.

---
 qga/commands-win32.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
qga/commands-win32.c +42 -1
index 1a82ec9..d26fd59 100644
@@ -384,7 +384,48 @@ static void guest_file_init(void)
 
 static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp)
 {
-    return NULL;
+    DWORD info_size;
+    char mnt, *mnt_point;
+    char fs_name[32];
+    char vol_info[MAX_PATH+1];
+    size_t len;
+    GuestFilesystemInfo *fs = NULL;
+
+    GetVolumePathNamesForVolumeName(guid, mnt, NULL, &info_size);
+    if (GetLastError() != ERROR_MORE_DATA) {
+        error_setg_win32(errp, GetLastError(), "failed to get volume name");
+        return NULL;
+    }
+
+    mnt_point = g_malloc(info_size + 1);
+    if (!GetVolumePathNamesForVolumeName(guid, mnt_point, info_size,
+                                         &info_size)) {
+        error_setg_win32(errp, GetLastError(), "failed to get volume name");
+        goto free;
+    }
+
+    len = strlen(mnt_point);
+    mnt_point[len] = '\\';
+    mnt_point[len+1] = 0;
+    if (!GetVolumeInformation(mnt_point, vol_info, sizeof(vol_info), NULL, NULL,
+                              NULL, &fs_name, sizeof(fs_name))) {
+        error_setg_win32(errp, GetLastError(), "failed to get volume info");
+        goto free;
+    }
+
+    fs_name[sizeof(fs_name) - 1] = 0;
+    fs = g_malloc(sizeof(*fs));
+    fs->name = g_strdup(guid);
+    if (len == 0) {
+        fs->mountpoint = g_strdup("System Reserved");
+    } else {
+        fs->mountpoint = g_strndup(mnt_point, len);
+    }
+    fs->type = g_strdup(fs_name);
+    fs->disk = NULL;
+free:
+    g_free(mnt_point);
+    return fs;
 }
 
 GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp)
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/4 qga: added bus type and disk location path

In reply to Denis V. Lunev

From: Olga Krishtal <[email protected]>

According to Microsoft disk location path can be obtained via IOCTL_SCSI_GET_ADDRESS. Unfortunately this ioctl can not be used for all devices. There are certain bus types which could be obtained with this API. Please refer to the following link for more details
https://technet.microsoft.com/en-us/library/ee851589(v=ws.10).aspx

Bus type could be obtained using IOCTL_STORAGE_QUERY_PROPERTY. Enum STORAGE_BUS_TYPE describes all buses supported by OS.

Windows defines more bus types that Linux. Thus some values have been added to GuestDiskBusType.

---
 qga/commands-win32.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 qga/qapi-schema.json |  15 ++++++-
 2 files changed, 132 insertions(+), 3 deletions(-)
qga/commands-win32.c +119 -1
index d26fd59..f3569e9 100644
@@ -16,6 +16,8 @@
 #include <powrprof.h>
 #include <stdio.h>
 #include <string.h>
+#include <winioctl.h>
+#include <ntddscsi.h>
 #include "qga/guest-agent-core.h"
 #include "qga/vss-win32.h"
 #include "qga-qmp-commands.h"
@@ -84,6 +86,36 @@ static OpenFlags *find_open_flag(const char *mode_str)
     return NULL;
 }
 
+static STORAGE_BUS_TYPE win2qemu[] = {
+    [BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
+    [BusTypeScsi] = GUEST_DISK_BUS_TYPE_SCSI,
+    [BusTypeAtapi] = GUEST_DISK_BUS_TYPE_IDE,
+    [BusTypeAta] = GUEST_DISK_BUS_TYPE_IDE,
+    [BusType1394] = GUEST_DISK_BUS_TYPE_1394,
+    [BusTypeSsa] = GUEST_DISK_BUS_TYPE_SSA,
+    [BusTypeFibre] = GUEST_DISK_BUS_TYPE_SSA,
+    [BusTypeUsb] = GUEST_DISK_BUS_TYPE_USB,
+    [BusTypeRAID] = GUEST_DISK_BUS_TYPE_RAID,
+#if (_WIN32_WINNT >= 0x0600)
+    [BusTypeiScsi] = GUEST_DISK_BUS_TYPE_I_SCSI,
+    [BusTypeSas] = GUEST_DISK_BUS_TYPE_SAS,
+    [BusTypeSata] = GUEST_DISK_BUS_TYPE_SATA,
+    [BusTypeSd] =  GUEST_DISK_BUS_TYPE_SD,
+    [BusTypeMmc] = GUEST_DISK_BUS_TYPE_MMC,
+    [BusTypeVirtual] = GUEST_DISK_BUS_TYPE_VIRTUAL,
+    [BusTypeFileBackedVirtuaul] = GUEST_DISK_BUS_TYPE_FBIRTUAL,
+    [BusTypeSpaces] = GUEST_DISK_BUS_TYPE_SPACES
+#endif
+};
+
+static GuestDiskBusType find_bus_type(STORAGE_BUS_TYPE bus)
+{
+    if (bus > ARRAY_SIZE(win2qemu) || (int)bus < 0) {
+        return GUEST_DISK_BUS_TYPE_UNKNOWN;
+    }
+    return win2qemu[(int)bus];
+}
+
 static int64_t guest_file_handle_add(HANDLE fh, Error **errp)
 {
     GuestFileHandle *gfh;
@@ -382,6 +414,92 @@ static void guest_file_init(void)
     QTAILQ_INIT(&guest_file_state.filehandles);
 }
 
+static GuestPCIAddress *get_pci_info(char *guid, Error **errp)
+{
+    return NULL;
+}
+
+static int get_disk_bus_type(HANDLE vol_h, Error **errp)
+{
+    STORAGE_PROPERTY_QUERY query;
+    STORAGE_DEVICE_DESCRIPTOR *dev_desc, buf;
+    DWORD received;
+
+    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)) {
+        error_setg_win32(errp, GetLastError(), "failed to get bus type");
+        return -1;
+    }
+
+    return dev_desc->BusType;
+}
+
+/* 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 **errp)
+{
+    GuestDiskAddressList *list = NULL;
+    GuestDiskAddress *disk;
+    DWORD len;
+    int bus;
+    HANDLE vol_h;
+    char *name = g_strndup(guid, strlen(guid)-1);
+
+    vol_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
+                       NULL, NULL);
+    if (vol_h == INVALID_HANDLE_VALUE) {
+        error_setg_win32(errp, GetLastError(), "failed to open volume");
+        goto out_free;
+    }
+
+    bus = get_disk_bus_type(vol_h, errp);
+    if (bus < 0) {
+        goto out_close;
+    }
+
+    disk = g_malloc0(sizeof(*disk));
+    disk->bus_type = find_bus_type(bus);
+    if (bus == BusTypeScsi || bus == BusTypeAta || bus == BusTypeRAID
+#if (_WIN32_WINNT >= 0x0600)
+            /* This bus type is not supported before Windows Server 2003 SP1 */
+            || bus == BusTypeSas
+#endif
+        ) {
+        SCSI_ADDRESS addr;
+
+        /* 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 */
+        if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, &addr,
+                            sizeof(SCSI_ADDRESS), &len, NULL)) {
+            disk->unit = addr.Lun;
+            disk->target = addr.TargetId;
+            disk->bus = addr.PathId;
+            disk->pci_controller = get_pci_info(name, errp);
+        }
+        /* We do not set error in this case, because we still have enough
+         * information about volume. */
+    } else {
+         disk->pci_controller = NULL;
+    }
+
+    list = g_malloc0(sizeof(*list));
+    list->value = disk;
+    list->next = NULL;
+out_close:
+    CloseHandle(vol_h);
+out_free:
+    g_free(name);
+    return list;
+}
+
 static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp)
 {
     DWORD info_size;
@@ -424,7 +542,7 @@ static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp)
         fs->mountpoint = g_strndup(mnt_point, len);
     }
     fs->type = g_strdup(fs_name);
-    fs->disk = NULL;
+    fs->disk = build_guest_disk_info(guid, errp);
 free:
     g_free(mnt_point);
     return fs;
qga/qapi-schema.json +13 -2
index 5c4cd40..6eaa7c1 100644
@@ -667,6 +667,7 @@
 # @GuestDiskBusType
 #
 # An enumeration of bus type of disks
+# it is different for Linux and Windows guest
 #
 # @ide: IDE disks
 # @fdc: floppy disks
@@ -677,12 +678,22 @@
 # @uml: UML disks
 # @sata: SATA disks
 # @sd: SD cards
-#
+# @unknown: Unknown bus type
+# @1394: Win IEEE 1394 bus type
+# @ssa: Win SSA bus type
+# @fibre: Win fiber channel bus type
+# @raid: Win RAID bus type
+# @iscsi: Win iScsi bus type
+# @sas: Win serial-attaches SCSI bus type
+# @mmc: Win multimedia card (MMC) bus type
+# @virtual: Win virtual bus type
+# @file-backed virtual: Win file-backed bus type
 # Since: 2.2
 ##
 { 'enum': 'GuestDiskBusType',
   'data': [ 'ide', 'fdc', 'scsi', 'virtio', 'xen', 'usb', 'uml', 'sata',
-            'sd' ] }
+            'sd', 'unknown', '1394', 'ssa', 'fibre', 'raid', 'iscsi',
+            'sas', 'mmc', 'virtual', 'file-backed-virtual' ] }
 
 ##
 # @GuestPCIAddress:
Signature · 1 line
1.9.1
#4 lore raw

PATCH 4/4 qga: added GuestPCIAddress information

In reply to Denis V. Lunev

From: Olga Krishtal <[email protected]>

PCIAddress inforfation is obtained via SetupApi, which provides the information about address, bus, etc. We look throught entire device tree in the system and try to find device object for given volume. For this PDO SetupDiGetDeviceRegistryProperty is called, which reads PCI configuration if it is possible for a given device.

This is the most convinient way for a userspace service. The lookup is performed for every volume available. However, this information is not mandatory for vss-provider.

In order to use SetupApi we need to notify linker about it. We do not need to install additional libs, so we do not make separate configuration option to use libsetupapi.su

SetupApi gives as the same information as kernel driver with IRP_MN_QUERY_INTERFACE.
https://support.microsoft.com/en-us/kb/253232

---
 configure            |  2 +-
 qga/commands-win32.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 96 insertions(+), 2 deletions(-)
configure +1 -1
index 255d85b..5d62aa0 100755
@@ -719,7 +719,7 @@ EOF
   sysconfdir="\${prefix}"
   local_statedir=
   confsuffix=""
-  libs_qga="-lws2_32 -lwinmm -lpowrprof $libs_qga"
+  libs_qga="-lsetupapi -lws2_32 -lwinmm -lpowrprof $libs_qga"
 fi
 
 werror=""
qga/commands-win32.c +95 -1

114 lines not on this page · raw message

Signature · 1 line
1.9.1
#9 lore raw
Quoted 8 lines · Denis V. Lunev
Quoted 7 lines · Denis V. Lunev

Functionality match with Linux. Patches 1 and 2 are very useful for consistent backups of Windows guests.

Quoted 7 lines

PING, 1 week till soft freeze.

Michael, can you pls consider these patches? We have really small amount of time left.

Regards,
Den

_PING_

#10 lore raw
Quoted 9 lines · Denis V. Lunev
Quoted 8 lines · Denis V. Lunev
Quoted 7 lines · Denis V. Lunev

Functionality match with Linux. Patches 1 and 2 are very useful for consistent backups of Windows guests.

Quoted 8 lines
Quoted 7 lines

PING, 1 week till soft freeze.

Michael, can you pls consider these patches? We have really small amount of time left.

Regards,
Den

_PING_

I think Michael is on vacation until the end of this week.

Stefan

#11 lore raw
Quoted 15 lines · Stefan Hajnoczi
Quoted 14 lines · Denis V. Lunev
Quoted 13 lines · Denis V. Lunev
Quoted 7 lines · Denis V. Lunev

Functionality match with Linux. Patches 1 and 2 are very useful for consistent backups of Windows guests.

PING, 1 week till soft freeze.

Michael, can you pls consider these patches? We have really small amount of time left.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

Regards,
Den

_PING_

I think Michael is on vacation until the end of this week.

Stefan

thank you for the update.

This is really a problem for this set and for guest exec code to be merged into 2.4

OK, I'll get some patience if nobody other can help. Windows is not a favorite platform in this list :)

Den

#12 lore raw
Quoted 11 lines · Denis V. Lunev
Quoted 11 lines
Quoted 9 lines
Quoted 8 lines
Quoted 1 line

PING, 1 week till soft freeze.

Michael, can you pls consider these patches? We have really small amount of time left.

Regards,
Den

_PING_

I think Michael is on vacation until the end of this week.

Quoted 8 lines
Quoted 1 line

Stefan

thank you for the update.

This is really a problem for this set and for guest exec code to be merged into 2.4

OK, I'll get some patience if nobody other can help. Windows is not a favorite platform in this list :)

If I understand soft freeze correctly, it's okay if your patches have been posted but not yet applied; a maintainer can still pick them up. It's not until hard freeze that we no longer take new features into the tree.

I still hope to help review the interface side of pending qga patches before I go on vacation next week, but I'm not enough of an expert on Windows coding to review much beyond that.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#13 lore raw
Quoted 20 lines · Eric Blake
Quoted 10 lines · Denis V. Lunev
Quoted 10 lines
Quoted 8 lines
Quoted 7 lines

PING, 1 week till soft freeze.

Michael, can you pls consider these patches? We have really small amount of time left.

Regards,
Den

_PING_

I think Michael is on vacation until the end of this week.

Quoted 8 lines
Quoted 1 line

Stefan

thank you for the update.

This is really a problem for this set and for guest exec code to be merged into 2.4

OK, I'll get some patience if nobody other can help. Windows is not a favorite platform in this list :)

Quoted 9 lines

If I understand soft freeze correctly, it's okay if your patches have been posted but not yet applied; a maintainer can still pick them up. It's not until hard freeze that we no longer take new features into the tree.

I still hope to help review the interface side of pending qga patches before I go on vacation next week, but I'm not enough of an expert on Windows coding to review much beyond that.

I think that it will have more sense if you will start from second patchset with guest exec, which really touch interfaces and your review will be very useful.

Den