qcow2, lazy_refcounts and killing qemu
I found out a few days ago that if you:
(1) Open a qcow2 file that has lazy_refcounts = on and a backing file, and
(2) Write lots of stuff, and
(3) Kill qemu with SIGTERM [which I believed, maybe incorrectly, is a "nice" way to kill qemu]
.. then you can end up with a corrupt qcow2 file. In particular the qcow2 file sometimes forgot that it had a backing file, but I suspect this was just a symptom and in fact the qcow2 file header wasn't being written to disk correctly.
Is it correct that sending SIGTERM to qemu should kill it cleanly, or is that no longer the case, or is lazy_refcounts a special case, or have I found a bug?
I can reproduce this easily, although of course the reproducer will involve libguestfs.
Rich.
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Quoted 6 lines · On Sat, 30 Aug 2014 15:53:13 +0100 "Richard W.M. Jones" <[email protected]>…
I found out a few days ago that if you:
(1) Open a qcow2 file that has
lazy_refcounts= on and a backing file, and(2) Write lots of stuff, and
Quoted 8 lines
(3) Kill qemu with SIGTERM [which I believed, maybe incorrectly, is a "nice" way to kill qemu]
.. then you can end up with a corrupt qcow2 file. In particular the qcow2 file sometimes forgot that it had a backing file, but I suspect this was just a symptom and in fact the qcow2 file header wasn't being written to disk correctly.
Hi Rich,
Someone in IBM hit a very similar issue with PowerKVM a few monthes ago. The symptom was a corrupted filesystem in a qcow2 file. The steps involved to kill the QEMU process while the guest OS is shutting down. Unfortunately, no easy reproducer could be found and investigations halted...
Quoted 4 lines
Is it correct that sending SIGTERM to qemu should kill it cleanly, or is that no longer the case, or is
lazy_refcountsa special case, or have I found a bug?
QEMU catches SIGTERM and calls bdrv_close(), so I would favor it is a bug or an undocumented limitation (hence a documentation bug :)
Quoted 5 lines
I can reproduce this easily, although of course the reproducer will involve libguestfs.
Rich.
Can you share this reproducer ?
Cheers.
--
Greg
Quoted 9 lines · Greg Kurz
Quoted 5 lines · On Sat, 30 Aug 2014 15:53:13 +0100 "Richard W.M. Jones" <[email protected]>…
I can reproduce this easily, although of course the reproducer will involve libguestfs.
Rich.
Can you share this reproducer ?
The immediate reproducer (not very useful for you) is virt-v2v, if you enable lazy_refcounts by hacking the call to qemu-img here:
https://github.com/libguestfs/libguestfs/blob/master/v2v/v2v.ml#L102
I'll try to come up with an actual reproducer, but I stress it's still going to use libguestfs because that's the only sane way to run qemu for the purposes of this test.
Rich.
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
A test case, attached.
Note that you have to look at the output of the final qemu-img info command. In the case where it goes wrong, the 'backing file:' and 'backing file format:' lines disappear completely. In the case where the bug is not reproduced, these lines are still present.
It's 100% reproducible for me when lazy_refcounts=on, and 0% reproducible when lazy_refcounts=off.
BUT it only occurs if the backing file is a remote source (nbd:... in this case), not if the backing file is a plain file. Make of that what you will.
Rich.
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Quoted 3 lines
# Write stuff to the overlay.
guestfish <<EOF
add-drive overlay.qcow2 format:qcow2 cachemode:unsafe
To head off any suggestions, removing cachemode:unsafe doesn't fix it.
Rich.
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Quoted 7 lines · On Mon, 1 Sep 2014 15:19:28 +0100 "Richard W.M. Jones" <[email protected]>…
A test case, attached.
Note that you have to look at the output of the final qemu-img info command. In the case where it goes wrong, the 'backing file:' and 'backing file format:' lines disappear completely. In the case where the bug is not reproduced, these lines are still present.
Quoted 9 lines
It's 100% reproducible for me when lazy_refcounts=on, and 0% reproducible when lazy_refcounts=off.
BUT it only occurs if the backing file is a remote source (nbd:... in this case), not if the backing file is a plain file. Make of that what you will.
Rich.
Thanks. I'll try that.
Signature · 7 lines
Gregory Kurz [email protected] [email protected] Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)562 165 496 "Anarchy is about taking complete responsibility for yourself." Alan Moore.
Quoted 14 lines · Richard W.M. Jones
I found out a few days ago that if you:
(1) Open a qcow2 file that has
lazy_refcounts= on and a backing file, and(2) Write lots of stuff, and
(3) Kill qemu with SIGTERM [which I believed, maybe incorrectly, is a "nice" way to kill qemu]
.. then you can end up with a corrupt qcow2 file. In particular the qcow2 file sometimes forgot that it had a backing file, but I suspect this was just a symptom and in fact the qcow2 file header wasn't being written to disk correctly.
Quoted 6 lines
Is it correct that sending SIGTERM to qemu should kill it cleanly, or is that no longer the case, or is
lazy_refcountsa special case, or have I found a bug?I can reproduce this easily, although of course the reproducer will involve libguestfs.
That is very interesting, thanks for posting.
Did you try older QEMU versions? I'm curious if this is something that crept in later or is fundamentally broken in lazy_refcounts=on.
Stefan
Quoted 2 lines · Stefan Hajnoczi
Did you try older QEMU versions? I'm curious if this is something that crept in later or is fundamentally broken in lazy_refcounts=on.
At your prompting, I've done a bit more investigation.
I was basing my observations on qemu 2.1.0. However I tried my test against qemu from git today and the bug has gone. Good!
For my entertainment, I bisected the problem, and the commit which *fixes* it is:
commit 91af7014125895cc74141be6b60f3a3e882ed743
Author: Max Reitz <[email protected]>
Date: Fri Jul 18 20:24:56 2014 +0200
block: Add bdrv_refresh_filename()
I didn't believe this either, but I have checked the result manually and I'm pretty sure that whatever this commit does, it does end up fixing the lazy_refcounts problem as a side-effect.
----------------------------------------------------------------------
I've updated the test script (attached), so you can now run it against your own qemu, and also to improve the output.
Rich.
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Quoted 16 lines · Richard W.M. Jones
Quoted 2 lines · Stefan Hajnoczi
Did you try older QEMU versions? I'm curious if this is something that crept in later or is fundamentally broken in lazy_refcounts=on.
At your prompting, I've done a bit more investigation.
I was basing my observations on qemu 2.1.0. However I tried my test against qemu from git today and the bug has gone. Good!
For my entertainment, I bisected the problem, and the commit which *fixes* it is:
commit
91af7014125895cc74141be6b60f3a3e882ed743
Author: Max Reitz <[email protected]>
Date: Fri Jul 18 20:24:56 2014 +0200
Quoted 5 lines
block: Add
bdrv_refresh_filename()I didn't believe this either, but I have checked the result manually and I'm pretty sure that whatever this commit does, it does end up fixing the
lazy_refcountsproblem as a side-effect.
Weird. Maybe Max (cc'ed) has an idea.
Quoted 4 lines
----------------------------------------------------------------------
I've updated the test script (attached), so you can now run it against your own qemu, and also to improve the output.
Quoted 16 lines · Richard W.M. Jones
Quoted 2 lines · Stefan Hajnoczi
Did you try older QEMU versions? I'm curious if this is something that crept in later or is fundamentally broken in lazy_refcounts=on.
At your prompting, I've done a bit more investigation.
I was basing my observations on qemu 2.1.0. However I tried my test against qemu from git today and the bug has gone. Good!
For my entertainment, I bisected the problem, and the commit which *fixes* it is:
commit
91af7014125895cc74141be6b60f3a3e882ed743
Author: Max Reitz <[email protected]>
Date: Fri Jul 18 20:24:56 2014 +0200
Quoted 5 lines
block: Add
bdrv_refresh_filename()I didn't believe this either, but I have checked the result manually and I'm pretty sure that whatever this commit does, it does end up fixing the
lazy_refcountsproblem as a side-effect.
Thanks!
Quoted 17 lines · Markus Armbruster
Quoted 15 lines · Richard W.M. Jones
Quoted 2 lines · Stefan Hajnoczi
Did you try older QEMU versions? I'm curious if this is something that crept in later or is fundamentally broken in lazy_refcounts=on.
At your prompting, I've done a bit more investigation.
I was basing my observations on qemu 2.1.0. However I tried my test against qemu from git today and the bug has gone. Good!
For my entertainment, I bisected the problem, and the commit which *fixes* it is:
commit 91af7014125895cc74141be6b60f3a3e882ed743 Author: Max Reitz <[email protected]> Date: Fri Jul 18 20:24:56 2014 +0200
Quoted 6 lines
Quoted 5 lines
block: Add
bdrv_refresh_filename()I didn't believe this either, but I have checked the result manually and I'm pretty sure that whatever this commit does, it does end up fixing the
lazy_refcountsproblem as a side-effect.Weird. Maybe Max (cc'ed) has an idea.
No, not really. The only remotely related effect I can imagine is that this patch allows a BDS to remember when it has been opened with runtime options differing from the standard (e.g. forcing lazy_refcounts=on for a qcow2 image without that flag set), but it seems this is not the case here. Also, this should even be ignored in most cases.
Other than that, the main intention for this commit is to allow block drivers to reconstruct a filename based solely on the BDS, i.e. a filename which more or less recreates the same BDS when opened. The filename in the BDS will therefore no longer be necessarily the one originally used for opening it.
Max