All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zhang Haoyu" <zhanghy@sangfor.com>
To: qemu-devel <qemu-devel@nongnu.org>
Cc: Kevin Wolf <kwolf@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH] qcow2-cache: conditionally call bdrv_flush() in qcow2_cache_flush()
Date: Fri, 7 Nov 2014 09:30:59 +0800	[thread overview]
Message-ID: <201411070930569161961@sangfor.com> (raw)

Needless to call bdrv_flush() in qcow2_cache_flush()
if no cache entry is dirty.

Signed-off-by: Zhang Haoyu <zhanghy@sangfor.com>
---
 block/qcow2-cache.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 904f6b1..09ee155 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -110,10 +110,6 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i)
     BDRVQcowState *s = bs->opaque;
     int ret = 0;
 
-    if (!c->entries[i].dirty || !c->entries[i].offset) {
-        return 0;
-    }
-
     trace_qcow2_cache_entry_flush(qemu_coroutine_self(),
                                   c == s->l2_table_cache, i);
 
@@ -166,19 +162,23 @@ int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c)
 {
     BDRVQcowState *s = bs->opaque;
     int result = 0;
+    bool need_bdrv_flush = false;
     int ret;
     int i;
 
     trace_qcow2_cache_flush(qemu_coroutine_self(), c == s->l2_table_cache);
 
     for (i = 0; i < c->size; i++) {
-        ret = qcow2_cache_entry_flush(bs, c, i);
-        if (ret < 0 && result != -ENOSPC) {
-            result = ret;
+        if (c->entries[i].dirty && c->entries[i].offset) {
+            ret = qcow2_cache_entry_flush(bs, c, i);
+            if (ret < 0 && result != -ENOSPC) {
+                result = ret;
+            }
+            need_bdrv_flush = true;
         }
     }
 
-    if (result == 0) {
+    if (need_bdrv_flush && result == 0) {
         ret = bdrv_flush(bs->file);
         if (ret < 0) {
             result = ret;
@@ -289,9 +289,11 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c,
         return i;
     }
 
-    ret = qcow2_cache_entry_flush(bs, c, i);
-    if (ret < 0) {
-        return ret;
+    if (c->entries[i].dirty && c->entries[i].offset) {
+        ret = qcow2_cache_entry_flush(bs, c, i);
+        if (ret < 0) {
+            return ret;
+        }
     }
 
     trace_qcow2_cache_get_read(qemu_coroutine_self(),
-- 
1.7.12.4

             reply	other threads:[~2014-11-07  1:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-07  1:30 Zhang Haoyu [this message]
2014-11-13 11:53 ` [Qemu-devel] [PATCH] qcow2-cache: conditionally call bdrv_flush() in qcow2_cache_flush() Stefan Hajnoczi

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=201411070930569161961@sangfor.com \
    --to=zhanghy@sangfor.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.