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