From patchwork Wed Dec 23 15:21:16 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avishay Traeger1 X-Patchwork-Id: 41675 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 E1A45B6EEA for ; Thu, 24 Dec 2009 02:24:03 +1100 (EST) Received: from localhost ([127.0.0.1]:42310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NNT4B-0000LW-JR for incoming@patchwork.ozlabs.org; Wed, 23 Dec 2009 10:23:59 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NNT1o-0007l3-Ay for qemu-devel@nongnu.org; Wed, 23 Dec 2009 10:21:32 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NNT1i-0007j9-ID for qemu-devel@nongnu.org; Wed, 23 Dec 2009 10:21:31 -0500 Received: from [199.232.76.173] (port=35561 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NNT1i-0007j6-F2 for qemu-devel@nongnu.org; Wed, 23 Dec 2009 10:21:26 -0500 Received: from mtagate3.de.ibm.com ([195.212.17.163]:52125) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NNT1h-0000Iw-8z for qemu-devel@nongnu.org; Wed, 23 Dec 2009 10:21:26 -0500 Received: from d12nrmr1507.megacenter.de.ibm.com (d12nrmr1507.megacenter.de.ibm.com [9.149.167.1]) by mtagate3.de.ibm.com (8.13.1/8.13.1) with ESMTP id nBNFLLjC009404 for ; Wed, 23 Dec 2009 15:21:21 GMT Received: from d12av06.megacenter.de.ibm.com (d12av06.megacenter.de.ibm.com [9.149.165.230]) by d12nrmr1507.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id nBNFLGu02769132 for ; Wed, 23 Dec 2009 16:21:21 +0100 Received: from d12av06.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av06.megacenter.de.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id nBNFLGTe010214 for ; Wed, 23 Dec 2009 16:21:16 +0100 Received: from d12mc102.megacenter.de.ibm.com (d12mc102.megacenter.de.ibm.com [9.149.167.114]) by d12av06.megacenter.de.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id nBNFLGLG010211; Wed, 23 Dec 2009 16:21:16 +0100 X-KeepSent: 4B1029AA:64B229B3-C2257695:005329E5; 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, 23 Dec 2009 17:21:16 +0200 X-MIMETrack: Serialize by Router on D12MC102/12/M/IBM(Release 8.5|December 05, 2008) at 23/12/2009 17:21:15 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: Anthony Liguori , Rusty Russell Subject: [Qemu-devel] [PATCH 1/2] virtio-blk: add max sectors feature (qemu) 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 the accompanying qemu patch for the maximum number of total sectors in an I/O feature. Please CC me on replies, as I am not subscribed. Thanks, Avishay Signed-off-by: Avishay Traeger --- #define VIRTIO_BLK_ID_SN 10 /* start of char * serial# */ @@ -46,6 +47,7 @@ struct virtio_blk_config uint8_t heads; uint8_t sectors; uint32_t _blk_size; /* structure pad, currently unused */ + uint32_t sectors_max; uint16_t identify[VIRTIO_BLK_ID_LEN]; } __attribute__((packed)); diff --git a/block.c b/block.c index 3f3496e..9fa97b8 100644 --- a/block.c +++ b/block.c @@ -807,6 +807,29 @@ 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); +} + +/** + * Check if the bdrv driver implements bdrv_get_max_sectors. + */ +int bdrv_uses_max_sectors(BlockDriverState *bs) +{ + BlockDriver *drv = bs->drv; + if ((drv) && (drv->bdrv_get_max_sectors)) + return 1; + return 0; +} + /* 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 fa51ddf..bcfdfe9 100644 --- a/block.h +++ b/block.h @@ -79,6 +79,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 9a3b2e0..d3726c7 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 a2f0639..751f38d 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -416,13 +416,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; @@ -451,6 +454,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; } @@ -494,7 +500,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo) static int virtio_blk_id; 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); + offsetof(struct virtio_blk_config, identify); s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK, size, diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h index 23ad74c..305fc68 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 total sectors in an I/O */ #define VIRTIO_BLK_ID_LEN 256 /* length of identify u16 array */