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 16e8c212d6SChristoph Hellwig# along with this program. If not, see <http://www.gnu.org/licenses/>. 176bf19c94SChristoph Hellwig# 186bf19c94SChristoph Hellwig 199128ae5eSKevin Wolffunction do_is_allocated() { 209128ae5eSKevin Wolf local start=$1 219128ae5eSKevin Wolf local size=$(( $2 / 512)) 229128ae5eSKevin Wolf local step=$3 239128ae5eSKevin Wolf local count=$4 249128ae5eSKevin Wolf 259128ae5eSKevin Wolf for i in `seq 1 $count`; do 269128ae5eSKevin Wolf echo alloc $(( start + i * step )) $size 279128ae5eSKevin Wolf done 289128ae5eSKevin Wolf} 299128ae5eSKevin Wolf 309128ae5eSKevin Wolffunction is_allocated() { 319128ae5eSKevin Wolf do_is_allocated "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io 329128ae5eSKevin Wolf} 339128ae5eSKevin Wolf 346bf19c94SChristoph Hellwigfunction do_io() { 356bf19c94SChristoph Hellwig local op=$1 366bf19c94SChristoph Hellwig local start=$2 376bf19c94SChristoph Hellwig local size=$3 386bf19c94SChristoph Hellwig local step=$4 396bf19c94SChristoph Hellwig local count=$5 406bf19c94SChristoph Hellwig local pattern=$6 416bf19c94SChristoph Hellwig 426bf19c94SChristoph Hellwig echo === IO: pattern $pattern >&2 436bf19c94SChristoph Hellwig for i in `seq 1 $count`; do 446bf19c94SChristoph Hellwig echo $op -P $pattern $(( start + i * step )) $size 456bf19c94SChristoph Hellwig done 466bf19c94SChristoph Hellwig} 476bf19c94SChristoph Hellwig 486bf19c94SChristoph Hellwigfunction io_pattern() { 499c9afe57SKevin Wolf do_io "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io 506bf19c94SChristoph Hellwig} 516bf19c94SChristoph Hellwig 526bf19c94SChristoph Hellwigfunction io() { 536bf19c94SChristoph Hellwig local start=$2 546bf19c94SChristoph Hellwig local pattern=$(( (start >> 9) % 256 )) 556bf19c94SChristoph Hellwig 569c9afe57SKevin Wolf do_io "$@" $pattern | $QEMU_IO $TEST_IMG | _filter_qemu_io 576bf19c94SChristoph Hellwig} 586bf19c94SChristoph Hellwig 596bf19c94SChristoph Hellwigfunction io_zero() { 609c9afe57SKevin Wolf do_io "$@" 0 | $QEMU_IO $TEST_IMG | _filter_qemu_io 616bf19c94SChristoph Hellwig} 626bf19c94SChristoph Hellwig 636bf19c94SChristoph Hellwigfunction io_test() { 646bf19c94SChristoph Hellwig local op=$1 656bf19c94SChristoph Hellwig local offset=$2 66*8fc1024cSKevin Wolf local cluster_size=$3 676bf19c94SChristoph Hellwig 68*8fc1024cSKevin Wolf local num_large=$4 69*8fc1024cSKevin Wolf local num_medium=$((num_large * num_large)) 70*8fc1024cSKevin Wolf local num_small=$((4 * num_medium)) 71*8fc1024cSKevin Wolf 72*8fc1024cSKevin Wolf local half_cluster=$((cluster_size / 2)) 73*8fc1024cSKevin Wolf local quarter_cluster=$((cluster_size / 4)) 74*8fc1024cSKevin Wolf local l2_size=$((cluster_size * cluster_size / 8)) 75*8fc1024cSKevin Wolf 76*8fc1024cSKevin Wolf # Complete clusters 77*8fc1024cSKevin Wolf io "$op" $offset $cluster_size $cluster_size $num_small 78*8fc1024cSKevin Wolf offset=$((offset + num_small * $cluster_size)) 796bf19c94SChristoph Hellwig 806bf19c94SChristoph Hellwig # From somewhere in the middle to the end of a cluster 81*8fc1024cSKevin Wolf io "$op" $((offset + $half_cluster)) $half_cluster $cluster_size $num_small 82*8fc1024cSKevin Wolf offset=$((offset + num_small * $cluster_size)) 836bf19c94SChristoph Hellwig 846bf19c94SChristoph Hellwig # From the start to somewhere in the middle of a cluster 85*8fc1024cSKevin Wolf io "$op" $offset $half_cluster $cluster_size $num_small 86*8fc1024cSKevin Wolf offset=$((offset + num_small * $cluster_size)) 876bf19c94SChristoph Hellwig 886bf19c94SChristoph Hellwig # Completely misaligned (and small) 89*8fc1024cSKevin Wolf io "$op" $((offset + $quarter_cluster)) $half_cluster $cluster_size $num_small 90*8fc1024cSKevin Wolf offset=$((offset + num_small * $cluster_size)) 916bf19c94SChristoph Hellwig 926bf19c94SChristoph Hellwig # Spanning multiple clusters 93*8fc1024cSKevin Wolf io "$op" $((offset + $half_cluster)) $((cluster_size * 2)) $((cluster_size * 3)) $num_medium 94*8fc1024cSKevin Wolf offset=$((offset + num_medium * 3 * $cluster_size)) 956bf19c94SChristoph Hellwig 966bf19c94SChristoph Hellwig # Spanning multiple L2 tables 976bf19c94SChristoph Hellwig # L2 table size: 512 clusters of 4k = 2M 98*8fc1024cSKevin Wolf io "$op" $((offset + $half_cluster)) $((2 * l2_size)) 4999680 $num_large 99*8fc1024cSKevin Wolf offset=$((offset + num_large * (2 * l2_size + 512 * 1573))) 1006bf19c94SChristoph Hellwig} 1016bf19c94SChristoph Hellwig 1026bf19c94SChristoph Hellwigfunction io_test2() { 1036bf19c94SChristoph Hellwig local orig_offset=$1 104*8fc1024cSKevin Wolf local cluster_size=$2 105*8fc1024cSKevin Wolf local num=$3 1066bf19c94SChristoph Hellwig 1076bf19c94SChristoph Hellwig # Pattern (repeat after 9 clusters): 108*8fc1024cSKevin Wolf # used - used - free - used - compressed - compressed - 109*8fc1024cSKevin Wolf # free - free - compressed 1106bf19c94SChristoph Hellwig 1116bf19c94SChristoph Hellwig # Write the clusters to be compressed 1126bf19c94SChristoph Hellwig echo === Clusters to be compressed [1] 113*8fc1024cSKevin Wolf io_pattern writev $((offset + 4 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 1146bf19c94SChristoph Hellwig echo === Clusters to be compressed [2] 115*8fc1024cSKevin Wolf io_pattern writev $((offset + 5 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 1166bf19c94SChristoph Hellwig echo === Clusters to be compressed [3] 117*8fc1024cSKevin Wolf io_pattern writev $((offset + 8 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 1186bf19c94SChristoph Hellwig 1196bf19c94SChristoph Hellwig mv $TEST_IMG $TEST_IMG.orig 120e76a8e89SChristoph Hellwig $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c $TEST_IMG.orig $TEST_IMG 1216bf19c94SChristoph Hellwig 1226bf19c94SChristoph Hellwig # Write the used clusters 1236bf19c94SChristoph Hellwig echo === Used clusters [1] 124*8fc1024cSKevin Wolf io_pattern writev $((offset + 0 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 1256bf19c94SChristoph Hellwig echo === Used clusters [2] 126*8fc1024cSKevin Wolf io_pattern writev $((offset + 1 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 1276bf19c94SChristoph Hellwig echo === Used clusters [3] 128*8fc1024cSKevin Wolf io_pattern writev $((offset + 3 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 1296bf19c94SChristoph Hellwig 1306bf19c94SChristoph Hellwig # Read them 1316bf19c94SChristoph Hellwig echo === Read used/compressed clusters 132*8fc1024cSKevin Wolf io_pattern readv $((offset + 0 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num 165 133*8fc1024cSKevin Wolf io_pattern readv $((offset + 3 * $cluster_size)) $((3 * $cluster_size)) $((9 * $cluster_size)) $num 165 134*8fc1024cSKevin Wolf io_pattern readv $((offset + 8 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num 165 1356bf19c94SChristoph Hellwig 1366bf19c94SChristoph Hellwig echo === Read zeros 137*8fc1024cSKevin Wolf io_zero readv $((offset + 2 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num 138*8fc1024cSKevin Wolf io_zero readv $((offset + 6 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num 1396bf19c94SChristoph Hellwig} 140