]> git.proxmox.com Git - mirror_qemu.git/blob - tests/qemu-iotests/220
iotests: Enable fuse for many tests
[mirror_qemu.git] / tests / qemu-iotests / 220
1 #!/usr/bin/env bash
2 #
3 # max limits on compression in huge qcow2 files
4 #
5 # Copyright (C) 2018 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 seq=$(basename $0)
22 echo "QA output created by $seq"
23
24 status=1 # failure is the default!
25
26 _cleanup()
27 {
28 _cleanup_test_img
29 }
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 # get standard environment, filters and checks
33 . ./common.rc
34 . ./common.filter
35 . ./common.pattern
36
37 _supported_fmt qcow2
38 _supported_proto file fuse
39 _supported_os Linux
40 # To use a different refcount width but 16 bits we need compat=1.1,
41 # and external data files do not support compressed clusters.
42 _unsupported_imgopts 'compat=0.10' data_file
43
44 echo "== Creating huge file =="
45
46 # Sanity check: We require a file system that permits the creation
47 # of a HUGE (but very sparse) file. tmpfs works, ext4 does not.
48 _require_large_file 513T
49
50 _make_test_img -o 'cluster_size=2M,refcount_bits=1' 513T
51
52 echo "== Populating refcounts =="
53 # We want an image with 256M refcounts * 2M clusters = 512T referenced.
54 # Each 2M cluster holds 16M refcounts; the refcount table initially uses
55 # 1 refblock, so we need to add 15 more. The refcount table lives at 2M,
56 # first refblock at 4M, L2 at 6M, so our remaining additions start at 8M.
57 # Then, for each refblock, mark it as fully populated.
58 to_hex() {
59 printf %016x\\n $1 | sed 's/\(..\)/\\x\1/g'
60 }
61 truncate --size=38m "$TEST_IMG"
62 entry=$((0x200000))
63 $QEMU_IO_PROG -f raw -c "w -P 0xff 4m 2m" "$TEST_IMG" | _filter_qemu_io
64 for i in {1..15}; do
65 offs=$((0x600000 + i*0x200000))
66 poke_file "$TEST_IMG" $((i*8 + entry)) $(to_hex $offs)
67 $QEMU_IO_PROG -f raw -c "w -P 0xff $offs 2m" "$TEST_IMG" | _filter_qemu_io
68 done
69
70 echo "== Checking file before =="
71 # FIXME: 'qemu-img check' doesn't diagnose refcounts beyond the end of
72 # the file as leaked clusters
73 _check_test_img 2>&1 | sed '/^Leaked cluster/d'
74 stat -c 'image size %s' "$TEST_IMG"
75
76 echo "== Trying to write compressed cluster =="
77 # Given our file size, the next available cluster at 512T lies beyond the
78 # maximum offset that a compressed 2M cluster can reside in
79 $QEMU_IO_PROG -c 'w -c 0 2m' "$TEST_IMG" | _filter_qemu_io
80 # The attempt failed, but ended up allocating a new refblock
81 stat -c 'image size %s' "$TEST_IMG"
82
83 echo "== Writing normal cluster =="
84 # The failed write should not corrupt the image, so a normal write succeeds
85 $QEMU_IO_PROG -c 'w 0 2m' "$TEST_IMG" | _filter_qemu_io
86
87 echo "== Checking file after =="
88 # qemu-img now sees the millions of leaked clusters, thanks to the allocations
89 # at 512T. Undo many of our faked references to speed up the check.
90 $QEMU_IO_PROG -f raw -c "w -z 5m 1m" -c "w -z 8m 30m" "$TEST_IMG" |
91 _filter_qemu_io
92 _check_test_img 2>&1 | sed '/^Leaked cluster/d'
93
94 # success, all done
95 echo "*** done"
96 rm -f $seq.full
97 status=0