Rusty Russell
2009-Sep-21 06:58 UTC
[PATCH 5/6] virtio_blk: set QUEUE_ORDERED_DRAIN by default
From: Christoph Hellwig <hch at lst.de> Currently virtio-blk doesn't set any QUEUE_ORDERED_ flag by default, which means it does not allow filesystems to use barriers. But the typical use case for virtio-blk is to use a backed that uses synchronous I/O, and in that case we can simply set QUEUE_ORDERED_DRAIN to make the block layer drain the request queue around barrier I/O and provide the semantics that the filesystems need. This is what the SCSI disk driver does for disks that have the write cache disabled. With this patch we incorrectly advertise barrier support if someone configure qemu with write back caching. While this displays wrong information in the guest there is nothing that guest could have done even if we rightfully told it that we do not support any barriers. (Christoph further explains: "Really, enabling volatile write caches without advertising a cache flush command is a bug in the storage, where in our case qemu is the storage." Actual write cache feature is coming in successive patch. --RR ) Signed-off-by: Christoph Hellwig <hch at lst.de> Signed-off-by: Rusty Russell <rusty at rustcorp.com.au> --- drivers/block/virtio_blk.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) Index: linux-2.6/drivers/block/virtio_blk.c ==================================================================--- linux-2.6.orig/drivers/block/virtio_blk.c 2009-08-20 17:41:37.019718433 -0300 +++ linux-2.6/drivers/block/virtio_blk.c 2009-08-20 17:45:40.511747922 -0300 @@ -336,9 +336,16 @@ static int __devinit virtblk_probe(struc vblk->disk->driverfs_dev = &vdev->dev; index++; - /* If barriers are supported, tell block layer that queue is ordered */ + /* + * If barriers are supported, tell block layer that queue is ordered. + * + * If no barriers are supported assume the host uses synchronous + * writes and just drain the the queue before and after the barrier. + */ if (virtio_has_feature(vdev, VIRTIO_BLK_F_BARRIER)) blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL); + else + blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_DRAIN, NULL); /* If disk is read-only in the host, the guest should obey */ if (virtio_has_feature(vdev, VIRTIO_BLK_F_RO))
Possibly Parallel Threads
- [PATCH 5/6] virtio_blk: set QUEUE_ORDERED_DRAIN by default
- [PATCH] virtio_blk: allow read-only disks
- [PATCH RFC] virtio: use QUEUE_FLAG_CLUSTER in virtio_blk
- [PATCH RFC] virtio: use QUEUE_FLAG_CLUSTER in virtio_blk
- [PATCH] virtio_blk: Dont waste major numbers