From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, hreitz@redhat.com, aesteve@redhat.com,
nsoffer@redhat.com, qemu-devel@nongnu.org
Subject: [PATCH 2/4] qemu-img commit: Report errors while closing the image
Date: Thu, 12 Jan 2023 20:14:52 +0100 [thread overview]
Message-ID: <20230112191454.169353-3-kwolf@redhat.com> (raw)
In-Reply-To: <20230112191454.169353-1-kwolf@redhat.com>
blk_unref() can't report any errors that happen while closing the image.
For example, if qcow2 hits an -ENOSPC error while writing out dirty
bitmaps when it's closed, it prints error messages to stderr, but
'qemu-img commit' won't see any error return value and will therefore
look successful with exit code 0.
In order to fix this, manually inactivate the image first before calling
blk_unref(). This already performs the operations that would be most
likely to fail while closing the image, but it can still return errors.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qemu-img.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/qemu-img.c b/qemu-img.c
index 439d8de1e3..22d6ecefd5 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -449,6 +449,11 @@ static BlockBackend *img_open(bool image_opts,
blk = img_open_file(filename, NULL, fmt, flags, writethrough, quiet,
force_share);
}
+
+ if (blk) {
+ blk_set_force_allow_inactivate(blk);
+ }
+
return blk;
}
@@ -1119,6 +1124,14 @@ unref_backing:
done:
qemu_progress_end();
+ /*
+ * Manually inactivate the image first because this way we can know whether
+ * an error occurred. blk_unref() doesn't tell us about failures.
+ */
+ ret = bdrv_inactivate_all();
+ if (ret < 0 && !local_err) {
+ error_setg_errno(&local_err, -ret, "Error while closing the image");
+ }
blk_unref(blk);
if (local_err) {
--
2.38.1
next prev parent reply other threads:[~2023-01-12 19:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-12 19:14 [PATCH 0/4] qemu-img: Fix exit code for errors closing the image Kevin Wolf
2023-01-12 19:14 ` [PATCH 1/4] qcow2: Fix theoretical corruption in store_bitmap() error path Kevin Wolf
2023-01-13 7:30 ` Philippe Mathieu-Daudé
2023-01-13 10:45 ` Kevin Wolf
2023-01-13 17:37 ` Philippe Mathieu-Daudé
2023-01-12 19:14 ` Kevin Wolf [this message]
2023-01-12 19:14 ` [PATCH 3/4] qemu-img bitmap: Report errors while closing the image Kevin Wolf
2023-01-13 7:32 ` Philippe Mathieu-Daudé
2023-01-12 19:14 ` [PATCH 4/4] qemu-iotests: Test qemu-img bitmap/commit exit code on error Kevin Wolf
2023-01-13 7:30 ` [PATCH 0/4] qemu-img: Fix exit code for errors closing the image Markus Armbruster
2023-01-13 11:29 ` Kevin Wolf
2023-02-14 20:09 ` Vladimir Sementsov-Ogievskiy
2023-02-15 13:07 ` Markus Armbruster
2023-02-15 20:50 ` Vladimir Sementsov-Ogievskiy
2023-02-22 12:08 ` Reference-counting and finalizers that can fail are uneasy partners (was: [PATCH 0/4] qemu-img: Fix exit code for errors closing the image) Markus Armbruster
2023-02-22 12:54 ` Daniel P. Berrangé
2023-01-17 11:24 ` [PATCH 0/4] qemu-img: Fix exit code for errors closing the image Hanna Czenczek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230112191454.169353-3-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=aesteve@redhat.com \
--cc=hreitz@redhat.com \
--cc=nsoffer@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).