From: Christian Borntraeger Subject: [PATCH/RFC] virtio_blk: check for hardsector size from host Date: Tue, 27 May 2008 11:04:59 +0200 Message-ID: <200805271105.00077.borntraeger@de.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Jens Axboe , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org To: Rusty Russell Return-path: Received: from mtagate5.uk.ibm.com ([195.212.29.138]:33254 "EHLO mtagate5.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756853AbYE0JFN (ORCPT ); Tue, 27 May 2008 05:05:13 -0400 Received: from d06nrmr1407.portsmouth.uk.ibm.com (d06nrmr1407.portsmouth.uk.ibm.com [9.149.38.185]) by mtagate5.uk.ibm.com (8.13.8/8.13.8) with ESMTP id m4R954AM610642 for ; Tue, 27 May 2008 09:05:04 GMT Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v8.7) with ESMTP id m4R952lZ2670670 for ; Tue, 27 May 2008 10:05:03 +0100 Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m4R9515A012959 for ; Tue, 27 May 2008 10:05:01 +0100 Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: Rusty, Jens, I need your opinion on the following patch. It seems to work, but I would like to get some feedback if this patch is the right approach: --- Currently virtio_blk assumes a 512 byte hard sector size. This can cause trouble / performance issues if the backing has a different block size (like a file on an ext3 file system formatted with 4k block size or a dasd device). Lets add a feature flag that tells the guest to use a different hard sector size than 512 byte. The host can use stat->st_blksize to determine the right hard sector size for a specific backing. Signed-off-by: Christian Borntraeger --- drivers/block/virtio_blk.c | 10 +++++++++- include/linux/virtio_blk.h | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) Index: kvm/drivers/block/virtio_blk.c =================================================================== --- kvm.orig/drivers/block/virtio_blk.c +++ kvm/drivers/block/virtio_blk.c @@ -196,6 +196,7 @@ static int virtblk_probe(struct virtio_d int err; u64 cap; u32 v; + u64 blk_size; if (index_to_minor(index) >= 1 << MINORBITS) return -ENOSPC; @@ -290,6 +291,13 @@ static int virtblk_probe(struct virtio_d if (!err) blk_queue_max_hw_segments(vblk->disk->queue, v); + /* Host can optionally specify the block size of the device */ + err = virtio_config_val(vdev, VIRTIO_BLK_F_BLK_SIZE, + offsetof(struct virtio_blk_config, blk_size), + &blk_size); + if (!err) + blk_queue_hardsect_size(vblk->disk->queue, blk_size); + add_disk(vblk->disk); return 0; @@ -329,7 +337,7 @@ static struct virtio_device_id id_table[ static unsigned int features[] = { VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, - VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, + VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE, }; static struct virtio_driver virtio_blk = { Index: kvm/include/linux/virtio_blk.h =================================================================== --- kvm.orig/include/linux/virtio_blk.h +++ kvm/include/linux/virtio_blk.h @@ -11,6 +11,7 @@ #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ +#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ struct virtio_blk_config { @@ -26,6 +27,8 @@ struct virtio_blk_config __u8 heads; __u8 sectors; } geometry; + /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ + __u64 blk_size; } __attribute__((packed)); /* These two define direction. */