From patchwork Wed Dec 7 12:10:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 129949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 587C21007D1 for ; Wed, 7 Dec 2011 23:12:02 +1100 (EST) Received: from localhost ([::1]:56319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYGLp-0004RR-5x for incoming@patchwork.ozlabs.org; Wed, 07 Dec 2011 07:11:53 -0500 Received: from eggs.gnu.org ([140.186.70.92]:60292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYGLd-0003nP-Sj for qemu-devel@nongnu.org; Wed, 07 Dec 2011 07:11:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYGLX-0005Qp-Ip for qemu-devel@nongnu.org; Wed, 07 Dec 2011 07:11:36 -0500 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:44956) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYGLX-0005Qa-8P for qemu-devel@nongnu.org; Wed, 07 Dec 2011 07:11:35 -0500 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 7 Dec 2011 12:11:27 -0000 Received: from d06nrmr1307.portsmouth.uk.ibm.com ([9.149.38.129]) by e06smtp13.uk.ibm.com ([192.168.101.143]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 7 Dec 2011 12:11:05 -0000 Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pB7CB5XS2130166 for ; Wed, 7 Dec 2011 12:11:05 GMT Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pB7CB4BZ012986 for ; Wed, 7 Dec 2011 05:11:05 -0700 Received: from localhost (sig-9-145-136-175.de.ibm.com [9.145.136.175]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pB7CB3Oi012918; Wed, 7 Dec 2011 05:11:04 -0700 From: Stefan Hajnoczi To: Date: Wed, 7 Dec 2011 12:10:57 +0000 Message-Id: <1323259859-8709-2-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1323259859-8709-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1323259859-8709-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 11120712-2966-0000-0000-0000028B82EB X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.109 Cc: Kevin Wolf , Marcelo Tosatti , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 1/3] block: add zero write detection interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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;