blob: ddfbca1b76927c88cdd5727f0b727ae34f7441c2 [file] [log] [blame]
Stefan Hajnoczi908eaf62010-04-26 11:44:05 +02001#!/bin/bash
Christoph Hellwig6bf19c92009-06-22 18:29:05 +02002#
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
Christoph Hellwige8c212d2009-07-16 19:26:54 +020016# along with this program. If not, see <http://www.gnu.org/licenses/>.
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020017#
18
Kevin Wolf9128ae52009-07-16 19:11:09 +020019function do_is_allocated() {
20 local start=$1
21 local size=$(( $2 / 512))
22 local step=$3
23 local count=$4
24
25 for i in `seq 1 $count`; do
Stefan Hajnoczidd0c35d2011-02-04 12:55:02 +000026 echo alloc $(( start + (i - 1) * step )) $size
Kevin Wolf9128ae52009-07-16 19:11:09 +020027 done
28}
29
30function is_allocated() {
Jeff Cody00840432013-10-31 11:57:36 -040031 do_is_allocated "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
Kevin Wolf9128ae52009-07-16 19:11:09 +020032}
33
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020034function do_io() {
35 local op=$1
36 local start=$2
37 local size=$3
38 local step=$4
39 local count=$5
40 local pattern=$6
41
42 echo === IO: pattern $pattern >&2
43 for i in `seq 1 $count`; do
Stefan Hajnoczidd0c35d2011-02-04 12:55:02 +000044 echo $op -P $pattern $(( start + (i - 1) * step )) $size
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020045 done
46}
47
48function io_pattern() {
Jeff Cody00840432013-10-31 11:57:36 -040049 do_io "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020050}
51
52function io() {
53 local start=$2
54 local pattern=$(( (start >> 9) % 256 ))
55
Jeff Cody00840432013-10-31 11:57:36 -040056 do_io "$@" $pattern | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020057}
58
59function io_zero() {
Jeff Cody00840432013-10-31 11:57:36 -040060 do_io "$@" 0 | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020061}
62
63function io_test() {
64 local op=$1
65 local offset=$2
Kevin Wolf8fc10242009-10-01 14:29:59 -030066 local cluster_size=$3
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020067
Kevin Wolf8fc10242009-10-01 14:29:59 -030068 local num_large=$4
69 local num_medium=$((num_large * num_large))
70 local num_small=$((4 * num_medium))
71
72 local half_cluster=$((cluster_size / 2))
73 local quarter_cluster=$((cluster_size / 4))
74 local l2_size=$((cluster_size * cluster_size / 8))
75
76 # Complete clusters
77 io "$op" $offset $cluster_size $cluster_size $num_small
78 offset=$((offset + num_small * $cluster_size))
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020079
80 # From somewhere in the middle to the end of a cluster
Kevin Wolf8fc10242009-10-01 14:29:59 -030081 io "$op" $((offset + $half_cluster)) $half_cluster $cluster_size $num_small
82 offset=$((offset + num_small * $cluster_size))
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020083
84 # From the start to somewhere in the middle of a cluster
Kevin Wolf8fc10242009-10-01 14:29:59 -030085 io "$op" $offset $half_cluster $cluster_size $num_small
86 offset=$((offset + num_small * $cluster_size))
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020087
88 # Completely misaligned (and small)
Kevin Wolf8fc10242009-10-01 14:29:59 -030089 io "$op" $((offset + $quarter_cluster)) $half_cluster $cluster_size $num_small
90 offset=$((offset + num_small * $cluster_size))
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020091
92 # Spanning multiple clusters
Kevin Wolf8fc10242009-10-01 14:29:59 -030093 io "$op" $((offset + $half_cluster)) $((cluster_size * 2)) $((cluster_size * 3)) $num_medium
94 offset=$((offset + num_medium * 3 * $cluster_size))
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020095
96 # Spanning multiple L2 tables
97 # L2 table size: 512 clusters of 4k = 2M
Kevin Wolfac5e2b22009-10-01 14:30:19 -030098 offset=$(( ((offset + l2_size - 1) & ~(l2_size - 1)) - (3 * half_cluster) ))
99 io "$op" $offset $((6 * half_cluster)) $(( l2_size + half_cluster )) $num_large
100 offset=$((offset + num_large * ( l2_size + half_cluster )))
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200101}
102
103function io_test2() {
104 local orig_offset=$1
Kevin Wolf8fc10242009-10-01 14:29:59 -0300105 local cluster_size=$2
106 local num=$3
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200107
108 # Pattern (repeat after 9 clusters):
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200109 # used - used - free - used - compressed - compressed -
110 # free - free - compressed
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200111
112 # Write the clusters to be compressed
113 echo === Clusters to be compressed [1]
Kevin Wolf8fc10242009-10-01 14:29:59 -0300114 io_pattern writev $((offset + 4 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200115 echo === Clusters to be compressed [2]
Kevin Wolf8fc10242009-10-01 14:29:59 -0300116 io_pattern writev $((offset + 5 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200117 echo === Clusters to be compressed [3]
Kevin Wolf8fc10242009-10-01 14:29:59 -0300118 io_pattern writev $((offset + 8 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200119
Jeff Cody00840432013-10-31 11:57:36 -0400120 mv "$TEST_IMG" "$TEST_IMG.orig"
121 $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c "$TEST_IMG.orig" "$TEST_IMG"
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200122
123 # Write the used clusters
124 echo === Used clusters [1]
Kevin Wolf8fc10242009-10-01 14:29:59 -0300125 io_pattern writev $((offset + 0 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200126 echo === Used clusters [2]
Kevin Wolf8fc10242009-10-01 14:29:59 -0300127 io_pattern writev $((offset + 1 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200128 echo === Used clusters [3]
Kevin Wolf8fc10242009-10-01 14:29:59 -0300129 io_pattern writev $((offset + 3 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200130
131 # Read them
132 echo === Read used/compressed clusters
Kevin Wolf8fc10242009-10-01 14:29:59 -0300133 io_pattern readv $((offset + 0 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num 165
134 io_pattern readv $((offset + 3 * $cluster_size)) $((3 * $cluster_size)) $((9 * $cluster_size)) $num 165
135 io_pattern readv $((offset + 8 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num 165
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200136
137 echo === Read zeros
Kevin Wolf8fc10242009-10-01 14:29:59 -0300138 io_zero readv $((offset + 2 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num
139 io_zero readv $((offset + 6 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200140}