From 7491ff4089aedca43ac84d294af0032d59b0a6bc Mon Sep 17 00:00:00 2001
From: Naphtali Sprei <nsprei@redhat.com>
Date: Wed, 7 Apr 2010 16:44:23 -0300
Subject: [PATCH 12/21] block: fix cache flushing in bdrv_commit

RH-Author: Naphtali Sprei <nsprei@redhat.com>
Message-id: <1270658667-14294-13-git-send-email-nsprei@redhat.com>
Patchwork-id: 8444
O-Subject: [RHEL6 kvm PATCH v3 rebase 12/16] block: fix cache flushing in
	bdrv_commit
Bugzilla: 537164
RH-Acked-by: Daniel P. Berrange <berrange@redhat.com>
RH-Acked-by: Christoph Hellwig <chellwig@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>

From: Christoph Hellwig <hch@lst.de>

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=537164
upstream commit: 1d44952fc7f4de113eae892401e4d50ee476e82e

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Naphtali Sprei <nsprei@redhat.com>
---
 block.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 block.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index 0675aef..9252184 100644
--- a/block.c
+++ b/block.c
@@ -571,6 +571,7 @@ int bdrv_commit(BlockDriverState *bs)
     BlockDriver *drv = bs->drv;
     int64_t i, total_sectors;
     int n, j;
+    int ret = 0;
     unsigned char sector[512];
 
     if (!drv)
@@ -602,8 +603,10 @@ int bdrv_commit(BlockDriverState *bs)
         }
     }
 
-    if (drv->bdrv_make_empty)
-	return drv->bdrv_make_empty(bs);
+    if (drv->bdrv_make_empty) {
+        ret = drv->bdrv_make_empty(bs);
+        bdrv_flush(bs);
+    }
 
     /*
      * Make sure all data we wrote to the backing device is actually
@@ -611,7 +614,7 @@ int bdrv_commit(BlockDriverState *bs)
      */
     if (bs->backing_hd)
         bdrv_flush(bs->backing_hd);
-    return 0;
+    return ret;
 }
 
 /*
-- 
1.7.0.3

