>From a19863b191e5e32812ddcbd63f88826ff16d2298 Mon Sep 17 00:00:00 2001 From: Dor Laor Date: Sun, 24 May 2009 18:01:39 +0300 Subject: [PATCH] Optionally change the virtio-block storage class to PCI_CLASS_STORAGE_SCSI Windows whql tests does not recognizes the virtio device since its storage class is PCI_CLASS_STORAGE_OTHER. Changing the default and allow and option to pass the class as -drive file=...,class=128. Signed-off-by: Dor Laor --- hw/virtio-blk.c | 7 +++++++ hw/virtio-pci.c | 6 +++++- hw/virtio.h | 1 + sysemu.h | 2 ++ vl.c | 23 ++++++++++++++++++++++- 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 8dd3c7a..7f89e0d 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -348,6 +348,13 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id) return 0; } +int virtio_blk_get_class(DeviceState *dev) +{ + VirtIOBlock *s = (VirtIOBlock *)dev; + + return drive_get_class_code(s->bs); +} + VirtIODevice *virtio_blk_init(DeviceState *dev) { VirtIOBlock *s; diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index c072423..77d4a54 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -14,6 +14,7 @@ */ #include +#include #include "virtio.h" #include "pci.h" @@ -286,12 +287,15 @@ static void virtio_blk_init_pci(PCIDevice *pci_dev) { VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); VirtIODevice *vdev; + int class_code; vdev = virtio_blk_init(&pci_dev->qdev); + if ((class_code = virtio_blk_get_class(vdev)) == -1) + class_code = PCI_CLASS_STORAGE_SCSI; virtio_init_pci(proxy, vdev, PCI_VENDOR_ID_REDHAT_QUMRANET, PCI_DEVICE_ID_VIRTIO_BLOCK, - PCI_CLASS_STORAGE_OTHER, + (uint16_t)class_code, 0x00); } diff --git a/hw/virtio.h b/hw/virtio.h index 425727e..fd8b7a7 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -151,5 +151,6 @@ VirtIODevice *virtio_blk_init(DeviceState *dev); VirtIODevice *virtio_net_init(DeviceState *dev); VirtIODevice *virtio_console_init(DeviceState *dev); VirtIODevice *virtio_balloon_init(DeviceState *dev); +int virtio_blk_get_class(DeviceState *dev); #endif diff --git a/sysemu.h b/sysemu.h index 92501ed..659e222 100644 --- a/sysemu.h +++ b/sysemu.h @@ -154,6 +154,7 @@ typedef struct DriveInfo { BlockDriverState *bdrv; BlockInterfaceType type; int bus; + int class; int unit; int used; int drive_opt_idx; @@ -174,6 +175,7 @@ extern void drive_uninit(BlockDriverState *bdrv); extern void drive_remove(int index); extern const char *drive_get_serial(BlockDriverState *bdrv); extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv); +extern int drive_get_class_code(BlockDriverState *bdrv); BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type); diff --git a/vl.c b/vl.c index 2c1f0e0..5c8ac6f 100644 --- a/vl.c +++ b/vl.c @@ -2181,6 +2181,17 @@ BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv) return BLOCK_ERR_STOP_ENOSPC; } +extern int drive_get_class_code(BlockDriverState *bdrv) +{ + int index; + + for (index = 0; index < nb_drives; index++) + if (drives_table[index].bdrv == bdrv) + return drives_table[index].class; + + return -1; +} + static void bdrv_format_print(void *opaque, const char *name) { fprintf(stderr, " %s", name); @@ -2218,13 +2229,14 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) int index; int cache; int bdrv_flags, onerror; + int class = -1; int drives_table_idx; char *str = arg->opt; static const char * const params[] = { "bus", "unit", "if", "index", "cyls", "heads", "secs", "trans", "media", "snapshot", "file", "cache", "format", "serial", "werror", - NULL }; + "class", NULL }; if (check_params(params, str) < 0) { fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n", @@ -2355,6 +2367,14 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) } } + if (get_param_value(buf, sizeof(buf), "class", str)) { + if (type != IF_VIRTIO) { + fprintf(stderr, "class is no supported by this format\n"); + return -1; + } + class = strtol(buf, NULL, 0); + } + if (get_param_value(buf, sizeof(buf), "media", str)) { if (!strcmp(buf, "disk")) { media = MEDIA_DISK; @@ -2502,6 +2522,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) drives_table[drives_table_idx].bus = bus_id; drives_table[drives_table_idx].unit = unit_id; drives_table[drives_table_idx].onerror = onerror; + drives_table[drives_table_idx].class = class; drives_table[drives_table_idx].drive_opt_idx = arg - drives_opt; strncpy(drives_table[drives_table_idx].serial, serial, sizeof(serial)); nb_drives++; -- 1.5.6.6