build: Link user-only with crypto random number objects
[qemu/ar7.git] / tests / qemu-iotests / 244
blob13978f93d2449e32847c5e08d8656132902a2f58
1 #!/usr/bin/env bash
3 # Test qcow2 with external data files
5 # Copyright (C) 2019 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 status=1 # failure is the default!
29 _cleanup()
31 _cleanup_test_img
32 rm -f $TEST_IMG.data
33 rm -f $TEST_IMG.src
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
41 _supported_fmt qcow2
42 _supported_proto file
43 _supported_os Linux
45 echo
46 echo "=== Create and open image with external data file ==="
47 echo
49 echo "With data file name in the image:"
50 IMGOPTS="data_file=$TEST_IMG.data" _make_test_img 64M
51 _check_test_img
53 $QEMU_IO -c "open $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
54 $QEMU_IO -c "open -odata-file.filename=$TEST_IMG.data $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
55 $QEMU_IO -c "open -odata-file.filename=inexistent $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
57 echo
58 echo "Data file required, but without data file name in the image:"
59 $QEMU_IMG amend -odata_file= $TEST_IMG
61 $QEMU_IO -c "open $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
62 $QEMU_IO -c "open -odata-file.filename=$TEST_IMG.data $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
63 $QEMU_IO -c "open -odata-file.filename=inexistent $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
65 echo
66 echo "Setting data-file for an image with internal data:"
67 _make_test_img 64M
69 $QEMU_IO -c "open -odata-file.filename=$TEST_IMG.data $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
70 $QEMU_IO -c "open -odata-file.filename=inexistent $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
72 echo
73 echo "=== Conflicting features ==="
74 echo
76 echo "Convert to compressed target with data file:"
77 TEST_IMG="$TEST_IMG.src" _make_test_img 64M
79 $QEMU_IO -c 'write -P 0x11 0 1M' \
80 -f $IMGFMT "$TEST_IMG.src" |
81 _filter_qemu_io
83 $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c -odata_file="$TEST_IMG.data" \
84 "$TEST_IMG.src" "$TEST_IMG"
86 echo
87 echo "Convert uncompressed, then write compressed data manually:"
88 $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -odata_file="$TEST_IMG.data" \
89 "$TEST_IMG.src" "$TEST_IMG"
90 $QEMU_IMG compare "$TEST_IMG.src" "$TEST_IMG"
92 $QEMU_IO -c 'write -c -P 0x22 0 1M' \
93 -f $IMGFMT "$TEST_IMG" |
94 _filter_qemu_io
95 _check_test_img
97 echo
98 echo "Take an internal snapshot:"
100 $QEMU_IMG snapshot -c test "$TEST_IMG"
101 _check_test_img
103 echo
104 echo "=== Standalone image with external data file (efficient) ==="
105 echo
107 IMGOPTS="data_file=$TEST_IMG.data" _make_test_img 64M
109 echo -n "qcow2 file size before I/O: "
110 du -b $TEST_IMG | cut -f1
112 # Create image with the following layout
113 # 0-1 MB: Unallocated
114 # 1-2 MB: Written (pattern 0x11)
115 # 2-3 MB: Discarded
116 # 3-4 MB: Zero write over discarded space
117 # 4-5 MB: Zero write over written space
118 # 5-6 MB: Zero write over unallocated space
120 echo
121 $QEMU_IO -c 'write -P 0x11 1M 4M' \
122 -c 'discard 2M 2M' \
123 -c 'write -z 3M 3M' \
124 -f $IMGFMT "$TEST_IMG" |
125 _filter_qemu_io
126 _check_test_img
128 echo
129 $QEMU_IMG map --output=json "$TEST_IMG"
131 echo
132 $QEMU_IO -c 'read -P 0 0 1M' \
133 -c 'read -P 0x11 1M 1M' \
134 -c 'read -P 0 2M 4M' \
135 -f $IMGFMT "$TEST_IMG" |
136 _filter_qemu_io
138 # Zero clusters are only marked as such in the qcow2 metadata, but contain
139 # stale data in the external data file
140 echo
141 $QEMU_IO -c 'read -P 0 0 1M' \
142 -c 'read -P 0x11 1M 1M' \
143 -c 'read -P 0 2M 2M' \
144 -c 'read -P 0x11 4M 1M' \
145 -c 'read -P 0 5M 1M' \
146 -f raw "$TEST_IMG.data" |
147 _filter_qemu_io
150 echo -n "qcow2 file size after I/O: "
151 du -b $TEST_IMG | cut -f1
153 echo
154 echo "=== Standalone image with external data file (valid raw) ==="
155 echo
157 IMGOPTS="data_file=$TEST_IMG.data,data_file_raw=on" _make_test_img 64M
159 echo -n "qcow2 file size before I/O: "
160 du -b $TEST_IMG | cut -f1
162 echo
163 $QEMU_IO -c 'write -P 0x11 1M 4M' \
164 -c 'discard 2M 2M' \
165 -c 'write -z 3M 3M' \
166 -f $IMGFMT "$TEST_IMG" |
167 _filter_qemu_io
168 _check_test_img
170 echo
171 $QEMU_IMG map --output=json "$TEST_IMG"
173 echo
174 $QEMU_IO -c 'read -P 0 0 1M' \
175 -c 'read -P 0x11 1M 1M' \
176 -c 'read -P 0 2M 4M' \
177 -f $IMGFMT "$TEST_IMG" |
178 _filter_qemu_io
180 echo
181 $QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.data"
183 echo -n "qcow2 file size after I/O: "
184 du -b $TEST_IMG | cut -f1
186 echo
187 echo "=== bdrv_co_block_status test for file and offset=0 ==="
188 echo
190 IMGOPTS="data_file=$TEST_IMG.data" _make_test_img 64M
192 $QEMU_IO -c 'write -P 0x11 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
193 $QEMU_IO -c 'read -P 0x11 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
194 $QEMU_IMG map --output=human "$TEST_IMG" | _filter_testdir
195 $QEMU_IMG map --output=json "$TEST_IMG"
197 # success, all done
198 echo "*** done"
199 rm -f $seq.full
200 status=0