3 # Test compressed write to a qcow2 image at an offset above 4 GB
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 echo "QA output created by $seq"
24 status
=1 # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
32 # get standard environment, filters and checks
36 # This is a qcow2 regression test
40 # External data files do not support compression;
41 # We need an exact cluster size (2M) and refcount width (2) so we can
42 # get this test quickly over with; and this in turn require
44 _unsupported_imgopts data_file cluster_size refcount_bits
'compat=0.10'
46 # The idea is: Create an empty file, mark the first 4 GB as used, then
47 # do a compressed write that thus must be put beyond 4 GB.
48 # (This used to fail because the compressed sector mask was just a
49 # 32 bit mask, so qemu-img check will count a cluster before 4 GB as
52 # We would like to use refcount_bits=1 here, but then qemu-img check
53 # will throw an error when trying to count a cluster as referenced
55 _make_test_img
-o cluster_size
=2M
,refcount_bits
=2 64M
57 reft_offs
=$
(peek_file_be
"$TEST_IMG" 48 8)
58 refb_offs
=$
(peek_file_be
"$TEST_IMG" $reft_offs 8)
60 # We want to cover 4 GB, those are 2048 clusters, equivalent to
62 truncate
-s 4G
"$TEST_IMG"
63 for ((in_refb_offs
= 0; in_refb_offs
< 512; in_refb_offs
+= 8)); do
64 poke_file
"$TEST_IMG" $
((refb_offs
+ in_refb_offs
)) \
65 '\x55\x55\x55\x55\x55\x55\x55\x55'
68 $QEMU_IO -c 'write -c -P 42 0 2M' "$TEST_IMG" | _filter_qemu_io
73 # This should only print the leaked clusters in the first 4 GB
74 _check_test_img |
grep -v '^Leaked cluster '