From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MGV24-0001Po-Os for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:32:44 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MGV21-0001H4-1r for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:32:44 -0400 Received: from [199.232.76.173] (port=53238 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MGV20-0001Gj-4f for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:32:40 -0400 Received: from mx2.redhat.com ([66.187.237.31]:42608) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MGV1z-0000kZ-Dm for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:32:39 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5G9WcB2003944 for ; Tue, 16 Jun 2009 05:32:38 -0400 From: Kevin Wolf Date: Tue, 16 Jun 2009 11:31:30 +0200 Message-Id: <1245144690-27805-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1245144690-27805-1-git-send-email-kwolf@redhat.com> References: <1245144690-27805-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 3/3] update_refcount: Write complete sectors List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf When updating the refcount blocks in update_refcount(), write complete sectors instead of updating single entries. Signed-off-by: Kevin Wolf --- block/qcow2-refcount.c | 34 ++++++++++++++++++++++++++-------- 1 files changed, 26 insertions(+), 8 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index b38390c..dd6e293 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -209,6 +209,27 @@ static int64_t alloc_refcount_block(BlockDriverState *bs, int64_t cluster_index) return refcount_block_offset; } +#define REFCOUNTS_PER_SECTOR (512 >> REFCOUNT_SHIFT) +static int write_refcount_block_entries(BDRVQcowState *s, + int64_t refcount_block_offset, int first_index, int last_index) +{ + size_t size; + + first_index &= ~(REFCOUNTS_PER_SECTOR - 1); + last_index = (last_index + REFCOUNTS_PER_SECTOR) + & ~(REFCOUNTS_PER_SECTOR - 1); + + size = (last_index - first_index) << REFCOUNT_SHIFT; + if (bdrv_pwrite(s->hd, + refcount_block_offset + (first_index << REFCOUNT_SHIFT), + &s->refcount_block_cache[first_index], size) != size) + { + return -EIO; + } + + return 0; +} + /* XXX: cache several refcount block clusters ? */ static int update_refcount(BlockDriverState *bs, int64_t offset, int64_t length, @@ -238,10 +259,9 @@ static int update_refcount(BlockDriverState *bs, old_table_index = table_index; table_index = cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT); if ((old_table_index >= 0) && (table_index != old_table_index)) { - size_t size = (last_index - first_index + 1) << REFCOUNT_SHIFT; - if (bdrv_pwrite(s->hd, - refcount_block_offset + (first_index << REFCOUNT_SHIFT), - &s->refcount_block_cache[first_index], size) != size) + + if (write_refcount_block_entries(s, refcount_block_offset, + first_index, last_index) < 0) { return -EIO; } @@ -278,10 +298,8 @@ static int update_refcount(BlockDriverState *bs, /* Write last changed block to disk */ if (refcount_block_offset != 0) { - size_t size = (last_index - first_index + 1) << REFCOUNT_SHIFT; - if (bdrv_pwrite(s->hd, - refcount_block_offset + (first_index << REFCOUNT_SHIFT), - &s->refcount_block_cache[first_index], size) != size) + if (write_refcount_block_entries(s, refcount_block_offset, + first_index, last_index) < 0) { return -EIO; } -- 1.6.0.6