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

ed5979
From d0d3d694b3a8d200442484ae0c9d263e0439cd04 Mon Sep 17 00:00:00 2001
ed5979
From: Kevin Wolf <kwolf@redhat.com>
ed5979
Date: Thu, 12 Jan 2023 20:14:53 +0100
ed5979
Subject: [PATCH 03/20] qemu-img bitmap: Report errors while closing the image
ed5979
MIME-Version: 1.0
ed5979
Content-Type: text/plain; charset=UTF-8
ed5979
Content-Transfer-Encoding: 8bit
ed5979
ed5979
RH-Author: Kevin Wolf <kwolf@redhat.com>
ed5979
RH-MergeRequest: 143: qemu-img: Fix exit code for errors closing the image
ed5979
RH-Bugzilla: 2150180
ed5979
RH-Acked-by: Thomas Huth <thuth@redhat.com>
ed5979
RH-Acked-by: Hanna Czenczek <hreitz@redhat.com>
ed5979
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
ed5979
RH-Commit: [3/4] 4a704fec2e3bcb47b2be1529e27fd1833d58c517 (kmwolf/centos-qemu-kvm)
ed5979
ed5979
blk_unref() can't report any errors that happen while closing the image.
ed5979
For example, if qcow2 hits an -ENOSPC error while writing out dirty
ed5979
bitmaps when it's closed, it prints error messages to stderr, but
ed5979
'qemu-img bitmap' won't see any error return value and will therefore
ed5979
look successful with exit code 0.
ed5979
ed5979
In order to fix this, manually inactivate the image first before calling
ed5979
blk_unref(). This already performs the operations that would be most
ed5979
likely to fail while closing the image, but it can still return errors.
ed5979
ed5979
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1330
ed5979
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ed5979
Message-Id: <20230112191454.169353-4-kwolf@redhat.com>
ed5979
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
ed5979
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
ed5979
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ed5979
(cherry picked from commit c5e477110dcb8ef4642dce399777c3dee68fa96c)
ed5979
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ed5979
---
ed5979
 qemu-img.c | 11 +++++++++++
ed5979
 1 file changed, 11 insertions(+)
ed5979
ed5979
diff --git a/qemu-img.c b/qemu-img.c
ed5979
index 3cbdda9f76..2f85bb7ede 100644
ed5979
--- a/qemu-img.c
ed5979
+++ b/qemu-img.c
ed5979
@@ -4646,6 +4646,7 @@ static int img_bitmap(int argc, char **argv)
ed5979
     QSIMPLEQ_HEAD(, ImgBitmapAction) actions;
ed5979
     ImgBitmapAction *act, *act_next;
ed5979
     const char *op;
ed5979
+    int inactivate_ret;
ed5979
 
ed5979
     QSIMPLEQ_INIT(&actions);
ed5979
 
ed5979
@@ -4830,6 +4831,16 @@ static int img_bitmap(int argc, char **argv)
ed5979
     ret = 0;
ed5979
 
ed5979
  out:
ed5979
+    /*
ed5979
+     * Manually inactivate the images first because this way we can know whether
ed5979
+     * an error occurred. blk_unref() doesn't tell us about failures.
ed5979
+     */
ed5979
+    inactivate_ret = bdrv_inactivate_all();
ed5979
+    if (inactivate_ret < 0) {
ed5979
+        error_report("Error while closing the image: %s", strerror(-inactivate_ret));
ed5979
+        ret = 1;
ed5979
+    }
ed5979
+
ed5979
     blk_unref(src);
ed5979
     blk_unref(blk);
ed5979
     qemu_opts_del(opts);
ed5979
-- 
ed5979
2.31.1
ed5979