Commit c76d70f4 authored by Tomáš Golembiovský's avatar Tomáš Golembiovský Committed by Michael Roth
Browse files

qga-win: refactor disk properties (bus)



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: default avatarTomáš Golembiovský <tgolembi@redhat.com>
Signed-off-by: default avatarMichael Roth <mdroth@linux.vnet.ibm.com>
parent 222682ab
Loading
Loading
Loading
Loading
+27 −18
Original line number Diff line number Diff line
@@ -613,25 +613,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
@@ -643,7 +646,6 @@ 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;

@@ -655,17 +657,16 @@ 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. fail the command
@@ -675,12 +676,14 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
    disk->pci_controller = get_pci_info(name, &local_err);
    if (local_err) {
        error_propagate(errp, local_err);
        goto out_close;
        goto err_close;
    }
    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
@@ -700,11 +703,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