qemu-img: Fix exit code for errors closing the image
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2150180
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=50493336
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.
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.
Signed-off-by: Kevin Wolf kwolf@redhat.com