16bf19c94SChristoph Hellwig#!/bin/sh 26bf19c94SChristoph Hellwig# 36bf19c94SChristoph Hellwig# Copyright (C) 2009 Red Hat, Inc. 46bf19c94SChristoph Hellwig# 56bf19c94SChristoph Hellwig# This program is free software; you can redistribute it and/or modify 66bf19c94SChristoph Hellwig# it under the terms of the GNU General Public License as published by 76bf19c94SChristoph Hellwig# the Free Software Foundation; either version 2 of the License, or 86bf19c94SChristoph Hellwig# (at your option) any later version. 96bf19c94SChristoph Hellwig# 106bf19c94SChristoph Hellwig# This program is distributed in the hope that it will be useful, 116bf19c94SChristoph Hellwig# but WITHOUT ANY WARRANTY; without even the implied warranty of 126bf19c94SChristoph Hellwig# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 136bf19c94SChristoph Hellwig# GNU General Public License for more details. 146bf19c94SChristoph Hellwig# 156bf19c94SChristoph Hellwig# You should have received a copy of the GNU General Public License 166bf19c94SChristoph Hellwig# along with this program; if not, write to the Free Software 176bf19c94SChristoph Hellwig# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 186bf19c94SChristoph Hellwig# USA 196bf19c94SChristoph Hellwig# 206bf19c94SChristoph Hellwig 216bf19c94SChristoph Hellwigfunction do_io() { 226bf19c94SChristoph Hellwig local op=$1 236bf19c94SChristoph Hellwig local start=$2 246bf19c94SChristoph Hellwig local size=$3 256bf19c94SChristoph Hellwig local step=$4 266bf19c94SChristoph Hellwig local count=$5 276bf19c94SChristoph Hellwig local pattern=$6 286bf19c94SChristoph Hellwig 296bf19c94SChristoph Hellwig echo === IO: pattern $pattern >&2 306bf19c94SChristoph Hellwig for i in `seq 1 $count`; do 316bf19c94SChristoph Hellwig echo $op -P $pattern $(( start + i * step )) $size 326bf19c94SChristoph Hellwig done 336bf19c94SChristoph Hellwig} 346bf19c94SChristoph Hellwig 356bf19c94SChristoph Hellwigfunction io_pattern() { 366bf19c94SChristoph Hellwig do_io $@ | $QEMU_IO $TEST_IMG | _filter_qemu_io 376bf19c94SChristoph Hellwig} 386bf19c94SChristoph Hellwig 396bf19c94SChristoph Hellwigfunction io() { 406bf19c94SChristoph Hellwig local start=$2 416bf19c94SChristoph Hellwig local pattern=$(( (start >> 9) % 256 )) 426bf19c94SChristoph Hellwig 436bf19c94SChristoph Hellwig do_io $@ $pattern | $QEMU_IO $TEST_IMG | _filter_qemu_io 446bf19c94SChristoph Hellwig} 456bf19c94SChristoph Hellwig 466bf19c94SChristoph Hellwigfunction io_zero() { 476bf19c94SChristoph Hellwig do_io $@ 0 | $QEMU_IO $TEST_IMG | _filter_qemu_io 486bf19c94SChristoph Hellwig} 496bf19c94SChristoph Hellwig 506bf19c94SChristoph Hellwigfunction io_test() { 516bf19c94SChristoph Hellwig local op=$1 526bf19c94SChristoph Hellwig local offset=$2 536bf19c94SChristoph Hellwig 546bf19c94SChristoph Hellwig # Complete clusters (size = 4k) 556bf19c94SChristoph Hellwig io $op $offset 4096 4096 256 566bf19c94SChristoph Hellwig offset=$((offset + 256 * 4096)) 576bf19c94SChristoph Hellwig 586bf19c94SChristoph Hellwig # From somewhere in the middle to the end of a cluster 596bf19c94SChristoph Hellwig io $op $((offset + 2048)) 2048 4096 256 606bf19c94SChristoph Hellwig offset=$((offset + 256 * 4096)) 616bf19c94SChristoph Hellwig 626bf19c94SChristoph Hellwig # From the start to somewhere in the middle of a cluster 636bf19c94SChristoph Hellwig io $op $offset 2048 4096 256 646bf19c94SChristoph Hellwig offset=$((offset + 256 * 4096)) 656bf19c94SChristoph Hellwig 666bf19c94SChristoph Hellwig # Completely misaligned (and small) 676bf19c94SChristoph Hellwig io $op $((offset + 1024)) 2048 4096 256 686bf19c94SChristoph Hellwig offset=$((offset + 256 * 4096)) 696bf19c94SChristoph Hellwig 706bf19c94SChristoph Hellwig # Spanning multiple clusters 716bf19c94SChristoph Hellwig io $op $((offset + 2048)) 8192 12288 64 726bf19c94SChristoph Hellwig offset=$((offset + 64 * 12288)) 736bf19c94SChristoph Hellwig 746bf19c94SChristoph Hellwig # Spanning multiple L2 tables 756bf19c94SChristoph Hellwig # L2 table size: 512 clusters of 4k = 2M 766bf19c94SChristoph Hellwig io $op $((offset + 2048)) 4194304 4999680 8 776bf19c94SChristoph Hellwig offset=$((offset + 8 * 4999680)) 786bf19c94SChristoph Hellwig 796bf19c94SChristoph Hellwig if false; then 806bf19c94SChristoph Hellwig true 816bf19c94SChristoph Hellwig fi 826bf19c94SChristoph Hellwig} 836bf19c94SChristoph Hellwig 846bf19c94SChristoph Hellwigfunction io_test2() { 856bf19c94SChristoph Hellwig local orig_offset=$1 866bf19c94SChristoph Hellwig 876bf19c94SChristoph Hellwig # Pattern (repeat after 9 clusters): 886bf19c94SChristoph Hellwig # used - used - free - used - compressed - compressed - free - free - compressed 896bf19c94SChristoph Hellwig 906bf19c94SChristoph Hellwig # Write the clusters to be compressed 916bf19c94SChristoph Hellwig echo === Clusters to be compressed [1] 926bf19c94SChristoph Hellwig io_pattern writev $((offset + 4 * 4096)) 4096 $((9 * 4096)) 256 165 936bf19c94SChristoph Hellwig echo === Clusters to be compressed [2] 946bf19c94SChristoph Hellwig io_pattern writev $((offset + 5 * 4096)) 4096 $((9 * 4096)) 256 165 956bf19c94SChristoph Hellwig echo === Clusters to be compressed [3] 966bf19c94SChristoph Hellwig io_pattern writev $((offset + 8 * 4096)) 4096 $((9 * 4096)) 256 165 976bf19c94SChristoph Hellwig 986bf19c94SChristoph Hellwig mv $TEST_IMG $TEST_IMG.orig 99*e76a8e89SChristoph Hellwig $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c $TEST_IMG.orig $TEST_IMG 1006bf19c94SChristoph Hellwig 1016bf19c94SChristoph Hellwig # Write the used clusters 1026bf19c94SChristoph Hellwig echo === Used clusters [1] 1036bf19c94SChristoph Hellwig io_pattern writev $((offset + 0 * 4096)) 4096 $((9 * 4096)) 256 165 1046bf19c94SChristoph Hellwig echo === Used clusters [2] 1056bf19c94SChristoph Hellwig io_pattern writev $((offset + 1 * 4096)) 4096 $((9 * 4096)) 256 165 1066bf19c94SChristoph Hellwig echo === Used clusters [3] 1076bf19c94SChristoph Hellwig io_pattern writev $((offset + 3 * 4096)) 4096 $((9 * 4096)) 256 165 1086bf19c94SChristoph Hellwig 1096bf19c94SChristoph Hellwig # Read them 1106bf19c94SChristoph Hellwig echo === Read used/compressed clusters 1116bf19c94SChristoph Hellwig io_pattern readv $((offset + 0 * 4096)) $((2 * 4096)) $((9 * 4096)) 256 165 1126bf19c94SChristoph Hellwig io_pattern readv $((offset + 3 * 4096)) $((3 * 4096)) $((9 * 4096)) 256 165 1136bf19c94SChristoph Hellwig io_pattern readv $((offset + 8 * 4096)) $((1 * 4096)) $((9 * 4096)) 256 165 1146bf19c94SChristoph Hellwig 1156bf19c94SChristoph Hellwig echo === Read zeros 1166bf19c94SChristoph Hellwig io_zero readv $((offset + 2 * 4096)) $((1 * 4096)) $((9 * 4096)) 256 1176bf19c94SChristoph Hellwig io_zero readv $((offset + 6 * 4096)) $((2 * 4096)) $((9 * 4096)) 256 1186bf19c94SChristoph Hellwig} 119