test qemu-img rebase
[qemu-iotests/stefanha.git] / 024
blob3cad2879c9d67253622a64dc681d57139467dd95
1 #!/bin/sh
3 # Rebasing COW images
5 # Copyright (C) 2009 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # creator
22 owner=kwolf@redhat.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1 # failure is the default!
31 _cleanup()
33 _cleanup_test_img
34 rm -f $TEST_DIR/t.$IMGFMT.base_old
35 rm -f $TEST_DIR/t.$IMGFMT.base_new
37 trap "_cleanup; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
40 . ./common.rc
41 . ./common.filter
42 . ./common.pattern
44 # Currently only qcow2 supports rebasing
45 _supported_fmt qcow2
46 _supported_os Linux
48 CLUSTER_SIZE=65536
50 # Cluster allocations to be tested:
52 # Backing (old) 11 -- 11 -- 11 -- 11 --
53 # Backing (new) 22 22 -- -- 22 22 -- --
54 # COW image 33 33 33 33 -- -- -- --
56 echo "Creating backing file"
57 echo
59 _make_test_img 1G
60 io_pattern writev $((-2 * CLUSTER_SIZE)) $CLUSTER_SIZE $((2 * CLUSTER_SIZE)) 4 0x11
61 mv $TEST_IMG $TEST_IMG.base_old
63 echo "Creating new backing file"
64 echo
66 _make_test_img 1G
67 io_pattern writev $((-4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 2 0x22
68 mv $TEST_IMG $TEST_IMG.base_new
70 echo "Creating COW image"
71 echo
73 _make_test_img -b $TEST_IMG.base_old 1G
74 io_pattern writev 0 $((4 * CLUSTER_SIZE)) 0 1 0x33
76 echo "Read before the rebase to make sure everything is set up correctly"
77 echo
78 io_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
79 io_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
80 io_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
81 io_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
82 io_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
83 io_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
84 io_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
85 io_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
87 echo
88 echo Rebase and test again
89 echo
90 $QEMU_IMG rebase -b $TEST_IMG.base_new $TEST_IMG
91 io_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
92 io_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
93 io_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
94 io_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
95 io_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
96 io_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
97 io_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
98 io_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
101 # success, all done
102 echo "*** done"
103 rm -f $seq.full
104 status=0