exec/gdbstub: Make gdb_exit() / gdb_set_stop_cpu() target agnostic
[qemu/rayw.git] / tests / qemu-iotests / 179
blob09447b561030561e3a49bff07ca23dad3f7d8b49
1 #!/usr/bin/env bash
2 # group: rw auto quick
4 # Test case for write zeroes with unmap
6 # Copyright (C) 2017 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # creator
23 owner=eblake@redhat.com
25 seq="$(basename $0)"
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
33 rm -f "$TEST_DIR/blkdebug.conf"
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
41 _supported_fmt qcow2
42 _supported_proto file fuse
43 _supported_os Linux
45 # v2 images can't mark clusters as zero
46 _unsupported_imgopts compat=0.10
48 echo
49 echo '=== Testing write zeroes with unmap ==='
50 echo
52 TEST_IMG="$TEST_IMG.base" _make_test_img 64M
53 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
55 # Offsets chosen at or near 2M boundaries so test works at all cluster sizes
56 # 8k and larger (smaller clusters fail due to non-contiguous allocations)
58 # Aligned writes to unallocated cluster should not allocate mapping, but must
59 # mark cluster as zero, whether or not unmap was requested
60 $QEMU_IO -c "write -z -u 2M 2M" "$TEST_IMG.base" | _filter_qemu_io
61 $QEMU_IO -c "write -z 6M 2M" "$TEST_IMG.base" | _filter_qemu_io
62 $QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
63 $QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
65 # Unaligned writes need not allocate mapping if the cluster already reads
66 # as zero, but must mark cluster as zero, whether or not unmap was requested
67 $QEMU_IO -c "write -z -u 10485761 2097150" "$TEST_IMG.base" | _filter_qemu_io
68 $QEMU_IO -c "write -z 14680065 2097150" "$TEST_IMG.base" | _filter_qemu_io
69 $QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
70 $QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
72 # Requesting unmap of normal data must deallocate; omitting unmap should
73 # preserve the mapping
74 $QEMU_IO -c "write 18M 14M" "$TEST_IMG.base" | _filter_qemu_io
75 $QEMU_IO -c "write -z -u 20M 2M" "$TEST_IMG.base" | _filter_qemu_io
76 $QEMU_IO -c "write -z 24M 6M" "$TEST_IMG.base" | _filter_qemu_io
77 $QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
78 $QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
80 # Likewise when writing on already-mapped zero data
81 $QEMU_IO -c "write -z -u 26M 2M" "$TEST_IMG.base" | _filter_qemu_io
82 $QEMU_IO -c "write -z 28M 2M" "$TEST_IMG.base" | _filter_qemu_io
83 $QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
84 $QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
86 # Writing on unmapped zeroes does not allocate
87 $QEMU_IO -c "write -z 32M 8M" "$TEST_IMG.base" | _filter_qemu_io
88 $QEMU_IO -c "write -z -u 34M 2M" "$TEST_IMG.base" | _filter_qemu_io
89 $QEMU_IO -c "write -z 36M 2M" "$TEST_IMG.base" | _filter_qemu_io
90 $QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
91 $QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
93 # Writing zero overrides a backing file, regardless of backing cluster type
94 $QEMU_IO -c "write -z 40M 8M" "$TEST_IMG.base" | _filter_qemu_io
95 $QEMU_IO -c "write 48M 8M" "$TEST_IMG.base" | _filter_qemu_io
96 $QEMU_IO -c "write -z -u 42M 2M" "$TEST_IMG" | _filter_qemu_io
97 $QEMU_IO -c "write -z 44M 2M" "$TEST_IMG" | _filter_qemu_io
98 $QEMU_IO -c "write -z -u 50M 2M" "$TEST_IMG" | _filter_qemu_io
99 $QEMU_IO -c "write -z 52M 2M" "$TEST_IMG" | _filter_qemu_io
100 $QEMU_IO -c "write -z -u 58M 2M" "$TEST_IMG" | _filter_qemu_io
101 $QEMU_IO -c "write -z 60M 2M" "$TEST_IMG" | _filter_qemu_io
102 $QEMU_IO -c "map" "$TEST_IMG" | _filter_qemu_io
103 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
105 # Final check that mappings are correct and images are still sane
106 TEST_IMG="$TEST_IMG.base" _check_test_img
107 _check_test_img
109 echo
110 echo '=== Testing cache optimization ==='
111 echo
113 BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG.base"
115 cat > "$TEST_DIR/blkdebug.conf" <<EOF
116 [inject-error]
117 event = "l2_update"
118 errno = "5"
119 immediately = "on"
120 once = "off"
123 # None of the following writes should trigger an L2 update, because the
124 # cluster already reads as zero, and we don't have to change allocation
125 $QEMU_IO -c "w -z -u 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
126 $QEMU_IO -c "w -z 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
127 $QEMU_IO -c "w -z 28M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
129 # success, all done
130 echo '*** done'
131 status=0