3 # Copyright (C) 2011 Red Hat Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # Test that qemu snapshots are really isolating writes from the
20 # underlying disk image. If this test were to fail, you could expect
21 # libguestfs to cause massive disk corruption on live guests.
25 rm -f test1.img test2.img test3.img
27 truncate -s 100M test1.img
28 test1_md5sum="$(md5sum test1.img | awk '{print $1}')"
29 truncate -s 100M test2.img
30 test2_md5sum="$(md5sum test2.img | awk '{print $1}')"
31 qemu-img create -f qcow2 test3.img 100M
32 test3_md5sum="$(md5sum test3.img | awk '{print $1}')"
34 # The vitally important calls are 'add-drive-ro' and
35 # 'add-drive-opts ... readonly:true'.
36 ../fish/guestfish <<'EOF'
37 add-drive-ro test1.img
38 add-drive-opts test2.img format:raw readonly:true
39 add-drive-opts test3.img format:qcow2 readonly:true
42 part-disk /dev/sda mbr
43 part-disk /dev/sdb mbr
44 part-disk /dev/sdc mbr
47 copy-size /dev/sda1 /dev/sdb1 5M
54 mount-options "" /dev/sda1 /a
56 mount-options "" /dev/sdb1 /b
58 mount-options "" /dev/VG/LV /c
60 write /a/test "This is a test"
61 write /b/test "This is a test"
62 write /c/test "This is a test"
64 # Really try hard to force writes to the disk.
70 # Now verify that the original disks have not been touched.
71 function serious_error
75 echo "***** SERIOUS ERROR *****"
76 echo "qemu's snapshot isolation does not appear to be working."
77 echo "Running libguestfs could cause disk corruption on live guests."
79 echo "DO NOT USE libguestfs before you have resolved this problem."
84 if [ "$(md5sum test1.img | awk '{print $1}')" != "$test1_md5sum" ]; then
87 if [ "$(md5sum test2.img | awk '{print $1}')" != "$test2_md5sum" ]; then
90 if [ "$(md5sum test3.img | awk '{print $1}')" != "$test3_md5sum" ]; then
94 rm test1.img test2.img test3.img