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