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