qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v5 2/6] qcow2-cache: Empty cache
Date: Tue,  3 Sep 2013 10:09:51 +0200	[thread overview]
Message-ID: <1378195795-1674-3-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1378195795-1674-1-git-send-email-mreitz@redhat.com>

Add a function for emptying a cache, i.e., flushing it and marking all
elements invalid.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 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

  parent reply	other threads:[~2013-09-03  8:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-03  8:09 [Qemu-devel] [PATCH v5 0/6] block/qcow2: Image file option amendment Max Reitz
2013-09-03  8:09 ` [Qemu-devel] [PATCH v5 1/6] block: " Max Reitz
2013-09-03  8:09 ` Max Reitz [this message]
2013-09-03  8:09 ` [Qemu-devel] [PATCH v5 3/6] qcow2-cluster: Expand zero clusters Max Reitz
2013-09-03  8:09 ` [Qemu-devel] [PATCH v5 4/6] qcow2: Save refcount order in BDRVQcowState Max Reitz
2013-09-03  8:09 ` [Qemu-devel] [PATCH v5 5/6] qcow2: Implement bdrv_amend_options Max Reitz
2013-09-03  8:09 ` [Qemu-devel] [PATCH v5 6/6] qemu-iotest: qcow2 image option amendment Max Reitz
2013-09-03  8:42 ` [Qemu-devel] [PATCH v5 0/6] block/qcow2: Image file " Kevin Wolf
2013-09-09 12:02 ` Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1378195795-1674-3-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).