1*6bf19c94SChristoph Hellwig#!/bin/sh 2*6bf19c94SChristoph Hellwig# 3*6bf19c94SChristoph Hellwig# Copyright (C) 2009 Red Hat, Inc. 4*6bf19c94SChristoph Hellwig# 5*6bf19c94SChristoph Hellwig# This program is free software; you can redistribute it and/or modify 6*6bf19c94SChristoph Hellwig# it under the terms of the GNU General Public License as published by 7*6bf19c94SChristoph Hellwig# the Free Software Foundation; either version 2 of the License, or 8*6bf19c94SChristoph Hellwig# (at your option) any later version. 9*6bf19c94SChristoph Hellwig# 10*6bf19c94SChristoph Hellwig# This program is distributed in the hope that it will be useful, 11*6bf19c94SChristoph Hellwig# but WITHOUT ANY WARRANTY; without even the implied warranty of 12*6bf19c94SChristoph Hellwig# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*6bf19c94SChristoph Hellwig# GNU General Public License for more details. 14*6bf19c94SChristoph Hellwig# 15*6bf19c94SChristoph Hellwig# You should have received a copy of the GNU General Public License 16*6bf19c94SChristoph Hellwig# along with this program; if not, write to the Free Software 17*6bf19c94SChristoph Hellwig# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 18*6bf19c94SChristoph Hellwig# USA 19*6bf19c94SChristoph Hellwig# 20*6bf19c94SChristoph Hellwig 21*6bf19c94SChristoph Hellwigfunction do_io() { 22*6bf19c94SChristoph Hellwig local op=$1 23*6bf19c94SChristoph Hellwig local start=$2 24*6bf19c94SChristoph Hellwig local size=$3 25*6bf19c94SChristoph Hellwig local step=$4 26*6bf19c94SChristoph Hellwig local count=$5 27*6bf19c94SChristoph Hellwig local pattern=$6 28*6bf19c94SChristoph Hellwig 29*6bf19c94SChristoph Hellwig echo === IO: pattern $pattern >&2 30*6bf19c94SChristoph Hellwig for i in `seq 1 $count`; do 31*6bf19c94SChristoph Hellwig echo $op -P $pattern $(( start + i * step )) $size 32*6bf19c94SChristoph Hellwig done 33*6bf19c94SChristoph Hellwig} 34*6bf19c94SChristoph Hellwig 35*6bf19c94SChristoph Hellwigfunction io_pattern() { 36*6bf19c94SChristoph Hellwig do_io $@ | $QEMU_IO $TEST_IMG | _filter_qemu_io 37*6bf19c94SChristoph Hellwig} 38*6bf19c94SChristoph Hellwig 39*6bf19c94SChristoph Hellwigfunction io() { 40*6bf19c94SChristoph Hellwig local start=$2 41*6bf19c94SChristoph Hellwig local pattern=$(( (start >> 9) % 256 )) 42*6bf19c94SChristoph Hellwig 43*6bf19c94SChristoph Hellwig do_io $@ $pattern | $QEMU_IO $TEST_IMG | _filter_qemu_io 44*6bf19c94SChristoph Hellwig} 45*6bf19c94SChristoph Hellwig 46*6bf19c94SChristoph Hellwigfunction io_zero() { 47*6bf19c94SChristoph Hellwig do_io $@ 0 | $QEMU_IO $TEST_IMG | _filter_qemu_io 48*6bf19c94SChristoph Hellwig} 49*6bf19c94SChristoph Hellwig 50*6bf19c94SChristoph Hellwigfunction io_test() { 51*6bf19c94SChristoph Hellwig local op=$1 52*6bf19c94SChristoph Hellwig local offset=$2 53*6bf19c94SChristoph Hellwig 54*6bf19c94SChristoph Hellwig # Complete clusters (size = 4k) 55*6bf19c94SChristoph Hellwig io $op $offset 4096 4096 256 56*6bf19c94SChristoph Hellwig offset=$((offset + 256 * 4096)) 57*6bf19c94SChristoph Hellwig 58*6bf19c94SChristoph Hellwig # From somewhere in the middle to the end of a cluster 59*6bf19c94SChristoph Hellwig io $op $((offset + 2048)) 2048 4096 256 60*6bf19c94SChristoph Hellwig offset=$((offset + 256 * 4096)) 61*6bf19c94SChristoph Hellwig 62*6bf19c94SChristoph Hellwig # From the start to somewhere in the middle of a cluster 63*6bf19c94SChristoph Hellwig io $op $offset 2048 4096 256 64*6bf19c94SChristoph Hellwig offset=$((offset + 256 * 4096)) 65*6bf19c94SChristoph Hellwig 66*6bf19c94SChristoph Hellwig # Completely misaligned (and small) 67*6bf19c94SChristoph Hellwig io $op $((offset + 1024)) 2048 4096 256 68*6bf19c94SChristoph Hellwig offset=$((offset + 256 * 4096)) 69*6bf19c94SChristoph Hellwig 70*6bf19c94SChristoph Hellwig # Spanning multiple clusters 71*6bf19c94SChristoph Hellwig io $op $((offset + 2048)) 8192 12288 64 72*6bf19c94SChristoph Hellwig offset=$((offset + 64 * 12288)) 73*6bf19c94SChristoph Hellwig 74*6bf19c94SChristoph Hellwig # Spanning multiple L2 tables 75*6bf19c94SChristoph Hellwig # L2 table size: 512 clusters of 4k = 2M 76*6bf19c94SChristoph Hellwig io $op $((offset + 2048)) 4194304 4999680 8 77*6bf19c94SChristoph Hellwig offset=$((offset + 8 * 4999680)) 78*6bf19c94SChristoph Hellwig 79*6bf19c94SChristoph Hellwig if false; then 80*6bf19c94SChristoph Hellwig true 81*6bf19c94SChristoph Hellwig fi 82*6bf19c94SChristoph Hellwig} 83*6bf19c94SChristoph Hellwig 84*6bf19c94SChristoph Hellwigfunction io_test2() { 85*6bf19c94SChristoph Hellwig local orig_offset=$1 86*6bf19c94SChristoph Hellwig 87*6bf19c94SChristoph Hellwig # Pattern (repeat after 9 clusters): 88*6bf19c94SChristoph Hellwig # used - used - free - used - compressed - compressed - free - free - compressed 89*6bf19c94SChristoph Hellwig 90*6bf19c94SChristoph Hellwig # Write the clusters to be compressed 91*6bf19c94SChristoph Hellwig echo === Clusters to be compressed [1] 92*6bf19c94SChristoph Hellwig io_pattern writev $((offset + 4 * 4096)) 4096 $((9 * 4096)) 256 165 93*6bf19c94SChristoph Hellwig echo === Clusters to be compressed [2] 94*6bf19c94SChristoph Hellwig io_pattern writev $((offset + 5 * 4096)) 4096 $((9 * 4096)) 256 165 95*6bf19c94SChristoph Hellwig echo === Clusters to be compressed [3] 96*6bf19c94SChristoph Hellwig io_pattern writev $((offset + 8 * 4096)) 4096 $((9 * 4096)) 256 165 97*6bf19c94SChristoph Hellwig 98*6bf19c94SChristoph Hellwig mv $TEST_IMG $TEST_IMG.orig 99*6bf19c94SChristoph Hellwig $QEMU_IMG convert -f qcow2 -O qcow2 -c $TEST_IMG.orig $TEST_IMG 100*6bf19c94SChristoph Hellwig 101*6bf19c94SChristoph Hellwig # Write the used clusters 102*6bf19c94SChristoph Hellwig echo === Used clusters [1] 103*6bf19c94SChristoph Hellwig io_pattern writev $((offset + 0 * 4096)) 4096 $((9 * 4096)) 256 165 104*6bf19c94SChristoph Hellwig echo === Used clusters [2] 105*6bf19c94SChristoph Hellwig io_pattern writev $((offset + 1 * 4096)) 4096 $((9 * 4096)) 256 165 106*6bf19c94SChristoph Hellwig echo === Used clusters [3] 107*6bf19c94SChristoph Hellwig io_pattern writev $((offset + 3 * 4096)) 4096 $((9 * 4096)) 256 165 108*6bf19c94SChristoph Hellwig 109*6bf19c94SChristoph Hellwig # Read them 110*6bf19c94SChristoph Hellwig echo === Read used/compressed clusters 111*6bf19c94SChristoph Hellwig io_pattern readv $((offset + 0 * 4096)) $((2 * 4096)) $((9 * 4096)) 256 165 112*6bf19c94SChristoph Hellwig io_pattern readv $((offset + 3 * 4096)) $((3 * 4096)) $((9 * 4096)) 256 165 113*6bf19c94SChristoph Hellwig io_pattern readv $((offset + 8 * 4096)) $((1 * 4096)) $((9 * 4096)) 256 165 114*6bf19c94SChristoph Hellwig 115*6bf19c94SChristoph Hellwig echo === Read zeros 116*6bf19c94SChristoph Hellwig io_zero readv $((offset + 2 * 4096)) $((1 * 4096)) $((9 * 4096)) 256 117*6bf19c94SChristoph Hellwig io_zero readv $((offset + 6 * 4096)) $((2 * 4096)) $((9 * 4096)) 256 118*6bf19c94SChristoph Hellwig} 119