Blame SOURCES/kvm-qemu-img-commit-Report-errors-while-closing-the-imag.patch

bf143f
From 2396df7fe527567e8e78761ef24ea1057ef6fa48 Mon Sep 17 00:00:00 2001
bf143f
From: Kevin Wolf <kwolf@redhat.com>
bf143f
Date: Thu, 12 Jan 2023 20:14:52 +0100
bf143f
Subject: [PATCH 2/4] qemu-img commit: Report errors while closing the image
bf143f
bf143f
RH-Author: Kevin Wolf <kwolf@redhat.com>
bf143f
RH-MergeRequest: 251: qemu-img: Fix exit code for errors closing the image
bf143f
RH-Bugzilla: 2147617
bf143f
RH-Acked-by: Hanna Czenczek <hreitz@redhat.com>
bf143f
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
bf143f
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
bf143f
RH-Commit: [2/4] 28f95bf76d1d63e2b0bed0c2ba5206bd3e5ea4f8
bf143f
bf143f
blk_unref() can't report any errors that happen while closing the image.
bf143f
For example, if qcow2 hits an -ENOSPC error while writing out dirty
bf143f
bitmaps when it's closed, it prints error messages to stderr, but
bf143f
'qemu-img commit' won't see any error return value and will therefore
bf143f
look successful with exit code 0.
bf143f
bf143f
In order to fix this, manually inactivate the image first before calling
bf143f
blk_unref(). This already performs the operations that would be most
bf143f
likely to fail while closing the image, but it can still return errors.
bf143f
bf143f
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
bf143f
Message-Id: <20230112191454.169353-3-kwolf@redhat.com>
bf143f
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
bf143f
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
bf143f
(cherry picked from commit 44efba2d713aca076c411594d0c1a2b99155eeb3)
bf143f
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
bf143f
---
bf143f
 qemu-img.c | 13 +++++++++++++
bf143f
 1 file changed, 13 insertions(+)
bf143f
bf143f
diff --git a/qemu-img.c b/qemu-img.c
bf143f
index f036a1d428..18833f7d69 100644
bf143f
--- a/qemu-img.c
bf143f
+++ b/qemu-img.c
bf143f
@@ -443,6 +443,11 @@ static BlockBackend *img_open(bool image_opts,
bf143f
         blk = img_open_file(filename, NULL, fmt, flags, writethrough, quiet,
bf143f
                             force_share);
bf143f
     }
bf143f
+
bf143f
+    if (blk) {
bf143f
+        blk_set_force_allow_inactivate(blk);
bf143f
+    }
bf143f
+
bf143f
     return blk;
bf143f
 }
bf143f
 
bf143f
@@ -1110,6 +1115,14 @@ unref_backing:
bf143f
 done:
bf143f
     qemu_progress_end();
bf143f
 
bf143f
+    /*
bf143f
+     * Manually inactivate the image first because this way we can know whether
bf143f
+     * an error occurred. blk_unref() doesn't tell us about failures.
bf143f
+     */
bf143f
+    ret = bdrv_inactivate_all();
bf143f
+    if (ret < 0 && !local_err) {
bf143f
+        error_setg_errno(&local_err, -ret, "Error while closing the image");
bf143f
+    }
bf143f
     blk_unref(blk);
bf143f
 
bf143f
     if (local_err) {
bf143f
-- 
bf143f
2.37.3
bf143f