qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH 3/3] block: do not rely on the buffer alignment passed to the guest
Date: Wed, 23 Nov 2011 17:51:27 +0100	[thread overview]
Message-ID: <1322067087-16884-4-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1322067087-16884-1-git-send-email-pbonzini@redhat.com>

The guest alignment should not override the host's.  Instead, just use
the bdrv_set_buffer_alignment calls to print a warning about possible
performance degradations due to insufficiently-aligned guest buffers.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block.c           |    8 ++++++--
 block.h           |    2 +-
 hw/ide/core.c     |    2 +-
 hw/scsi-disk.c    |    2 +-
 hw/scsi-generic.c |    1 -
 hw/virtio-blk.c   |    2 +-
 6 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/block.c b/block.c
index aba92ad..cd11344 100644
--- a/block.c
+++ b/block.c
@@ -3039,9 +3039,13 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
     return NULL;
 }
 
-void bdrv_set_buffer_alignment(BlockDriverState *bs, int align)
+void bdrv_check_buffer_alignment(BlockDriverState *bs, int align)
 {
-    bs->buffer_alignment = align;
+    if ((bs->open_flags & BDRV_O_NOCACHE) && bdrv_get_alignment(bs) > align) {
+        error_report("Host block size is %d, guest block size is %d.\n"
+		     "cache=none may cause performance degradation.",
+		     bdrv_get_alignment(bs), align);
+    }
 }
 
 void *qemu_blockalign(BlockDriverState *bs, size_t size)
diff --git a/block.h b/block.h
index 5fa632c..386284c 100644
--- a/block.h
+++ b/block.h
@@ -295,7 +295,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
                     char *options, uint64_t img_size, int flags);
 
 int bdrv_get_alignment(BlockDriverState *bs);
-void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
+void bdrv_check_buffer_alignment(BlockDriverState *bs, int align);
 void *qemu_blockalign(BlockDriverState *bs, size_t size);
 
 #define BDRV_SECTORS_PER_DIRTY_CHUNK 2048
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 93a1a68..3b8cdb2 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1863,7 +1863,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
     s->smart_selftest_count = 0;
     if (kind == IDE_CD) {
         bdrv_set_dev_ops(bs, &ide_cd_block_ops, s);
-        bdrv_set_buffer_alignment(bs, 2048);
+        bdrv_check_buffer_alignment(bs, 2048);
     } else {
         if (!bdrv_is_inserted(s->bs)) {
             error_report("Device needs media, but drive is empty");
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 673948c..946d670 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1553,7 +1553,7 @@ static int scsi_initfn(SCSIDevice *dev)
     if (s->removable) {
         bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_cd_block_ops, s);
     }
-    bdrv_set_buffer_alignment(s->qdev.conf.bs, s->qdev.blocksize);
+    bdrv_check_buffer_alignment(s->qdev.conf.bs, s->qdev.blocksize);
 
     bdrv_iostatus_enable(s->qdev.conf.bs);
     add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, NULL);
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index 9594cc1..c681a37 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -188,7 +188,6 @@ static void scsi_read_complete(void * opaque, int ret)
             s->blocksize = ldl_be_p(&r->buf[8]);
             s->max_lba = ldq_be_p(&r->buf[0]);
         }
-        bdrv_set_buffer_alignment(s->conf.bs, s->blocksize);
 
         scsi_req_data(&r->req, len);
         if (!r->req.io_canceled) {
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 91c92b2..ddc8b15 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -624,7 +624,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
     register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
     bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
-    bdrv_set_buffer_alignment(s->bs, conf->logical_block_size);
+    bdrv_check_buffer_alignment(s->bs, conf->logical_block_size);
 
     bdrv_iostatus_enable(s->bs);
     add_boot_device_path(conf->bootindex, dev, "/disk@0,0");
-- 
1.7.7.1

  parent reply	other threads:[~2011-11-23 16:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-23 16:51 [Qemu-devel] [RFC PATCH 0/3] block: add support for 4k logical blocks Paolo Bonzini
2011-11-23 16:51 ` [Qemu-devel] [RFC PATCH 1/3] block: add bdrv_get_alignment, use it Paolo Bonzini
2011-11-23 16:51 ` [Qemu-devel] [RFC PATCH 2/3] raw: implement raw_get_alignment Paolo Bonzini
2011-11-23 16:51 ` Paolo Bonzini [this message]
2011-11-25  7:26 ` [Qemu-devel] [RFC PATCH 0/3] block: add support for 4k logical blocks Mark Wu
2011-11-25  8:27   ` Paolo Bonzini
2011-11-25 11:13     ` Christoph Hellwig
2011-11-28  3:05     ` Mark Wu

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=1322067087-16884-4-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@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).