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