xref: /qemu/tests/qemu-iotests/177 (revision d6ac6e93632e9196592199a5bcda957c06a8bf64)
140812d93SEric Blake#!/bin/bash
240812d93SEric Blake#
340812d93SEric Blake# Test corner cases with unusual block geometries
440812d93SEric Blake#
5*d6ac6e93SEric Blake# Copyright (C) 2016-2018 Red Hat, Inc.
640812d93SEric Blake#
740812d93SEric Blake# This program is free software; you can redistribute it and/or modify
840812d93SEric Blake# it under the terms of the GNU General Public License as published by
940812d93SEric Blake# the Free Software Foundation; either version 2 of the License, or
1040812d93SEric Blake# (at your option) any later version.
1140812d93SEric Blake#
1240812d93SEric Blake# This program is distributed in the hope that it will be useful,
1340812d93SEric Blake# but WITHOUT ANY WARRANTY; without even the implied warranty of
1440812d93SEric Blake# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1540812d93SEric Blake# GNU General Public License for more details.
1640812d93SEric Blake#
1740812d93SEric Blake# You should have received a copy of the GNU General Public License
1840812d93SEric Blake# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1940812d93SEric Blake#
2040812d93SEric Blake
2140812d93SEric Blake# creator
2240812d93SEric Blakeowner=eblake@redhat.com
2340812d93SEric Blake
2440812d93SEric Blakeseq=`basename $0`
2540812d93SEric Blakeecho "QA output created by $seq"
2640812d93SEric Blake
2740812d93SEric Blakehere=`pwd`
2840812d93SEric Blakestatus=1	# failure is the default!
2940812d93SEric Blake
3040812d93SEric Blake_cleanup()
3140812d93SEric Blake{
3240812d93SEric Blake	_cleanup_test_img
3340812d93SEric Blake}
3440812d93SEric Blaketrap "_cleanup; exit \$status" 0 1 2 3 15
3540812d93SEric Blake
3640812d93SEric Blake# get standard environment, filters and checks
3740812d93SEric Blake. ./common.rc
3840812d93SEric Blake. ./common.filter
3940812d93SEric Blake
40*d6ac6e93SEric Blake# This test is runnable under compat=0.10; see test 204 for additional
41*d6ac6e93SEric Blake# tests specific to compat=1.1.
42*d6ac6e93SEric Blake
4340812d93SEric Blake_supported_fmt qcow2
4440812d93SEric Blake_supported_proto file
4540812d93SEric Blake
4640812d93SEric BlakeCLUSTER_SIZE=1M
4740812d93SEric Blakesize=128M
4840812d93SEric Blakeoptions=driver=blkdebug,image.driver=qcow2
4940812d93SEric Blake
5040812d93SEric Blakeecho
5140812d93SEric Blakeecho "== setting up files =="
5240812d93SEric Blake
5340812d93SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img $size
5440812d93SEric Blake$QEMU_IO -c "write -P 11 0 $size" "$TEST_IMG.base" | _filter_qemu_io
5540812d93SEric Blake_make_test_img -b "$TEST_IMG.base"
56*d6ac6e93SEric Blake$QEMU_IO -c "write -P 22 0 $size" "$TEST_IMG" | _filter_qemu_io
5740812d93SEric Blake
5840812d93SEric Blake# Limited to 64k max-transfer
5940812d93SEric Blakeecho
6040812d93SEric Blakeecho "== constrained alignment and max-transfer =="
6140812d93SEric Blakelimits=align=4k,max-transfer=64k
6240812d93SEric Blake$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
6340812d93SEric Blake         -c "write -P 33 1000 128k" -c "read -P 33 1000 128k" | _filter_qemu_io
6440812d93SEric Blake
6540812d93SEric Blakeecho
6640812d93SEric Blakeecho "== write zero with constrained max-transfer =="
6740812d93SEric Blakelimits=align=512,max-transfer=64k,opt-write-zero=$CLUSTER_SIZE
6840812d93SEric Blake$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
6940812d93SEric Blake         -c "write -z 8003584 2093056" | _filter_qemu_io
7040812d93SEric Blake
7140812d93SEric Blake# non-power-of-2 write-zero/discard alignments
7240812d93SEric Blakeecho
7340812d93SEric Blakeecho "== non-power-of-2 write zeroes limits =="
7440812d93SEric Blake
7540812d93SEric Blakelimits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
7640812d93SEric Blake$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
7740812d93SEric Blake         -c "write -z 32M 32M" | _filter_qemu_io
7840812d93SEric Blake
7940812d93SEric Blakeecho
8040812d93SEric Blakeecho "== non-power-of-2 discard limits =="
8140812d93SEric Blake
8240812d93SEric Blakelimits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
8340812d93SEric Blake$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
8440812d93SEric Blake         -c "discard 80000001 30M" | _filter_qemu_io
8540812d93SEric Blake
8640812d93SEric Blakeecho
8740812d93SEric Blakeecho "== verify image content =="
8840812d93SEric Blake
8940812d93SEric Blakefunction verify_io()
9040812d93SEric Blake{
9140812d93SEric Blake    if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" |
9240812d93SEric Blake	    grep "compat: 0.10" > /dev/null); then
9340812d93SEric Blake        # For v2 images, discarded clusters are read from the backing file
9440812d93SEric Blake        discarded=11
9540812d93SEric Blake    else
9640812d93SEric Blake        # Discarded clusters are zeroed for v3 or later
9740812d93SEric Blake        discarded=0
9840812d93SEric Blake    fi
9940812d93SEric Blake
10040812d93SEric Blake    echo read -P 22 0 1000
10140812d93SEric Blake    echo read -P 33 1000 128k
10240812d93SEric Blake    echo read -P 22 132072 7871512
10340812d93SEric Blake    echo read -P 0 8003584 2093056
10440812d93SEric Blake    echo read -P 22 10096640 23457792
10540812d93SEric Blake    echo read -P 0 32M 32M
10640812d93SEric Blake    echo read -P 22 64M 13M
10740812d93SEric Blake    echo read -P $discarded 77M 29M
108*d6ac6e93SEric Blake    echo read -P 22 106M 22M
10940812d93SEric Blake}
11040812d93SEric Blake
11140812d93SEric Blakeverify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io
11240812d93SEric Blake
11340812d93SEric Blake_check_test_img
11440812d93SEric Blake
11540812d93SEric Blake# success, all done
11640812d93SEric Blakeecho "*** done"
11740812d93SEric Blakestatus=0
118