qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 1/3] block: add zero write detection interface
Date: Fri,  7 Oct 2011 16:49:47 +0100	[thread overview]
Message-ID: <1318002589-11315-2-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1318002589-11315-1-git-send-email-stefanha@linux.vnet.ibm.com>

Some image formats can represent zero regions efficiently even when a
backing file is present.  In order to use this feature they need to
detect zero writes and handle them specially.

Since zero write detection consumes CPU cycles it is disabled by default
and must be explicitly enabled.  This patch adds an interface to do so.

Currently no block drivers actually support zero write detection yet.
This is addressed in follow-up patches.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block.c     |   16 ++++++++++++++++
 block.h     |    2 ++
 block_int.h |   13 +++++++++++++
 3 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index e3fe97f..5cf53d6 100644
--- a/block.c
+++ b/block.c
@@ -481,6 +481,7 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
     bs->valid_key = 0;
     bs->open_flags = flags;
     bs->buffer_alignment = 512;
+    bs->use_zero_detection = false;
 
     pstrcpy(bs->filename, sizeof(bs->filename), filename);
 
@@ -3344,3 +3345,18 @@ out:
 
     return ret;
 }
+
+int bdrv_set_zero_detection(BlockDriverState *bs, bool enable)
+{
+    BlockDriver *drv = bs->drv;
+
+    if (!drv) {
+        return -ENOMEDIUM;
+    }
+    if (!drv->has_zero_detection) {
+        return -ENOTSUP;
+    }
+
+    bs->use_zero_detection = enable;
+    return 0;
+}
diff --git a/block.h b/block.h
index 16bfa0a..283dc27 100644
--- a/block.h
+++ b/block.h
@@ -273,6 +273,8 @@ int bdrv_img_create(const char *filename, const char *fmt,
 void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
 void *qemu_blockalign(BlockDriverState *bs, size_t size);
 
+int bdrv_set_zero_detection(BlockDriverState *bs, bool enable);
+
 #define BDRV_SECTORS_PER_DIRTY_CHUNK 2048
 
 void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable);
diff --git a/block_int.h b/block_int.h
index 8c3b863..3e8d768 100644
--- a/block_int.h
+++ b/block_int.h
@@ -146,6 +146,16 @@ struct BlockDriver {
      */
     int (*bdrv_has_zero_init)(BlockDriverState *bs);
 
+    /*
+     * True if zero write detection is supported, false otherwise.
+     *
+     * Block drivers that declare support for zero detection should check
+     * BlockDriverState.use_zero_detection for each write request to decide
+     * whether or not to perform detection.  Since zero detection consumes CPU
+     * cycles it is disabled by default.
+     */
+    bool has_zero_detection;
+
     QLIST_ENTRY(BlockDriver) list;
 };
 
@@ -195,6 +205,9 @@ struct BlockDriverState {
     /* do we need to tell the quest if we have a volatile write cache? */
     int enable_write_cache;
 
+    /* is zero write detection enabled? */
+    bool use_zero_detection;
+
     /* NOTE: the following infos are only hints for real hardware
        drivers. They are not used by the block driver */
     int cyls, heads, secs, translation;
-- 
1.7.6.3

  reply	other threads:[~2011-10-07 15:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-07 15:49 [Qemu-devel] [PATCH 0/3] block: zero write detection Stefan Hajnoczi
2011-10-07 15:49 ` Stefan Hajnoczi [this message]
2011-10-07 15:49 ` [Qemu-devel] [PATCH 2/3] qed: add zero write detection support Stefan Hajnoczi
2011-10-07 15:49 ` [Qemu-devel] [PATCH 3/3] qemu-io: add zero write detection option Stefan Hajnoczi
2011-10-09  9:52 ` [Qemu-devel] [PATCH 0/3] block: zero write detection Mars.cao
2011-10-11 13:46 ` Kevin Wolf
2011-10-12 10:39   ` Stefan Hajnoczi
2011-10-12 11:03     ` Kevin Wolf
2011-10-12 11:59       ` Stefan Hajnoczi

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=1318002589-11315-2-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=mtosatti@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).