Bug 22221 - qemu-0.14: restore snapshot defekt für ausgeschaltete VMs
qemu-0.14: restore snapshot defekt für ausgeschaltete VMs
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: Virtualization - KVM
UCS 2.4
Other Linux
: P5 critical (vote)
: UCS 2.4-3
Assigned To: Philipp Hahn
Janek Walkenhorst
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-04-14 10:36 CEST by Philipp Hahn
Modified: 2014-03-03 09:34 CET (History)
5 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:
hahn: Patch_Available+


Attachments
Revert Qemu to old behaviour when restoring snapshots. (626 bytes, patch)
2011-04-14 11:28 CEST, Philipp Hahn
Details | Diff
Shell script zum 100%igen reproduzieren (1.71 KB, text/plain)
2011-08-04 16:30 CEST, Philipp Hahn
Details
Python-Skript zum Dumpen einer Qcow2-Imagedatei (9.52 KB, text/plain)
2011-08-04 16:32 CEST, Philipp Hahn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Hahn univentionstaff 2011-04-14 10:36:17 CEST
Das Snapshot-Feature von qemu-0.14 scheint für ausgeschaltete VMs defekt zu sein: <https://bugs.launchpad.net/qemu/+bug/726619>

Der Defekt ist wohl durch f0aa7a8b2d518c54430e4382309281b93e51981a (Juli 2010!) eingeführt: Dort wurde die Reihenfolge vertauscht, so daß nun nicht mehr zuerst der alte Zustand des Block-Devices hergestellt wird, sondern Qemu direkt abbricht, weil der Snapshot keinen RAM-Zustand (sn.vm_state_size == 0) enthält. Dadurch ist dann beim nächsten Start natürlich das Block-Device nicht auf den Snapshot zurückgesetzt.

# apt-get build-dep qemu-kvm
# apt-get source qemu-kvm
# cd qemu-kvm-0.14.0+dfsg
# export DEB_BUILD_OPTIONS=noopt
# dpkg-buildpackage -uc -us -b
# gdb x86_64-softmmu/qemu-system-x86_64
(gdb) set args -S -M pc-0.14 -enable-kvm -m 512 -smp 1,sockets=1,cores=1,threads=1 -name tpeterse_other-tc -uuid 4760c57a-0d2d-f245-fb81-a521f3fef873 -nodefconfig -nodefaults -chardev socket,id=monitor,path=/var/lib/libvirt/qemu/tpeterse_other-tc.monitor,server,nowait -mon chardev=monitor,mode=readline -rtc base=utc -boot cnd -drive file=/var/lib/libvirt/images/tpeterse_other-tc-0.qcow2,if=none,id=drive-ide0-0-0,format=qcow2 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -netdev tap,ifname=tap0,script=no,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:80:5e:bf,bus=pci.0,addr=0x3 -usb -device usb-tablet,id=input0 -vnc 0.0.0.0:0 -k de -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4 -loadvm pre-update-flash -option-rom /usr/share/kvm/pxe-rtl8139.bin
(gdb) break load_vmstate
(gdb) run
(gdb) print sn
$6 = {id_str = "1", '\0' <repeats 126 times>, name = "pre-update-flash", '\0' <repeats 239 times>, vm_state_size = 0, date_sec = 1302698007, date_nsec = 711909000, 
  vm_clock_nsec = 0}



Könnte auch was mit Bug #22201 zu tun haben, halte ich aber eher für unwahrscheinlich.
Comment 1 Philipp Hahn univentionstaff 2011-04-14 11:28:32 CEST
Created attachment 3179 [details]
Revert Qemu to old behaviour when restoring snapshots.

Ein kurzer Test hat gezeigt, das es in der Tat ausreicht, die Reihenfolge von bdrv_snapshot_goto() und dem Test (sn.vm_state_size == 0) umzudrehen, um das alte Verhalten wieder zu erhalten.

Als Workaround kann für ausgeschaltete VMs das Qcow2-Image per Hand zurückgerollt werden:
# qemu-img snapshot -l "/var/lib/libvirt/images/tpeterse_other-tc-0.qcow2"
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         pre-update-flash          0 2011-04-13 14:33:27   00:00:00.000
# qemu-img snapshot -a "pre-update-flash" "/var/lib/libvirt/images/tpeterse_other-tc-0.qcow2"

Passender Bug-Report wurde an die Qemu-devel- und libvir-MLs geschickt.
Comment 2 Philipp Hahn univentionstaff 2011-08-02 20:35:59 CEST
I: Upstream-git bleibt dabei, das für offline-Snapshots qemu-img zu benutzen
ist:
<http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=commit;h=e11480db7ff15a9e878f6b3cc1199b439bf7c825>

I: Der angehängte Patch ist ein partial revert von
<http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=commit;f0aa7a8b2d518c54430e4382309281b93e51981a>.

E: Das hat jetzt wiederholt dazu geführt, das nach einigen Reverts das
Qcow2-Image komplett kaputt war. Mein Vorgehen war wie folgt:
1. Squeeze installieren
2. Backup des Images erstellen: dd if=/var/lib/libvirt/images/$VM-0.qcow2
of=/var/lib/libvirt/images/$VM-0.qcow2.bak bs=1M
2. Create Snapshot "Off"
3. Starten
4. "dpkg -P exim4", um eine Modifikation zu haben
5. Crate Snapshot "On"
6. "dd if=/dev/zero bs=1M count=1k of=/dev/vda ; sync ; touch /foo ; sync ;
echo b >/proc/sysrq-trigger"
7. Revert to Snapshot "On" bzw. "Off".

I: Das sollte immer funktionieren, aber nach ein paar Versuchen mit dem
gepatchten qemu-0.14.0 ist das Image kaputt und lässt sich nicht mehr booten.
Ein "qemu-img check /var/lib/libvirt/images/$VM-0.qcow2" zeigt sehr viele
Fehler.

E: Das gleiche mit einem gepatchten qemu-0.14.1: Auch da geht das Image kaputt.

E: Mit einem ungepatchten qemu-0.14.0 habe ich das Image auch kaputt bekommen.

I: Mit einem ungepatchten qemu-0.14.1 hat es bisher funktioniert, allerdings
muß man auch hier eine ausgeschaltete VM per "qemu-img snapshot -a "$SNAP_NAME"
"/var/lib/libvirt/images/$VM-0.qcow2" reverten.
Comment 3 Philipp Hahn univentionstaff 2011-08-04 08:35:03 CEST
Im Debian-Paket von qemu-kvm_0.14.1 ist folgender Patch enthalten, der ein Problem mit 32-Bit Gast-Systemen auf 64-Bit Host-Systemen behebt: <http://bugs.debian.org/625571> → <http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=commit;h=51b0c6065aa6e47a47094d73e24be298a4a7f3a1>. Der Patch bezieht sich eigentlich auf Live-Migration, ist aber auch für Suspend/Resume und damit für Snapshots relevant.

Das sieht zwar gut und relevant aus, allerdings trat das Problem mit qemu-kvm_0.14.1 immer noch auf, allerdings bisher nur bei der Verwendung von qemu-img (aus dem Paket qemu_0.14.0.
Comment 4 Philipp Hahn univentionstaff 2011-08-04 16:30:31 CEST
Created attachment 3425 [details]
Shell script zum 100%igen reproduzieren

Das scheint ein Bug in qemu-img zu sein.
Folgende Email ging an die qemu und kvm Mailingliste:

it seems like I have discovered a bug in qemu-0.14.1 which corrupts Qcow2 
image files when using internal snapshots.
I tied this both on an amd64 host running our Debian bases UCS distribution 
(using pure qemu-kvm_0.14 and pure qemu-kvm_0.14.1) and also on a pure Debian 
i386 sid installation (patched qemu-kvm_0.14.1).
I can reproducte this every time doing the following steps:
0. Create and install VM
1. Shut down VM
2. Create offline snapshot using "qemu-img snapshot -c Off image.qcow2"
3. Start VM
4. Create online snapshot using "savevm On"
5. Shut down VM
6. Revert to snapshot using "qemu-img snapshot -a Off image.qcow2"
Repeat step 6 three or more times and the Image is destroyed.

My guess is that this is a but in qemu-img, which is related to having an 
online snapshot (VM running) while reverting to an offline snapshot (VM 
stopped), because I wasn't able to reproduce this using only offline 
snapshots or only online snapshots.

I have attached a shell script to reproduce this bug on all my runs.
* It both happens with kvm-0.14.1 and also with qemu-0.14.1.
* The cache stragtegy "writethrough" vs. "writeback" is irrelevant.

The script needs an image nameded "pmh_squeeze-0.qcow.bak2" of an VM where you 
can login via serial console using "root" for login and "univention" for 
password. You can use other images as well, as long as you modify the block 
device from within the VM. You get get it from 
<http://download.univention.de/download/temp/qemu-0.14-qcow2/>

There you will also find the beginning of a small Python program 
called "qcow2.py" which can be used to dump the structure of an qcow2 file in 
some more human readable format with some consistency checking.

Related links:
<http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=commit;h=e11480db7ff15a9e878f6b3cc1199b439bf7c825>
<http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=commit;h=f0aa7a8b2d518c54430e4382309281b93e51981a>
<http://lists.gnu.org/archive/html/qemu-devel/2011-04/msg01376.html>
Comment 5 Philipp Hahn univentionstaff 2011-08-04 16:32:58 CEST
Created attachment 3426 [details]
Python-Skript zum Dumpen einer Qcow2-Imagedatei
Comment 6 Philipp Hahn univentionstaff 2011-08-04 17:00:50 CEST
Erste Reaktion von Kevin Wolf (RedHat) im IRC bzw. auf dem ML:

Thanks for the report. This small script seems to be enough to reproduce the corruption:

qemu-img create -f qcow2 /tmp/sn.qcow2 64M
qemu-img snapshot -c foo /tmp/sn.qcow2
qemu-io -c 'write -b 0 4M' /tmp/sn.qcow2
qemu-img snapshot -a foo /tmp/sn.qcow2
Comment 7 Philipp Hahn univentionstaff 2011-08-04 20:30:21 CEST
Patch: <http://lists.gnu.org/archive/html/qemu-devel/2011-08/msg00716.html>
Wurde erfolgreich getestet und hat das Problem behoben.
Comment 8 Philipp Hahn univentionstaff 2011-08-05 14:38:47 CEST
Der Patch in Version v3 <http://lists.gnu.org/archive/html/qemu-devel/2011-08/msg00851.html> wurde in den beiden Quellpaketen "qemu-kvm" und "qemu" eingespielt. Ersteres liefert "/usr/bin/kvm" während aus letzterem das Paket "qemu-utils" gebaut wird, das "/usr/bin/qemu-img" beinhaltet.

svn9540, svn9541, qemu-kvm_0.14.1+dfsg-4.12.201108051244, qemu_0.14.1+dfsg-3.23.201108051249

ChangeLog:
\item Die Versionen von Qemu und Qemu-KVM wurden jeweils auf die Version 0.14.1 aktualisiert.
...
\item Beim Wiederherstellen von Sicherungspunkten wurden einige Fehler korrigiert (\ucsBug{22636}, \ucsBug{22221}).


Tests:
# 1
qemu-img create -f qcow2 /tmp/sn.qcow2 64M
qemu-img snapshot -c foo /tmp/sn.qcow2
qemu-io -c 'write -b 0 4M' /tmp/sn.qcow2
qemu-img snapshot -a foo /tmp/sn.qcow2
qemu-img check /tmp/sn.qcow2

# 2
qemu-img create -f qcow2 /tmp/sn.qcow2 16m -o cluster_size=1024
qemu-img snapshot -c foo /tmp/sn.qcow2
qemu-io -c 'write -b 0 4M' /tmp/sn.qcow2
qemu-img snapshot -a foo /tmp/sn.qcow2
qemu-img check /tmp/sn.qcow2 # Leaks sind "normal" und unkritisch
Comment 9 Philipp Hahn univentionstaff 2011-08-09 15:11:34 CEST
In libvirt wurde die Logik für das Wiederherstellen von Sicherungspunkten von ausgeschalteten KVM-Instanzen ergänzt.

Getestet werden sollten möglichst alle 4 Übergänge: off→off, off→on, on→off, on→on
# virsh define "$VM.xml"
# virsh snapshot-create "$VM" <<<'<domainsnapshot><name>Before</name></domainsnapshot>'
# virsh start "$VM"
# virsh snapshot-create "$VM" <<<'<domainsnapshot><name>Running</name></domainsnapshot>'
# ... 'dd if=/dev/zero bs=1M count=1k of=/dev/vda ; sync
# virsh snapshot-create "$VM" <<<'<domainsnapshot><name>Blanked</name>
# virsh destroy "$VM"
# virsh snapshot-create "$VM" <<<'<domainsnapshot><name>After</name></domainsnapshot>'
# virsh snapshot-revert "$VM" "$SNAP_NAME"

svn9547, libvirt-bin_0.8.7-1.90.201108091448

ChangeLog:
\item In \ucsName{libvirt} wurde eine Fehler behoben, das das Wiederherstellen von Sicherungspunkten von ausgeschalteten KVM-Instanzen verhindert hat (\ucsBug{22221}).
Comment 10 Philipp Hahn univentionstaff 2011-08-10 12:29:56 CEST
Upstream hat inzwischen einen eigenen Patch <http://www.redhat.com/archives/libvir-list/2011-August/msg00326.html> in der Entwicklung, der noch ein Speicherleck in meinem Patch aufgedeckt hat. Deswegen wurde der Patch nochmal überarbeitet und basiert jetzt auf dem Upstream-Vorschlag.

svn9548, libvirt0_0.8.7-1.91.201108101210

ChangeLog: keine Änderung
Comment 11 Janek Walkenhorst univentionstaff 2011-08-25 16:35:06 CEST
Obige kleine Testskripte funktionieren.

Es wurden mehrere Snapshots angelegt mit der VM offline und online.
Dann wurden bei diviersen Wiederherstellungen keine Probleme beobachtet.
Im Speziellen auch nicht bei den Fällen VM offline, revert auf online-Snapshot, (sowie offline→offline, online→online, online→offline)

Changelog OK
Comment 12 Sönke Schwardt-Krummrich univentionstaff 2011-09-14 10:56:55 CEST
UCS 2.4-3 wurde veröffentlicht. Sollte der hier beschriebene Bug mit einer
neueren Version von UCS erneut auftreten, so sollte der Bug dupliziert werden:
"Clone This Bug".