From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGlgs-00040V-UK for qemu-devel@nongnu.org; Tue, 03 Sep 2013 04:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VGlgm-0003Ba-Uc for qemu-devel@nongnu.org; Tue, 03 Sep 2013 04:10:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52092) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGlgm-0003BT-NN for qemu-devel@nongnu.org; Tue, 03 Sep 2013 04:10:16 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r838AGbv030632 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 3 Sep 2013 04:10:16 -0400 From: Max Reitz Date: Tue, 3 Sep 2013 10:09:51 +0200 Message-Id: <1378195795-1674-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1378195795-1674-1-git-send-email-mreitz@redhat.com> References: <1378195795-1674-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v5 2/6] qcow2-cache: Empty cache List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Add a function for emptying a cache, i.e., flushing it and marking all elements invalid. Signed-off-by: Max Reitz --- block/qcow2-cache.c | 18 ++++++++++++++++++ block/qcow2.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c index 7bcae09..40a5a3f 100644 --- a/block/qcow2-cache.c +++ b/block/qcow2-cache.c @@ -202,6 +202,24 @@ void qcow2_cache_depends_on_flush(Qcow2Cache *c) c->depends_on_flush = true; } +int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c) +{ + int ret, i; + + ret = qcow2_cache_flush(bs, c); + if (ret < 0) { + return ret; + } + + for (i = 0; i < c->size; i++) { + assert(c->entries[i].ref == 0); + c->entries[i].offset = 0; + c->entries[i].cache_hits = 0; + } + + return 0; +} + static int qcow2_cache_find_entry_to_replace(Qcow2Cache *c) { int i; diff --git a/block/qcow2.h b/block/qcow2.h index 10b7bf4..3db0877 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -473,6 +473,8 @@ int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c, Qcow2Cache *dependency); void qcow2_cache_depends_on_flush(Qcow2Cache *c); +int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c); + int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset, void **table); int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset, -- 1.8.3.1