From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqT3I-000613-OR for qemu-devel@nongnu.org; Thu, 26 Jan 2012 12:24:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RqT33-0003Ww-1j for qemu-devel@nongnu.org; Thu, 26 Jan 2012 12:23:57 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:57875) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqT32-0003V7-OL for qemu-devel@nongnu.org; Thu, 26 Jan 2012 12:23:44 -0500 Received: by iahk25 with SMTP id k25so1228265iah.4 for ; Thu, 26 Jan 2012 09:23:42 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 26 Jan 2012 18:22:48 +0100 Message-Id: <1327598569-5199-18-git-send-email-pbonzini@redhat.com> In-Reply-To: <1327598569-5199-1-git-send-email-pbonzini@redhat.com> References: <1327598569-5199-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v2 17/18] block: default min_io_size to host block size when doing rmw List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com Same as the previous patch. However, since the min_io_size is a byte value rather than an exponent, we want to make sure that we pass a 0 when running on 512b-sector disks. Signed-off-by: Paolo Bonzini --- block.c | 17 +++++++++++++++++ block.h | 1 + hw/scsi-disk.c | 2 +- hw/virtio-blk.c | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 0fce655..4880143 100644 --- a/block.c +++ b/block.c @@ -4153,3 +4153,20 @@ unsigned int get_physical_block_exp(BlockConf *conf) return exp; } + +unsigned int get_min_io_size(BlockConf *conf) +{ + if (conf->min_io_size || !conf->bs) { + return conf->min_io_size; + } + + /* Ask the OS to avoid read-modify-write cycles. But when running + * on 512b-sector disks, we should not modify the parameters that + * guests had seen so far. + */ + if (conf->bs->host_block_size > conf->logical_block_size) { + return conf->bs->host_block_size; + } + + return 0; +} diff --git a/block.h b/block.h index 4270f67..ad1d18c 100644 --- a/block.h +++ b/block.h @@ -406,6 +406,7 @@ typedef struct BlockConf { } BlockConf; unsigned int get_physical_block_exp(BlockConf *conf); +unsigned int get_min_io_size(BlockConf *conf); #define DEFINE_BLOCK_PROPERTIES(_state, _conf) \ DEFINE_PROP_DRIVE("drive", _state, _conf.bs), \ diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 4f370a6..032ccf1 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -429,7 +429,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) unsigned int unmap_sectors = s->qdev.conf.discard_granularity / s->qdev.blocksize; unsigned int min_io_size = - s->qdev.conf.min_io_size / s->qdev.blocksize; + get_min_io_size(&s->qdev.conf) / s->qdev.blocksize; unsigned int opt_io_size = s->qdev.conf.opt_io_size / s->qdev.blocksize; diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 7c44a1f..06b5c0d 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -491,7 +491,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) stl_raw(&blkcfg.seg_max, 128 - 2); stw_raw(&blkcfg.cylinders, cylinders); stl_raw(&blkcfg.blk_size, blk_size); - stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size); + stw_raw(&blkcfg.min_io_size, get_min_io_size(s->conf) / blk_size); stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size); blkcfg.heads = heads; blkcfg.sectors = secs & ~s->sector_mask; -- 1.7.7.6