From patchwork Sun Aug 31 17:22:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lijun X-Patchwork-Id: 384551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B36001400B6 for ; Mon, 1 Sep 2014 03:23:21 +1000 (EST) Received: from localhost ([::1]:50552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XO8qV-0001V4-Pg for incoming@patchwork.ozlabs.org; Sun, 31 Aug 2014 13:23:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XO8q8-0001De-CG for qemu-devel@nongnu.org; Sun, 31 Aug 2014 13:23:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XO8pz-0000f8-AT for qemu-devel@nongnu.org; Sun, 31 Aug 2014 13:22:56 -0400 Received: from mail-pd0-x233.google.com ([2607:f8b0:400e:c02::233]:37403) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XO8pz-0000et-34 for qemu-devel@nongnu.org; Sun, 31 Aug 2014 13:22:47 -0400 Received: by mail-pd0-f179.google.com with SMTP id z10so4276370pdj.10 for ; Sun, 31 Aug 2014 10:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=DmO6TnB8plFGwpLjnC4tmxacYSCGMBceZTpI/hV5DEw=; b=cTSsS0jWr4nFYTXyYJel0xOqVvXjmQcSWU2qdlIwZMcUdfrFnNa+YB2Lj+ZiDvLKW4 0qOUfrVVJKomfSMooJWLi2MYWxV4CJncxlP1RApFMzbN3o6Q2YHRbM6l9+OqSKsW6r62 YEfAuSSDvtNdIUqhJNjFa7bkKC/V8BEsra8pX/vC0a9SH7JAZrQ0Hh5Pd5BN+0TAuE0K kG7x3Ph/W0mr9ylRgMIYYx7IOScT7rxFbcqqKmVB3yV1NYVGV3GNxLRQLE1oiTDYJXUW 6bI/pUSx8YE6BzX0ZG3kTSvMdllx+tdEWIAwl35mm+ugK2tlS2jiwcgzN4y1YMOGyDkA kqEg== X-Received: by 10.70.22.163 with SMTP id e3mr4413757pdf.157.1409505765394; Sun, 31 Aug 2014 10:22:45 -0700 (PDT) Received: from localhost ([124.202.191.136]) by mx.google.com with ESMTPSA id db4sm8565800pdb.74.2014.08.31.10.22.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Aug 2014 10:22:44 -0700 (PDT) From: Jun Li To: qemu-devel@nongnu.org Date: Mon, 1 Sep 2014 01:22:37 +0800 Message-Id: <1409505757-10344-1-git-send-email-junmuzi@gmail.com> X-Mailer: git-send-email 1.9.3 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::233 Cc: kwolf@redhat.com, famz@redhat.com, juli@redhat.com, Jun Li , stefanha@redhat.com Subject: [Qemu-devel] [PATCH] qcow2: add update refcount table realization for update_refcount 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 When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL. Signed-off-by: Jun Li --- block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 43665b8..b53a000 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, if (refcount == 0 && s->discard_passthrough[type]) { update_refcount_discard(bs, cluster_offset, s->cluster_size); } + + /* When refcount block is NULL, update refcount table */ + if (block_index == 0) { + int k = block_index; + int refcount_block_entries = s->cluster_size / sizeof(uint16_t); + for (k = 1; k < refcount_block_entries; k++) { + if (refcount_block[++k] != cpu_to_be16(refcount)) { + break; + } + } + + if (k == refcount_block_entries) { + qemu_vfree(refcount_block); + /* update refcount table */ + unsigned int refcount_table_index; + uint64_t data64 = cpu_to_be64(0); + refcount_table_index = cluster_index >> (s->cluster_bits - + REFCOUNT_SHIFT); + ret = bdrv_pwrite_sync(bs->file, + s->refcount_table_offset + + refcount_table_index * + sizeof(uint64_t), + &data64, sizeof(data64)); + if (ret < 0) { + goto fail; + } + + s->refcount_table[refcount_table_index] = data64; + + } + } } ret = 0;