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 <pbonz...@redhat.com> --- 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