python/qemu: make 'args' style arguments immutable
[qemu.git] / tests / qemu-iotests / 179
blob11a20cb1bfa87928d07bf9808c2da2c9fc3c442c
1 #!/usr/bin/env bash
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/>.
21 # creator
22 owner=eblake@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_DIR/blkdebug.conf"
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
40 _supported_fmt qcow2
41 _supported_proto file
42 _supported_os Linux
44 # v2 images can't mark clusters as zero
45 _unsupported_imgopts compat=0.10
47 echo
48 echo '=== Testing write zeroes with unmap ==='
49 echo
51 TEST_IMG="$TEST_IMG.base" _make_test_img 64M
52 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
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
106 _check_test_img
108 echo
109 echo '=== Testing cache optimization ==='
110 echo
112 BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG.base"
114 cat > "$TEST_DIR/blkdebug.conf" <<EOF
115 [inject-error]
116 event = "l2_update"
117 errno = "5"
118 immediately = "on"
119 once = "off"
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
128 # success, all done
129 echo '*** done'
130 status=0