]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qemu-iotests/033
qemu-iotests: Test qcow2 preallocation modes
[mirror_qemu.git] / tests / qemu-iotests / 033
CommitLineData
11a82d14 1#!/usr/bin/env bash
ee3a315e
PB
2#
3# Test aligned and misaligned write zeroes operations.
4#
5# Copyright (C) 2012 Red Hat, Inc.
6#
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.
11#
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.
16#
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/>.
19#
20
21# creator
22owner=pbonzini@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
ee3a315e
PB
27status=1 # failure is the default!
28
29_cleanup()
30{
31 _cleanup_test_img
32}
33trap "_cleanup; exit \$status" 0 1 2 3 15
34
35# get standard environment, filters and checks
36. ./common.rc
37. ./common.filter
38
39_supported_fmt generic
40_supported_proto generic
41_supported_os Linux
42
43
44size=128M
45_make_test_img $size
46
61815d6e
FZ
47do_test()
48{
49 local align=$1
50 local iocmd=$2
51 local img=$3
13a1d4a7
DB
52 if [ "$IMGOPTSSYNTAX" = "true" ]
53 then
54 IO_OPEN_ARG="$img"
55 IO_EXTRA_ARGS="--image-opts"
56 else
57 IO_OPEN_ARG="-o driver=$IMGFMT,file.align=$align blkdebug::$img"
58 IO_EXTRA_ARGS=""
59 fi
61815d6e 60 {
13a1d4a7 61 echo "open $IO_OPEN_ARG"
61815d6e 62 echo $iocmd
13a1d4a7 63 } | $QEMU_IO $IO_EXTRA_ARGS
61815d6e
FZ
64}
65
afe35cde
AN
66echo
67echo "=== Test aligned and misaligned write zeroes operations ==="
68
7fa84cd8 69for write_zero_cmd in "write -z" "aio_write -z"; do
61815d6e
FZ
70for align in 512 4k; do
71 echo
72 echo "== preparing image =="
73 do_test $align "write -P 0xa 0x200 0x400" "$TEST_IMG" | _filter_qemu_io
74 do_test $align "write -P 0xa 0x20000 0x600" "$TEST_IMG" | _filter_qemu_io
7fa84cd8 75 do_test $align "$write_zero_cmd 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
ee3a315e 76
61815d6e
FZ
77 echo
78 echo "== verifying patterns (1) =="
79 do_test $align "read -P 0xa 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
80 do_test $align "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
81 do_test $align "read -P 0xa 0x20400 0x200" "$TEST_IMG" | _filter_qemu_io
ee3a315e 82
61815d6e
FZ
83 echo
84 echo "== rewriting zeroes =="
85 do_test $align "write -P 0xb 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
7fa84cd8 86 do_test $align "$write_zero_cmd 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
ee3a315e 87
61815d6e
FZ
88 echo
89 echo "== verifying patterns (2) =="
90 do_test $align "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
ab53c447
FZ
91
92 echo
93 echo "== rewriting unaligned zeroes =="
94 do_test $align "write -P 0xb 0x0 0x1000" "$TEST_IMG" | _filter_qemu_io
7fa84cd8 95 do_test $align "$write_zero_cmd 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
ab53c447
FZ
96
97 echo
98 echo "== verifying patterns (3) =="
99 do_test $align "read -P 0xb 0x0 0x200" "$TEST_IMG" | _filter_qemu_io
100 do_test $align "read -P 0x0 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
101 do_test $align "read -P 0xb 0x400 0xc00" "$TEST_IMG" | _filter_qemu_io
102
103 echo
61815d6e 104done
7fa84cd8 105done
ee3a315e 106
6eba9f01 107_cleanup_test_img
afe35cde
AN
108
109# Trigger truncate that would shrink qcow2 L1 table, which is done by
110# clearing one entry (8 bytes) with bdrv_co_pwrite_zeroes()
111
112echo
113echo "=== Test misaligned write zeroes via truncate ==="
114echo
115
116# any size will do, but the smaller the size the smaller the required image
117CLUSTER_SIZE=$((4 * 1024))
118L2_COVERAGE=$(($CLUSTER_SIZE * $CLUSTER_SIZE / 8))
119_make_test_img $(($L2_COVERAGE * 2))
120
121do_test 512 "write -P 1 0 0x200" "$TEST_IMG" | _filter_qemu_io
122# next L2 table
123do_test 512 "write -P 1 $L2_COVERAGE 0x200" "$TEST_IMG" | _filter_qemu_io
124
125# only interested in qcow2 here; also other formats might respond with
126# "not supported" error message
127if [ $IMGFMT = "qcow2" ]; then
128 do_test 512 "truncate $L2_COVERAGE" "$TEST_IMG" | _filter_qemu_io
129fi
130
131do_test 512 "read -P 1 0 0x200" "$TEST_IMG" | _filter_qemu_io
132
ee3a315e 133# success, all done
afe35cde 134echo
ee3a315e
PB
135echo "*** done"
136rm -f $seq.full
137status=0