0a122b
From 89bdd1d20e9ccde41f271fe5dc22c355cbbc822a Mon Sep 17 00:00:00 2001
0a122b
From: Jeffrey Cody <jcody@redhat.com>
0a122b
Date: Tue, 11 Feb 2014 16:14:28 +0100
0a122b
Subject: [PATCH 22/28] block: Fix bdrv_commit return value
0a122b
0a122b
RH-Author: Jeffrey Cody <jcody@redhat.com>
0a122b
Message-id: <5019e17d0114b49c58c42415e79b81abdcb648d3.1392134912.git.jcody@redhat.com>
0a122b
Patchwork-id: 57218
0a122b
O-Subject: [RHEL7 qemu-kvm PATCH 4/6] block: Fix bdrv_commit return value
0a122b
Bugzilla: 1047254
0a122b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
0a122b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
0a122b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
0a122b
From: Kevin Wolf <kwolf@redhat.com>
0a122b
0a122b
bdrv_commit() could return 0 or 1 on success, depending on whether or
0a122b
not the last sector was allocated in the overlay and whether the overlay
0a122b
format had a .bdrv_make_empty callback.
0a122b
0a122b
Most callers ignored it, but qemu-img commit would print an error
0a122b
message while the operation actually succeeded.
0a122b
0a122b
Also clean up the handling of I/O errors to return the real error code
0a122b
instead of -EIO.
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
Reviewed-by: Benoit Canet <benoit@irqsave.net>
0a122b
(cherry picked from commit dabfa6cc2e2a06269026fcb42772894f67bd0c3e)
0a122b
---
0a122b
 block.c | 15 ++++++++++-----
0a122b
 1 file changed, 10 insertions(+), 5 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 block.c |   15 ++++++++++-----
0a122b
 1 files changed, 10 insertions(+), 5 deletions(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index c7aa285..642e8d6 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -2006,13 +2006,13 @@ int bdrv_commit(BlockDriverState *bs)
0a122b
             goto ro_cleanup;
0a122b
         }
0a122b
         if (ret) {
0a122b
-            if (bdrv_read(bs, sector, buf, n) != 0) {
0a122b
-                ret = -EIO;
0a122b
+            ret = bdrv_read(bs, sector, buf, n);
0a122b
+            if (ret < 0) {
0a122b
                 goto ro_cleanup;
0a122b
             }
0a122b
 
0a122b
-            if (bdrv_write(bs->backing_hd, sector, buf, n) != 0) {
0a122b
-                ret = -EIO;
0a122b
+            ret = bdrv_write(bs->backing_hd, sector, buf, n);
0a122b
+            if (ret < 0) {
0a122b
                 goto ro_cleanup;
0a122b
             }
0a122b
         }
0a122b
@@ -2020,6 +2020,9 @@ int bdrv_commit(BlockDriverState *bs)
0a122b
 
0a122b
     if (drv->bdrv_make_empty) {
0a122b
         ret = drv->bdrv_make_empty(bs);
0a122b
+        if (ret < 0) {
0a122b
+            goto ro_cleanup;
0a122b
+        }
0a122b
         bdrv_flush(bs);
0a122b
     }
0a122b
 
0a122b
@@ -2027,9 +2030,11 @@ int bdrv_commit(BlockDriverState *bs)
0a122b
      * Make sure all data we wrote to the backing device is actually
0a122b
      * stable on disk.
0a122b
      */
0a122b
-    if (bs->backing_hd)
0a122b
+    if (bs->backing_hd) {
0a122b
         bdrv_flush(bs->backing_hd);
0a122b
+    }
0a122b
 
0a122b
+    ret = 0;
0a122b
 ro_cleanup:
0a122b
     g_free(buf);
0a122b
 
0a122b
-- 
0a122b
1.7.1
0a122b