aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2009-09-07 21:14:37 +0300
committerAnthony Liguori <aliguori@us.ibm.com>2009-09-11 10:19:46 -0500
commit711bf3d954371abffc07e397fc868a9c9e7e5585 (patch)
treedfb0e11d37ed9b782e6fa9453f70507d879c13dd
parentc4c0e236beabb9de5ff472f77aeb811ec5484615 (diff)
qemu: make virtio-blk PCI compliant by default
commit bf011293faaa7f87e4de83185931e7411b794128 made virtio-blk-pci not PCI-compliant, since it makes region 0 (which is an i/o region) size > 256, and, since PCI 2.1, i/o regions are limited to 256 bytes size. When the ATA serial number feature is off, which is the default, make the device spec compliant again, by making region 0 smaller. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reported-by: Vadim Rozenfeld <vrozenfe@redhat.com> Tested-by: Vadim Rozenfeld <vrozenfe@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--hw/virtio-blk.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 5c88c12260..8cbb1efd5d 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -27,6 +27,7 @@ typedef struct VirtIOBlock
void *rq;
char serial_str[BLOCK_SERIAL_STRLEN + 1];
QEMUBH *bh;
+ size_t config_size;
} VirtIOBlock;
static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
@@ -406,7 +407,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
virtio_identify_template(&blkcfg);
memcpy(&blkcfg.identify[VIRTIO_BLK_ID_SN], s->serial_str,
VIRTIO_BLK_ID_SN_BYTES);
- memcpy(config, &blkcfg, sizeof(blkcfg));
+ memcpy(config, &blkcfg, s->config_size);
}
static uint32_t virtio_blk_get_features(VirtIODevice *vdev)
@@ -463,18 +464,21 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo)
VirtIOBlock *s;
int cylinders, heads, secs;
static int virtio_blk_id;
- char *ps;
+ char *ps = (char *)drive_get_serial(dinfo->bdrv);
+ size_t size = strlen(ps) ? sizeof(struct virtio_blk_config) :
+ offsetof(struct virtio_blk_config, _blk_size);
s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
- sizeof(struct virtio_blk_config),
+ size,
sizeof(VirtIOBlock));
+ s->config_size = size;
s->vdev.get_config = virtio_blk_update_config;
s->vdev.get_features = virtio_blk_get_features;
s->vdev.reset = virtio_blk_reset;
s->bs = dinfo->bdrv;
s->rq = NULL;
- if (strlen(ps = (char *)drive_get_serial(s->bs)))
+ if (strlen(ps))
strncpy(s->serial_str, ps, sizeof(s->serial_str));
else
snprintf(s->serial_str, sizeof(s->serial_str), "0");