OSDN Git Service

Merge tag 'pull-halloween-omnibus-311023-2' of https://gitlab.com/stsquad/qemu into...
[qmiga/qemu.git] / tests / qemu-iotests / 020
1 #!/usr/bin/env bash
2 # group: rw backing auto quick
3 #
4 # Commit changes to backing file
5 #
6 # Copyright (C) 2009 Red Hat, Inc.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21
22 # creator
23 owner=kwolf@redhat.com
24
25 seq=`basename $0`
26 echo "QA output created by $seq"
27
28 status=1        # failure is the default!
29
30 _cleanup()
31 {
32     _cleanup_test_img
33     _rm_test_img "$TEST_IMG.base"
34     _rm_test_img "$TEST_IMG.orig"
35
36     _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT.base"
37     _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT.mid"
38     _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT"
39     rmdir "$TEST_DIR/subdir" &> /dev/null
40 }
41 trap "_cleanup; exit \$status" 0 1 2 3 15
42
43 # get standard environment, filters and checks
44 . ./common.rc
45 . ./common.filter
46 . ./common.pattern
47
48 # Any format supporting backing files
49 _supported_fmt qcow qcow2 vmdk qed
50 _supported_proto file
51 _unsupported_imgopts "subformat=monolithicFlat" \
52                      "subformat=twoGbMaxExtentFlat" \
53                      "subformat=twoGbMaxExtentSparse" \
54                      "subformat=streamOptimized"
55
56 TEST_OFFSETS="0 4294967296"
57
58 TEST_IMG_SAVE="$TEST_IMG"
59 TEST_IMG="$TEST_IMG.base"
60
61 _make_test_img 6G
62
63 echo "Filling base image"
64 echo
65
66 for offset in $TEST_OFFSETS; do
67     # Some clusters with alternating backing file/image file reads
68     io writev $(( offset )) 512 1024 64
69
70     # Complete backing clusters
71     io writev $(( offset  + 64 * 1024))  65536 65536 1
72 done
73 _check_test_img
74
75 echo "Creating test image with backing file"
76 echo
77
78 TEST_IMG="$TEST_IMG_SAVE"
79 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT 6G
80
81 echo "Filling test image"
82 echo
83
84 for offset in $TEST_OFFSETS; do
85     # Some clusters with alternating backing file/image file reads
86     io writev $(( offset + 512 )) 512 1024 64
87
88     # Complete test image clusters
89     io writev $(( offset + 64 * 1024 + 65536))  65536 65536 1
90 done
91 _check_test_img
92
93 $QEMU_IMG commit "$TEST_IMG"
94 TEST_IMG="$TEST_IMG.base"
95
96 echo "Reading from the backing file"
97 echo
98
99 for offset in $TEST_OFFSETS; do
100     # Some clusters with alternating backing file/image file reads
101     io readv $(( offset )) 512 1024 64
102     io readv $(( offset + 512 )) 512 1024 64
103
104     # Complete test image clusters
105     io readv $(( offset  + 64 * 1024))  65536 65536 1
106     io readv $(( offset + 64 * 1024 + 65536))  65536 65536 1
107
108     # Empty sectors
109     io_zero readv $(( offset + 64 * 1024 + 65536 * 4 )) 65536 65536 1
110 done
111 _check_test_img
112 _cleanup
113 TEST_IMG=$TEST_IMG_SAVE
114
115 echo
116 echo 'Testing failing commit'
117 echo
118
119 TEST_IMG="$TEST_IMG.base" _make_test_img 1M
120
121 # Create an image with a null backing file to which committing will fail (with
122 # ENOSPC so we can distinguish the result from some generic EIO which may be
123 # generated anywhere in the block layer)
124 backing="json:{'driver': '$IMGFMT',
125                'file': {
126                    'driver': 'blkdebug',
127                    'inject-error': [{
128                        'event': 'write_aio',
129                        'errno': 28,
130                        'once': true
131                    }],
132                    'image': {
133                        'driver': 'file',
134                        'filename': '$TEST_IMG.base'
135                    }}}"
136
137 # Filter out newlines and collapse spaces
138 backing=$(echo "$backing" | tr -d '\n' | tr -s ' ')
139
140 _make_test_img -b "$backing" -F $IMGFMT
141
142 # Just write anything so committing will not be a no-op
143 $QEMU_IO -c 'writev 0 64k' "$TEST_IMG" | _filter_qemu_io
144
145 $QEMU_IMG commit "$TEST_IMG"
146 _cleanup
147
148
149 echo
150 echo 'Testing commit in sub-directory with relative filenames'
151 echo
152
153 pushd "$TEST_DIR" > /dev/null
154
155 mkdir subdir
156
157 TEST_IMG="subdir/t.$IMGFMT.base" _make_test_img 1M
158 TEST_IMG="subdir/t.$IMGFMT.mid" _make_test_img -b "t.$IMGFMT.base" -F $IMGFMT
159 TEST_IMG="subdir/t.$IMGFMT" _make_test_img -b "t.$IMGFMT.mid" -F $IMGFMT
160
161 # Should work
162 $QEMU_IMG commit -b "t.$IMGFMT.mid" "subdir/t.$IMGFMT"
163
164 # Might theoretically work, but does not in practice (we have to
165 # decide between this and the above; and since we always represent
166 # backing file names as relative to the overlay, we go for the above)
167 $QEMU_IMG commit -b "subdir/t.$IMGFMT.mid" "subdir/t.$IMGFMT" 2>&1 | \
168     _filter_imgfmt
169
170 # This should work as well
171 $QEMU_IMG commit -b "$TEST_DIR/subdir/t.$IMGFMT.mid" "subdir/t.$IMGFMT"
172
173 popd > /dev/null
174
175 # Now let's try with just absolute filenames
176 # (This will not work with external data files, though, because when
177 # using relative paths for those, qemu will always resolve them
178 # relative to its CWD.  Therefore, it cannot find those data files now
179 # that we left $TEST_DIR.)
180 if _get_data_file '' > /dev/null; then
181     echo 'Image committed.' # Skip test
182 else
183     $QEMU_IMG commit -b "$TEST_DIR/subdir/t.$IMGFMT.mid" \
184         "$TEST_DIR/subdir/t.$IMGFMT"
185 fi
186
187 # success, all done
188 echo "*** done"
189 rm -f $seq.full
190 status=0