thebeanogamer / rpms / qemu-kvm

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