----------------------------------- [kashyap@moon vmimgs2]$ ls -lash test-f17base.qcow2 1.1G -rw-r--r--. 1 kashyap kashyap 1.1G Oct 7 20:44 test-f17base.qcow2 [kashyap@moon vmimgs2]$ [kashyap@moon vmimgs2]$ qemu-img convert -f qcow2 -O raw test-f17base.qcow2 test-f17base.img [kashyap@moon vmimgs2]$ ls -lash test-f17base.img 608M -rw-r--r--. 1 kashyap kashyap 1.0G Oct 7 20:44 test-f17base.img [kashyap@moon vmimgs2]$ ----------------------------------- [Test-1] -------- + Base file image = qcow2; And rest of all backing files are also qcow2 - [base] <-- [snap-1] <-- [snap-2] <-- [snap3] <-- [act-f17-base.qcow2] Flatten the above chain to: (resulting in invalidating snap1, snap2, snap3) - [base] <-- [act-f17-base.qcow2] ================== [root@moon libvirt]# virsh blockcommit --domain f17-base vda --wait --base /export/vmimgs2/f17-base.qcow2 --top /export/vmimgs2/snap3-f17-base.qcow2 --verbose Block Commit: [100 %] Commit complete [root@moon libvirt]# ================== - For a simple test, I've added a directory(/export), & a few text files into snap1, snap2, snap3 BEFORE 'blockcommit' (the text files & directory does not reflect in the guest file system _before_ blockcommit) #======================# [kashyap@moon qemu]$ guestfish --ro -i -a /export/vmimgs2/f17-base.qcow2 Welcome to guestfish, the libguestfs filesystem interactive shell for editing virtual machine filesystems. Type: 'help' for help on commands 'man' to read the manual 'quit' to quit the shell Operating system: Fedora release 17 (Beefy Miracle) /dev/sda1 mounted on / > ls /export libguestfs: error: ls0: opendir: /export: No such file or directory > #======================# AFTER 'blockcommit' (the text files & directory does reflect on the guest file system _after_ blockcommit) #======================# [kashyap@moon qemu]$ guestfish --ro -i -a /export/vmimgs2/f17-base.qcow2 Welcome to guestfish, the libguestfs filesystem interactive shell for editing virtual machine filesystems. Type: 'help' for help on commands 'man' to read the manual 'quit' to quit the shell Operating system: Fedora release 17 (Beefy Miracle) /dev/sda1 mounted on / > ls /export file2.txt file3.txt file4.txt > #======================# [Test-2] -------- + Base file = raw; rest of all backing chain files are qcow2 - [base] <-- [snap-1] <-- [snap-2] <-- [snap3] <-- [active-layer] Flatten the above chain to: (resulting in invalidating snap1, snap2) - [base] <--- [snap-3] <--- [active-layer] - Before taking snap1, do : #mkdir /export ; touch /export/file1.txt ; echo foo > /export/file1.txt - Now take snap1 ----------- [root@moon qemu]# virsh snapshot-create-as test-f17base snap1 snap1-of-test-f17base-desc --disk-only --diskspec vda,snapshot=external,file=/var/lib/libvirt/images/snap1-of-test-f17base.qcow2 --atomic Domain snapshot snap1 created [root@moon qemu]# ----------- - Before taking snap2, do : touch /export/file2.txt ; echo foo > file2.txt - Now take snap2 ----------- [root@moon qemu]# virsh snapshot-create-as test-f17base snap2 snap2-of-test-f17base-desc --disk-only --diskspec vda,snapshot=external,file=/var/lib/libvirt/images/snap2-of-test-f17base.qcow2 --atomic Domain snapshot snap2 created [root@moon qemu]# ----------- - Before taking snap3, do : touch /export/file3.txt ; echo foo > file3.txt - Now take snap3 ----------- [root@moon qemu]# virsh snapshot-create-as test-f17base snap3 snap3-of-test-f17base-desc --disk-only --diskspec vda,snapshot=external,file=/var/lib/libvirt/images/snap3-of-test-f17base.qcow2 --atomic Domain snapshot snap2 created [root@moon qemu]# ----------- - Before taking snap4, do : touch /export/file4.txt ; echo foo > file4.txt - Now take snap4 ----------- [root@moon qemu]# virsh snapshot-create-as test-f17base snap4 snap4-of-test-f17base-desc --disk-only --diskspec vda,snapshot=external,file=/var/lib/libvirt/images/snap4-of-test-f17base.qcow2 --atomic Domain snapshot snap2 created [root@moon qemu]# ----------- Now, the backing chain is [base] <-- [snap-1] <-- [snap-2] <-- [snap3] <-- [snap4-active-layer] Let's do a qemu-img info 'before' block-commit: ----------- [root@moon images]# qemu-img info /export/vmimgs2/test-f17base.img image: /export/vmimgs2/test-f17base.img file format: raw virtual size: 1.0G (1073741824 bytes) disk size: 607M [root@moon images]# ----------- [root@moon qemu]# qemu-img info /var/lib/libvirt/images/snap1-of-test-f17base.qcow2 image: /var/lib/libvirt/images/snap1-of-test-f17base.qcow2 file format: qcow2 virtual size: 1.0G (1073741824 bytes) disk size: 456K cluster_size: 65536 backing file: /export/vmimgs2/test-f17base.img [root@moon qemu]# [root@moon qemu]# qemu-img info /var/lib/libvirt/images/snap2-of-test-f17base.qcow2 image: /var/lib/libvirt/images/snap2-of-test-f17base.qcow2 file format: qcow2 virtual size: 1.0G (1073741824 bytes) disk size: 776K cluster_size: 65536 backing file: /var/lib/libvirt/images/snap1-of-test-f17base.qcow2 [root@moon qemu]# [root@moon qemu]# qemu-img info /var/lib/libvirt/images/snap3-of-test-f17base.qcow2 image: /var/lib/libvirt/images/snap3-of-test-f17base.qcow2 file format: qcow2 virtual size: 1.0G (1073741824 bytes) disk size: 456K cluster_size: 65536 backing file: /var/lib/libvirt/images/snap2-of-test-f17base.qcow2 [root@moon qemu]# qemu-img info /var/lib/libvirt/images/snap4-of-test-f17base.qcow2 image: /var/lib/libvirt/images/snap4-of-test-f17base.qcow2 file format: qcow2 virtual size: 1.0G (1073741824 bytes) disk size: 840K cluster_size: 65536 backing file: /var/lib/libvirt/images/snap3-of-test-f17base.qcow2 [root@moon qemu]# ----------- Now, let's do a blockcommit: So that, [base] <-- [snap-1] <-- [snap-2] <-- [snap3] <-- [active-layer] becomes [base] <--- [snap-1] <--- [active-layer] (where data from snap2 & snap3 are committed into 'snap1' and thus, rightfully invalidating snap2 & snap3) ==> list files of snap1 BEFORE blockcommit <== ----------------------------------------- [kashyap@moon images]$ guestfish --ro -i -a /var/lib/libvirt/images/snap1-of-test-f17base.qcow2 ls /export file1.txt file2.txt [kashyap@moon images]$ [kashyap@moon images]$ guestfish --ro -i -a /var/lib/libvirt/images/snap2-of-test-f17base.qcow2 ls /export file1.txt file2.txt file3.txt [kashyap@moon images]$ guestfish --ro -i -a /var/lib/libvirt/images/snap3-of-test-f17base.qcow2 ls /export file1.txt file2.txt file3.txt file4.txt ----------------------------------------- (NEGATIVE-TEST) Tested while the guest is 'offline' ---------------------------------- [root@moon qemu]# virsh blockcommit --domain test-f17base vda --wait --base /var/lib/libvirt/images/snap1-of-test-f17-base.qcow2 --top /var/lib/libvirt/images/snap3-of-test-f17-base.qcow2 --verbose error: Requested operation is not valid: domain is not running ---------------------------------- (NEGATIVE-TEST) Give an incorrect file path for base/top(and both incorrect) ---------------------------------- [root@moon qemu]# virsh blockcommit --domain test-f17base vda --wait --base /var/lib/libvirt/images/snap1-of-test-f17base.qcow2 --top /var/lib/libvirt/images/snap3-of--f17base.qcow2 --verbose error: internal error unable to execute QEMU command 'block-commit': Top image file /var/lib/libvirt/images/snap3-of--f17base.qcow2 not found [root@moon qemu]# [root@moon qemu]# virsh blockcommit --domain test-f17base vda --wait --base /var/lib/libvirt/images/snap1-of--f17base.qcow2 --top /var/lib/libvirt/images/snap3-of-test-f17base.qcow2 --verbose error: internal error unable to execute QEMU command 'block-commit': Base '/var/lib/libvirt/images/snap1-of--f17base.qcow2' not found [root@moon qemu]# [root@moon qemu]# virsh blockcommit --domain test-f17base vda --wait --base /var/lib/libvirt/images/snap1-of--f17base.qcow2 --top /var/lib/libvirt/images/snap3-of--f17base.qcow2 --verbose error: internal error unable to execute QEMU command 'block-commit': Base '/var/lib/libvirt/images/snap1-of--f17base.qcow2' not found [root@moon qemu]# ---------------------------------- (NEGATIVE-TEST) Give --base & --top values out of order: ---------------------------------- [root@moon qemu]# virsh blockcommit --domain test-f17base vda --wait --base /var/lib/libvirt/images/snap3-of-test-f17base.qcow2 --top /var/lib/libvirt/images/snap1-of-test-f17base.qcow2 --verbose error: internal error unable to execute QEMU command 'block-commit': Base '/var/lib/libvirt/images/snap3-of-test-f17base.qcow2' not found [root@moon qemu]# ---------------------------------- Start the guest & do the 'blockcommit' operation when the guest is running: ---------------------------------- # virsh start test-f17base ---------------------------------- [root@moon qemu]# virsh blockcommit --domain test-f17base vda --wait --base /var/lib/libvirt/images/snap1-of-test-f17base.qcow2 --top /var/lib/ libvirt/images/snap3-of-test-f17base.qcow2 --verbose Block Commit: [100 %] Commit complete [root@moon qemu]# ---------------------------------- ==> list files of snap1 AFTER succesful blockcommit <== ---------------------------------- [kashyap@moon images]$ guestfish --ro -i -a /var/lib/libvirt/images/snap1-of-test-f17base.qcow2 ls /export file1.txt file2.txt file3.txt file4.txt [kashyap@moon images]$ ---------------------------------- It can now be noticed that snap4's backing file pointed ot snap1 ---------------------------------- [root@moon qemu]# qemu-img info /var/lib/libvirt/images/snap4-of-test-f17base.qcow2 image: /var/lib/libvirt/images/snap4-of-test-f17base.qcow2 file format: qcow2 virtual size: 1.0G (1073741824 bytes) disk size: 2.3M cluster_size: 65536 backing file: /var/lib/libvirt/images/snap1-of-test-f17base.qcow2 [root@moon qemu]# [root@moon qemu]# qemu-img info /var/lib/libvirt/images/snap1-of-test-f17base.qcow2image: /var/lib/libvirt/images/snap1-of-test-f17base.qcow2 file format: qcow2 virtual size: 1.0G (1073741824 bytes) disk size: 968K cluster_size: 65536 backing file: /export/vmimgs2/test-f17base.img [root@moon qemu]# ---------------------------------- Now, the resultant chain is reduced to: [base] <--- [snap-1] <--- [active-layer] And, we're still able to login to the machine: ---------------------------------- [root@moon qemu]# virsh console test-f17base Connected to domain test-f17base Escape character is ^] Fedora release 17 (Beefy Miracle) Kernel 3.3.4-5.fc17.x86_64 on an x86_64 (ttyS0) dhcp201-148 login: root Password: Last login: Sun Oct 7 16:06:43 on ttyS0 [root@dhcp201-148 ~]# ----------------------------------