qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH v2 17/18] block: default min_io_size to host block size when doing rmw
Date: Thu, 26 Jan 2012 18:22:48 +0100	[thread overview]
Message-ID: <1327598569-5199-18-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1327598569-5199-1-git-send-email-pbonzini@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 <pbonzini@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

  parent reply	other threads:[~2012-01-26 17:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-26 17:22 [Qemu-devel] [PATCH v2 00/18] Support mismatched host and guest logical block sizes Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 01/18] block: do not rely on open_flags for bdrv_is_snapshot Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 02/18] block: store actual flags in bs->open_flags Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 03/18] block: pass protocol flags up to the format Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 04/18] block: non-raw protocols never cache Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 05/18] block: remove enable_write_cache Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 06/18] block: move flag bits together Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 07/18] raw: remove the aligned_buf Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 08/18] block: rename buffer_alignment to guest_block_size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 09/18] block: add host_block_size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 10/18] raw: probe host_block_size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 11/18] iscsi: save host block size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 12/18] block: allow waiting only for overlapping writes Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 13/18] block: allow waiting at arbitrary granularity Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 14/18] block: protect against "torn reads" for guest_block_size > host_block_size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 15/18] block: align and serialize I/O when guest_block_size < host_block_size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 16/18] block: default physical block size to host block size Paolo Bonzini
2012-01-26 17:22 ` Paolo Bonzini [this message]
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 18/18] qemu-io: add blocksize argument to open Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1327598569-5199-18-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).