Skip to content

qemu-img: Fix exit code for errors closing the image

Kevin Wolf qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 12 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4qcow2: Fix theoretical corruption in store_bitmap() error pathblock/qcow2-bitmap.c+3 -23 replies
2/4qemu-img commit: Report errors while closing the imageqemu-img.c+13 -00 replies
3/4qemu-img bitmap: Report errors while closing the imageqemu-img.c+11 -01 reply
4/4qemu-iotests: Test qemu-img bitmap/commit exit code on errortests/qemu-iotests/tests/qemu-img-close-errors tests/qemu-iotests/tests/qemu-img-close-errors.out+118 -00 replies

Reviews trailers per patch

2 of 4 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchPhilippe Mathieu-DaudéHanna Czenczek
SeriesR-b
1/4R-b
2/4
3/4R-b
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/4] qemu-img: Fix exit code for errors closing the image

This series addresses the problem described in these bug reports:
https://gitlab.com/qemu-project/qemu/-/issues/1330
https://bugzilla.redhat.com/show_bug.cgi?id=2147617

qcow2 can fail when writing back dirty bitmaps in qcow2_inactivate(). However, when the function is called through blk_unref(), in the case of such errors, while an error message is written to stderr, the callers never see an error return. Specifically, 'qemu-img bitmap/commit' are reported to exit with an exit code 0 despite the errors.

The solution taken here is inactivating the images first, which can still return errors, but already performs all of the write operations. Only then the images are actually blk_unref()-ed.

If we agree that this is the way to go (as a potential alternative, allowing blk_unref() to fail would require changes in all kinds of places, many of which probably wouldn't even know what to do with the error), then I suppose doing the same for other qemu-img subcommands would make sense, too.

As a bonus fix, I found an endianness confusion in an error path of store_bitmap(). The reported error message "qcow2_free_clusters failed:
No space left on device" looked too suspicious to ignore this. Freeing an actually existing cluster should never run into ENOSPC.

Kevin Wolf (4):
qcow2: Fix theoretical corruption in store_bitmap() error path qemu-img commit: Report errors while closing the image qemu-img bitmap: Report errors while closing the image
qemu-iotests: Test qemu-img bitmap/commit exit code on error

 block/qcow2-bitmap.c                          |  5 +-
 qemu-img.c                                    | 24 +++++
 .../qemu-iotests/tests/qemu-img-close-errors  | 95 +++++++++++++++++++
 .../tests/qemu-img-close-errors.out           | 23 +++++
 4 files changed, 145 insertions(+), 2 deletions(-)
 create mode 100755 tests/qemu-iotests/tests/qemu-img-close-errors
 create mode 100644 tests/qemu-iotests/tests/qemu-img-close-errors.out
Signature · 1 line
2.38.1