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