From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH v2 1/3] block: add zero write detection interface
Date: Wed, 7 Dec 2011 12:10:57 +0000 [thread overview]
Message-ID: <1323259859-8709-2-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1323259859-8709-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 | 3 +++
block_int.h | 9 +++++++++
3 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/block.c b/block.c
index 3f072f6..5dcffb1 100644
--- a/block.c
+++ b/block.c
@@ -554,6 +554,21 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs)
bs->copy_on_read--;
}
+/**
+ * Multiple users may use this feature without worrying about clobbering its
+ * previous state. It stays enabled until all users have called to disable it.
+ */
+void bdrv_enable_zero_detection(BlockDriverState *bs)
+{
+ bs->zero_detection++;
+}
+
+void bdrv_disable_zero_detection(BlockDriverState *bs)
+{
+ assert(bs->zero_detection > 0);
+ bs->zero_detection--;
+}
+
/*
* Common part for opening disk images and files
*/
@@ -574,6 +589,7 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
bs->open_flags = flags;
bs->growable = 0;
bs->buffer_alignment = 512;
+ bs->zero_detection = 0;
assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */
if ((flags & BDRV_O_RDWR) && (flags & BDRV_O_COPY_ON_READ)) {
diff --git a/block.h b/block.h
index 1790f99..30b72e9 100644
--- a/block.h
+++ b/block.h
@@ -317,6 +317,9 @@ int64_t bdrv_get_dirty_count(BlockDriverState *bs);
void bdrv_enable_copy_on_read(BlockDriverState *bs);
void bdrv_disable_copy_on_read(BlockDriverState *bs);
+void bdrv_enable_zero_detection(BlockDriverState *bs);
+void bdrv_disable_zero_detection(BlockDriverState *bs);
+
void bdrv_set_in_use(BlockDriverState *bs, int in_use);
int bdrv_in_use(BlockDriverState *bs);
diff --git a/block_int.h b/block_int.h
index 311bd2a..89a860c 100644
--- a/block_int.h
+++ b/block_int.h
@@ -247,6 +247,15 @@ struct BlockDriverState {
/* do we need to tell the quest if we have a volatile write cache? */
int enable_write_cache;
+ /*
+ * If zero write detection is enabled this field is != 0.
+ *
+ * Block drivers that support zero detection should check this field for
+ * each write request to decide whether or not to perform detection. Since
+ * zero detection consumes CPU cycles it is disabled by default.
+ */
+ int 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.7.3
next prev parent reply other threads:[~2011-12-07 12:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-07 12:10 [Qemu-devel] [PATCH v2 0/3] block: zero write detection Stefan Hajnoczi
2011-12-07 12:10 ` Stefan Hajnoczi [this message]
2011-12-07 12:10 ` [Qemu-devel] [PATCH v2 2/3] qed: add zero write detection support Stefan Hajnoczi
2011-12-08 14:29 ` Mark Wu
2011-12-08 15:54 ` Stefan Hajnoczi
2011-12-07 12:10 ` [Qemu-devel] [PATCH v2 3/3] qemu-io: add zero write detection option 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=1323259859-8709-2-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.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).