3 # Test case for write zeroes with unmap
5 # Copyright (C) 2017 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
=eblake@redhat.com
25 echo "QA output created by $seq"
28 status
=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
44 # v2 images can't mark clusters as zero
45 _unsupported_imgopts compat
=0.10
48 echo '=== Testing write zeroes with unmap ==='
51 TEST_IMG
="$TEST_IMG.base" _make_test_img
64M
52 _make_test_img
-b "$TEST_IMG.base"
54 # Offsets chosen at or near 2M boundaries so test works at all cluster sizes
55 # 8k and larger (smaller clusters fail due to non-contiguous allocations)
57 # Aligned writes to unallocated cluster should not allocate mapping, but must
58 # mark cluster as zero, whether or not unmap was requested
59 $QEMU_IO -c "write -z -u 2M 2M" "$TEST_IMG.base" | _filter_qemu_io
60 $QEMU_IO -c "write -z 6M 2M" "$TEST_IMG.base" | _filter_qemu_io
61 $QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
62 $QEMU_IMG map
--output=json
"$TEST_IMG.base" | _filter_qemu_img_map
64 # Unaligned writes need not allocate mapping if the cluster already reads
65 # as zero, but must mark cluster as zero, whether or not unmap was requested
66 $QEMU_IO -c "write -z -u 10485761 2097150" "$TEST_IMG.base" | _filter_qemu_io
67 $QEMU_IO -c "write -z 14680065 2097150" "$TEST_IMG.base" | _filter_qemu_io
68 $QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
69 $QEMU_IMG map
--output=json
"$TEST_IMG.base" | _filter_qemu_img_map
71 # Requesting unmap of normal data must deallocate; omitting unmap should
72 # preserve the mapping
73 $QEMU_IO -c "write 18M 14M" "$TEST_IMG.base" | _filter_qemu_io
74 $QEMU_IO -c "write -z -u 20M 2M" "$TEST_IMG.base" | _filter_qemu_io
75 $QEMU_IO -c "write -z 24M 6M" "$TEST_IMG.base" | _filter_qemu_io
76 $QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
77 $QEMU_IMG map
--output=json
"$TEST_IMG.base" | _filter_qemu_img_map
79 # Likewise when writing on already-mapped zero data
80 $QEMU_IO -c "write -z -u 26M 2M" "$TEST_IMG.base" | _filter_qemu_io
81 $QEMU_IO -c "write -z 28M 2M" "$TEST_IMG.base" | _filter_qemu_io
82 $QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
83 $QEMU_IMG map
--output=json
"$TEST_IMG.base" | _filter_qemu_img_map
85 # Writing on unmapped zeroes does not allocate
86 $QEMU_IO -c "write -z 32M 8M" "$TEST_IMG.base" | _filter_qemu_io
87 $QEMU_IO -c "write -z -u 34M 2M" "$TEST_IMG.base" | _filter_qemu_io
88 $QEMU_IO -c "write -z 36M 2M" "$TEST_IMG.base" | _filter_qemu_io
89 $QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
90 $QEMU_IMG map
--output=json
"$TEST_IMG.base" | _filter_qemu_img_map
92 # Writing zero overrides a backing file, regardless of backing cluster type
93 $QEMU_IO -c "write -z 40M 8M" "$TEST_IMG.base" | _filter_qemu_io
94 $QEMU_IO -c "write 48M 8M" "$TEST_IMG.base" | _filter_qemu_io
95 $QEMU_IO -c "write -z -u 42M 2M" "$TEST_IMG" | _filter_qemu_io
96 $QEMU_IO -c "write -z 44M 2M" "$TEST_IMG" | _filter_qemu_io
97 $QEMU_IO -c "write -z -u 50M 2M" "$TEST_IMG" | _filter_qemu_io
98 $QEMU_IO -c "write -z 52M 2M" "$TEST_IMG" | _filter_qemu_io
99 $QEMU_IO -c "write -z -u 58M 2M" "$TEST_IMG" | _filter_qemu_io
100 $QEMU_IO -c "write -z 60M 2M" "$TEST_IMG" | _filter_qemu_io
101 $QEMU_IO -c "map" "$TEST_IMG" | _filter_qemu_io
102 $QEMU_IMG map
--output=json
"$TEST_IMG" | _filter_qemu_img_map
104 # Final check that mappings are correct and images are still sane
105 TEST_IMG
="$TEST_IMG.base" _check_test_img
109 echo '=== Testing cache optimization ==='
112 BLKDBG_TEST_IMG
="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG.base"
114 cat > "$TEST_DIR/blkdebug.conf" <<EOF
122 # None of the following writes should trigger an L2 update, because the
123 # cluster already reads as zero, and we don't have to change allocation
124 $QEMU_IO -c "w -z -u 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
125 $QEMU_IO -c "w -z 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
126 $QEMU_IO -c "w -z 28M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io