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/>.
22 owner
=kwolf@redhat.com
25 echo "QA output created by $seq"
27 status
=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
46 echo "=== Create and open image with external data file ==="
49 echo "With data file name in the image:"
50 IMGOPTS
="data_file=$TEST_IMG.data" _make_test_img
64M
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
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
66 echo "Setting data-file for an image with internal data:"
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
73 echo "=== Conflicting features ==="
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" |
83 $QEMU_IMG convert
-f $IMGFMT -O $IMGFMT -c -odata_file="$TEST_IMG.data" \
84 "$TEST_IMG.src" "$TEST_IMG"
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" |
98 echo "Take an internal snapshot:"
100 $QEMU_IMG snapshot
-c test "$TEST_IMG"
104 echo "=== Standalone image with external data file (efficient) ==="
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)
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
121 $QEMU_IO -c 'write -P 0x11 1M 4M' \
123 -c 'write -z 3M 3M' \
124 -f $IMGFMT "$TEST_IMG" |
129 $QEMU_IMG map
--output=json
"$TEST_IMG"
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" |
138 # Zero clusters are only marked as such in the qcow2 metadata, but contain
139 # stale data in the external data file
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" |
150 echo -n "qcow2 file size after I/O: "
151 du
-b $TEST_IMG | cut
-f1
154 echo "=== Standalone image with external data file (valid raw) ==="
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
163 $QEMU_IO -c 'write -P 0x11 1M 4M' \
165 -c 'write -z 3M 3M' \
166 -f $IMGFMT "$TEST_IMG" |
171 $QEMU_IMG map
--output=json
"$TEST_IMG"
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" |
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
187 echo "=== bdrv_co_block_status test for file and offset=0 ==="
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"