thebeanogamer / rpms / qemu-kvm

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