xref: /qemu/tests/qemu-iotests/033 (revision 325dd915b231801e48f89b38a4bfb89c8956098c)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2ee3a315eSPaolo Bonzini#
3ee3a315eSPaolo Bonzini# Test aligned and misaligned write zeroes operations.
4ee3a315eSPaolo Bonzini#
5ee3a315eSPaolo Bonzini# Copyright (C) 2012 Red Hat, Inc.
6ee3a315eSPaolo Bonzini#
7ee3a315eSPaolo Bonzini# This program is free software; you can redistribute it and/or modify
8ee3a315eSPaolo Bonzini# it under the terms of the GNU General Public License as published by
9ee3a315eSPaolo Bonzini# the Free Software Foundation; either version 2 of the License, or
10ee3a315eSPaolo Bonzini# (at your option) any later version.
11ee3a315eSPaolo Bonzini#
12ee3a315eSPaolo Bonzini# This program is distributed in the hope that it will be useful,
13ee3a315eSPaolo Bonzini# but WITHOUT ANY WARRANTY; without even the implied warranty of
14ee3a315eSPaolo Bonzini# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15ee3a315eSPaolo Bonzini# GNU General Public License for more details.
16ee3a315eSPaolo Bonzini#
17ee3a315eSPaolo Bonzini# You should have received a copy of the GNU General Public License
18ee3a315eSPaolo Bonzini# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19ee3a315eSPaolo Bonzini#
20ee3a315eSPaolo Bonzini
21ee3a315eSPaolo Bonzini# creator
22ee3a315eSPaolo Bonziniowner=pbonzini@redhat.com
23ee3a315eSPaolo Bonzini
24ee3a315eSPaolo Bonziniseq=`basename $0`
25ee3a315eSPaolo Bonziniecho "QA output created by $seq"
26ee3a315eSPaolo Bonzini
27ee3a315eSPaolo Bonzinistatus=1	# failure is the default!
28ee3a315eSPaolo Bonzini
29ee3a315eSPaolo Bonzini_cleanup()
30ee3a315eSPaolo Bonzini{
31ee3a315eSPaolo Bonzini	_cleanup_test_img
32ee3a315eSPaolo Bonzini}
33ee3a315eSPaolo Bonzinitrap "_cleanup; exit \$status" 0 1 2 3 15
34ee3a315eSPaolo Bonzini
35ee3a315eSPaolo Bonzini# get standard environment, filters and checks
36ee3a315eSPaolo Bonzini. ./common.rc
37ee3a315eSPaolo Bonzini. ./common.filter
38ee3a315eSPaolo Bonzini
39ee3a315eSPaolo Bonzini_supported_fmt generic
40ee3a315eSPaolo Bonzini_supported_proto generic
41*325dd915SMax Reitz_unsupported_imgopts "subformat=streamOptimized"
42ee3a315eSPaolo Bonzini
43ee3a315eSPaolo Bonzini
44ee3a315eSPaolo Bonzinisize=128M
45ee3a315eSPaolo Bonzini_make_test_img $size
46ee3a315eSPaolo Bonzini
4761815d6eSFam Zhengdo_test()
4861815d6eSFam Zheng{
4961815d6eSFam Zheng	local align=$1
5061815d6eSFam Zheng	local iocmd=$2
5161815d6eSFam Zheng	local img=$3
5213a1d4a7SDaniel P. Berrange	if [ "$IMGOPTSSYNTAX" = "true" ]
5313a1d4a7SDaniel P. Berrange	then
5413a1d4a7SDaniel P. Berrange	    IO_OPEN_ARG="$img"
5513a1d4a7SDaniel P. Berrange	    IO_EXTRA_ARGS="--image-opts"
5613a1d4a7SDaniel P. Berrange	else
5713a1d4a7SDaniel P. Berrange	    IO_OPEN_ARG="-o driver=$IMGFMT,file.align=$align blkdebug::$img"
5813a1d4a7SDaniel P. Berrange	    IO_EXTRA_ARGS=""
5913a1d4a7SDaniel P. Berrange	fi
6061815d6eSFam Zheng	{
6113a1d4a7SDaniel P. Berrange		echo "open $IO_OPEN_ARG"
6261815d6eSFam Zheng		echo $iocmd
6313a1d4a7SDaniel P. Berrange	} | $QEMU_IO $IO_EXTRA_ARGS
6461815d6eSFam Zheng}
6561815d6eSFam Zheng
66afe35cdeSAnton Nefedovecho
67afe35cdeSAnton Nefedovecho "=== Test aligned and misaligned write zeroes operations ==="
68afe35cdeSAnton Nefedov
697fa84cd8SKevin Wolffor write_zero_cmd in "write -z" "aio_write -z"; do
7061815d6eSFam Zhengfor align in 512 4k; do
71ee3a315eSPaolo Bonzini	echo
72ee3a315eSPaolo Bonzini	echo "== preparing image =="
7361815d6eSFam Zheng	do_test $align "write -P 0xa 0x200 0x400" "$TEST_IMG" | _filter_qemu_io
7461815d6eSFam Zheng	do_test $align "write -P 0xa 0x20000 0x600" "$TEST_IMG" | _filter_qemu_io
757fa84cd8SKevin Wolf	do_test $align "$write_zero_cmd 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
76ee3a315eSPaolo Bonzini
77ee3a315eSPaolo Bonzini	echo
78ee3a315eSPaolo Bonzini	echo "== verifying patterns (1) =="
7961815d6eSFam Zheng	do_test $align "read -P 0xa 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
8061815d6eSFam Zheng	do_test $align "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
8161815d6eSFam Zheng	do_test $align "read -P 0xa 0x20400 0x200" "$TEST_IMG" | _filter_qemu_io
82ee3a315eSPaolo Bonzini
83ee3a315eSPaolo Bonzini	echo
84ee3a315eSPaolo Bonzini	echo "== rewriting zeroes =="
8561815d6eSFam Zheng	do_test $align "write -P 0xb 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
867fa84cd8SKevin Wolf	do_test $align "$write_zero_cmd 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
87ee3a315eSPaolo Bonzini
88ee3a315eSPaolo Bonzini	echo
89ee3a315eSPaolo Bonzini	echo "== verifying patterns (2) =="
9061815d6eSFam Zheng	do_test $align "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
91ab53c447SFam Zheng
92ab53c447SFam Zheng	echo
93ab53c447SFam Zheng	echo "== rewriting unaligned zeroes =="
94ab53c447SFam Zheng	do_test $align "write -P 0xb 0x0 0x1000" "$TEST_IMG" | _filter_qemu_io
957fa84cd8SKevin Wolf	do_test $align "$write_zero_cmd 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
96ab53c447SFam Zheng
97ab53c447SFam Zheng	echo
98ab53c447SFam Zheng	echo "== verifying patterns (3) =="
99ab53c447SFam Zheng	do_test $align "read -P 0xb 0x0 0x200" "$TEST_IMG" | _filter_qemu_io
100ab53c447SFam Zheng	do_test $align "read -P 0x0 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
101ab53c447SFam Zheng	do_test $align "read -P 0xb 0x400 0xc00" "$TEST_IMG" | _filter_qemu_io
102ab53c447SFam Zheng
103ab53c447SFam Zheng	echo
10461815d6eSFam Zhengdone
1057fa84cd8SKevin Wolfdone
106ee3a315eSPaolo Bonzini
1076eba9f01SEric Blake_cleanup_test_img
108afe35cdeSAnton Nefedov
109afe35cdeSAnton Nefedov# Trigger truncate that would shrink qcow2 L1 table, which is done by
110afe35cdeSAnton Nefedov#   clearing one entry (8 bytes) with bdrv_co_pwrite_zeroes()
111afe35cdeSAnton Nefedov
112afe35cdeSAnton Nefedovecho
113afe35cdeSAnton Nefedovecho "=== Test misaligned write zeroes via truncate ==="
114afe35cdeSAnton Nefedovecho
115afe35cdeSAnton Nefedov
116afe35cdeSAnton Nefedov# any size will do, but the smaller the size the smaller the required image
117afe35cdeSAnton NefedovCLUSTER_SIZE=$((4 * 1024))
118afe35cdeSAnton NefedovL2_COVERAGE=$(($CLUSTER_SIZE * $CLUSTER_SIZE / 8))
119afe35cdeSAnton Nefedov_make_test_img $(($L2_COVERAGE * 2))
120afe35cdeSAnton Nefedov
121afe35cdeSAnton Nefedovdo_test 512 "write -P 1 0 0x200" "$TEST_IMG" | _filter_qemu_io
122afe35cdeSAnton Nefedov# next L2 table
123afe35cdeSAnton Nefedovdo_test 512 "write -P 1 $L2_COVERAGE 0x200" "$TEST_IMG" | _filter_qemu_io
124afe35cdeSAnton Nefedov
125afe35cdeSAnton Nefedov# only interested in qcow2 here; also other formats might respond with
126afe35cdeSAnton Nefedov#  "not supported" error message
127afe35cdeSAnton Nefedovif [ $IMGFMT = "qcow2" ]; then
128afe35cdeSAnton Nefedov    do_test 512 "truncate $L2_COVERAGE" "$TEST_IMG" | _filter_qemu_io
129afe35cdeSAnton Nefedovfi
130afe35cdeSAnton Nefedov
131afe35cdeSAnton Nefedovdo_test 512 "read -P 1 0 0x200" "$TEST_IMG" | _filter_qemu_io
132afe35cdeSAnton Nefedov
133ee3a315eSPaolo Bonzini# success, all done
134afe35cdeSAnton Nefedovecho
135ee3a315eSPaolo Bonziniecho "*** done"
136ee3a315eSPaolo Bonzinirm -f $seq.full
137ee3a315eSPaolo Bonzinistatus=0
138