From patchwork Fri Sep 13 11:50:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 274734 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F38872C00FC for ; Fri, 13 Sep 2013 21:52:06 +1000 (EST) Received: from localhost ([::1]:46150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKRuv-0006X7-3G for incoming@patchwork.ozlabs.org; Fri, 13 Sep 2013 07:52:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKRuE-0006Mz-MS for qemu-devel@nongnu.org; Fri, 13 Sep 2013 07:51:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VKRu7-0001O7-Bp for qemu-devel@nongnu.org; Fri, 13 Sep 2013 07:51:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16949) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKRu7-0001O0-4A for qemu-devel@nongnu.org; Fri, 13 Sep 2013 07:51:15 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8DBpDhS025029 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 13 Sep 2013 07:51:13 -0400 Received: from dhcp-200-207.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8DBp5Eg032643; Fri, 13 Sep 2013 07:51:12 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 13 Sep 2013 13:50:35 +0200 Message-Id: <1379073063-14963-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1379073063-14963-1-git-send-email-kwolf@redhat.com> References: <1379073063-14963-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 05/33] qcow2-cache: Empty cache 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 From: Max Reitz Add a function for emptying a cache, i.e., flushing it and marking all elements invalid. Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- 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 49eed82..35c822b 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -478,6 +478,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,