From patchwork Wed Nov 25 19:18:09 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avishay Traeger1 X-Patchwork-Id: 39450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 42C491007D4 for ; Thu, 26 Nov 2009 07:17:25 +1100 (EST) Received: from localhost ([127.0.0.1]:46978 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDOIk-0005C1-0f for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 15:17:22 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDNNf-00028e-Pq for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:18:23 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDNNa-00025O-8v for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:18:22 -0500 Received: from [199.232.76.173] (port=51372 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDNNa-00025L-5T for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:18:18 -0500 Received: from mtagate6.de.ibm.com ([195.212.17.166]:33785) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NDNNZ-0003DB-Ct for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:18:17 -0500 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate6.de.ibm.com (8.13.1/8.13.1) with ESMTP id nAPJIAvJ028178 for ; Wed, 25 Nov 2009 19:18:10 GMT Received: from d12av04.megacenter.de.ibm.com (d12av04.megacenter.de.ibm.com [9.149.165.229]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id nAPJIAO1979022 for ; Wed, 25 Nov 2009 20:18:10 +0100 Received: from d12av04.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av04.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id nAPJIAS1026595 for ; Wed, 25 Nov 2009 20:18:10 +0100 Received: from d12mc102.megacenter.de.ibm.com (d12mc102.megacenter.de.ibm.com [9.149.167.114]) by d12av04.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id nAPJIAQ1026592; Wed, 25 Nov 2009 20:18:10 +0100 X-KeepSent: 6170BA26:9C2A4C26-C2257679:005FFE86; type=4; name=$KeepSent To: kvm@vger.kernel.org, qemu-devel@nongnu.org X-Mailer: Lotus Notes Release 8.0.1 February 07, 2008 Message-ID: From: Avishay Traeger1 Date: Wed, 25 Nov 2009 21:18:09 +0200 X-MIMETrack: Serialize by Router on D12MC102/12/M/IBM(Release 8.5|December 05, 2008) at 25/11/2009 21:18:09 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Subject: [Qemu-devel] [PATCH] virtio-blk: add max sectors feature X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is a patch to have the guest virtio-blk driver get the value for the maximum I/O size from the host bdrv, rather than assume that there is no limit. Right now we use it for an in-house bdrv driver that needs this option. The patches are below, against the latest gits, split into kernel (kvm) and user-space (qemu-kvm) changes. I appreciate any comments. Please CC me on replies, as I am not subscribed. Thank you, Avishay Signed-off-by: Avishay Traeger #define VIRTIO_BLK_ID_SN 10 /* start of char * serial# */ @@ -45,6 +46,7 @@ struct virtio_blk_config uint16_t cylinders; uint8_t heads; uint8_t sectors; + uint32_t sectors_max; uint32_t _blk_size; /* structure pad, currently unused */ uint16_t identify[VIRTIO_BLK_ID_LEN]; } __attribute__((packed)); === KERNEL === diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 51042f0..f590463 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -351,8 +351,14 @@ static int __devinit virtblk_probe(struct virtio_device *vdev) /* No need to bounce any requests */ blk_queue_bounce_limit(vblk->disk->queue, BLK_BOUNCE_ANY); - /* No real sector limit. */ - blk_queue_max_sectors(vblk->disk->queue, -1U); + /* Host can optionally specify maximum sector size for I/Os. */ + err = virtio_config_val(vdev, VIRTIO_BLK_F_SECTOR_MAX, + offsetof(struct virtio_blk_config, sectors_max), + &v); + if (!err) + blk_queue_max_sectors(vblk->disk->queue, v); + else + blk_queue_max_sectors(vblk->disk->queue, -1U); /* Host can optionally specify maximum segment size and number of * segments. */ @@ -412,7 +418,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_BLK_SIZE, - VIRTIO_BLK_F_SCSI, VIRTIO_BLK_F_FLUSH + VIRTIO_BLK_F_SCSI, VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_SECTOR_MAX }; /* diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h index fd294c5..22cde32 100644 --- a/include/linux/virtio_blk.h +++ b/include/linux/virtio_blk.h @@ -15,6 +15,7 @@ #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */ #define VIRTIO_BLK_F_FLUSH 9 /* Cache flush command support */ +#define VIRTIO_BLK_F_SECTOR_MAX 10 /* Maximum # of sectors per I/O */ struct virtio_blk_config { /* The capacity (in 512-byte sectors). */ @@ -29,6 +30,7 @@ struct virtio_blk_config { __u8 heads; __u8 sectors; } geometry; + __u32 sectors_max; /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ __u32 blk_size; } __attribute__((packed)); === USER-SPACE === diff --git a/block.c b/block.c index 6fdabff..e63ca3b 100644 --- a/block.c +++ b/block.c @@ -800,6 +800,26 @@ int64_t bdrv_getlength(BlockDriverState *bs) return drv->bdrv_getlength(bs); } +/** + * Maximum length of an I/O in sectors. Return -1 if not specified. + */ +void bdrv_get_max_sectors(BlockDriverState *bs, uint32_t *sectors_max) +{ + BlockDriver *drv = bs->drv; + if ((!drv) || (!drv->bdrv_get_max_sectors)) + *sectors_max = -1; + else + * sectors_max = drv->bdrv_get_max_sectors(bs); +} + +int bdrv_uses_max_sectors(BlockDriverState *bs) +{ + BlockDriver *drv = bs->drv; + if ((!drv) || (!drv->bdrv_get_max_sectors)) + return 0; + return 1; +} + /* return 0 as number of sectors if no device present or error */ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr) { diff --git a/block.h b/block.h index 2d4f066..21c6b40 100644 --- a/block.h +++ b/block.h @@ -72,6 +72,8 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset, const void *buf, int count); int bdrv_truncate(BlockDriverState *bs, int64_t offset); int64_t bdrv_getlength(BlockDriverState *bs); +void bdrv_get_max_sectors(BlockDriverState *bs, uint32_t *sectors_max); +int bdrv_uses_max_sectors(BlockDriverState *bs); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs); int bdrv_commit(BlockDriverState *bs); diff --git a/block_int.h b/block_int.h index 7ebe926..c7c4eb9 100644 --- a/block_int.h +++ b/block_int.h @@ -81,6 +81,7 @@ struct BlockDriver { const char *protocol_name; int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset); int64_t (*bdrv_getlength)(BlockDriverState *bs); + uint32_t (*bdrv_get_max_sectors)(BlockDriverState *bs); int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num, const uint8_t *buf, int nb_sectors); diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 42b766f..b2c0933 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -413,13 +413,16 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) struct virtio_blk_config blkcfg; uint64_t capacity; int cylinders, heads, secs; + uint32_t sectors_max; bdrv_get_geometry(s->bs, &capacity); bdrv_get_geometry_hint(s->bs, &cylinders, &heads, &secs); + bdrv_get_max_sectors(s->bs, §ors_max); memset(&blkcfg, 0, sizeof(blkcfg)); stq_raw(&blkcfg.capacity, capacity); stl_raw(&blkcfg.seg_max, 128 - 2); stw_raw(&blkcfg.cylinders, cylinders); + stl_raw(&blkcfg.sectors_max, sectors_max); blkcfg.heads = heads; blkcfg.sectors = secs; blkcfg.size_max = 0; @@ -448,6 +451,9 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev) if (bdrv_is_read_only(s->bs)) features |= 1 << VIRTIO_BLK_F_RO; + if (bdrv_uses_max_sectors(s->bs)) + features |= 1 << VIRTIO_BLK_F_SECTOR_MAX; + return features; } diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h index 23ad74c..21cf5a8 100644 --- a/hw/virtio-blk.h +++ b/hw/virtio-blk.h @@ -32,6 +32,7 @@ #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */ #define VIRTIO_BLK_F_IDENTIFY 8 /* ATA IDENTIFY supported */ #define VIRTIO_BLK_F_WCACHE 9 /* write cache enabled */ +#define VIRTIO_BLK_F_SECTOR_MAX 10 /* Maximum # of sectors per I/O */ #define VIRTIO_BLK_ID_LEN 256 /* length of identify u16 array */