Modify know hosts (kermit1, gonzo1).
[xfstests-dev.git] / common.filestreams
1 ##/bin/sh
2 #
3 # Copyright (c) 2007 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # Core of filestreams tests.
6 #
7
8 _check_filestreams_support()
9 {
10         local irix_timeout_sysvar="xfs_mfstream_timeout"
11         local linux_timeout_procvar="/proc/sys/fs/xfs/filestream_centisecs"
12         local streams_avail=""
13         if [ "$HOSTOS" == "IRIX" ]; then
14                 # check for the filestreams timeout systune variable in irix
15                 streams_avail=`systune $irix_timeout_sysvar 2>&1 |
16                         perl -ne 'if (/'$irix_timeout_sysvar'\s+=\s+\d+/) {print "true"}'`
17         else
18                 # check for the filestreams timeout proc entry in linux
19                 [ -f $linux_timeout_procvar ] && streams_avail="true"
20         fi
21
22         if [ "$streams_avail" == "true" ]; then
23                 return 0
24         else
25                 return 1
26         fi
27 }
28
29 _set_stream_timeout_centisecs()
30 {
31         local new_timeout_csecs=$1
32         local irix_timeout_sysvar="xfs_mfstream_timeout"
33         local linux_timeout_procvar="/proc/sys/fs/xfs/filestream_centisecs"
34         if [ "$HOSTOS" == "IRIX" ]; then
35                 echo y | systune -r $irix_timeout_sysvar $new_timeout_csecs >/dev/null
36         else
37                 echo $new_timeout_csecs > $linux_timeout_procvar
38         fi
39 }
40
41 _do_stream()
42 {
43         local directory_name=$1
44         local files=$2
45         local file_size=$3
46         local bsize=$4
47         local iflag=$5
48         local dio=$6
49         local blocks_in_file=`expr $file_size / $bsize`
50
51         mkdir $directory_name
52         if [ "$iflag" = "1" -a "$HOSTOS" != "IRIX" ]; then
53                 $XFS_IO_PROG -x -c "chattr +S" $directory_name \
54                         || _fail "chattr of filestream flag"
55         fi
56         cd $directory_name
57
58         local dd_cmd=""
59         if [ "$HOSTOS" == "IRIX" ]; then
60                 # for irix use lmdd
61                 dd_cmd="lmdd"
62                 [ "$dio" = "1" ] && dd_cmd="$dd_cmd odirect=1"
63         else
64                 # for linux use dd
65                 dd_cmd="dd"
66                 [ "$dio" = "1" ] && dd_cmd="$dd_cmd oflag=direct"
67         fi
68         dd_cmd="$dd_cmd if=/dev/zero bs=${bsize} count=${blocks_in_file}"
69
70         local i=1
71         while [ $i -le $files ]; do
72                 $dd_cmd of=frame-${i} 2>&1 | grep -v records | grep -v secs
73                 i=`expr $i + 1`
74         done
75 }
76
77 _filter_agno()
78 {
79         # the ag number is in column 4 of xfs_bmap output
80         perl -ne '
81                 $ag = (split /\s+/)[4] ;
82                 if ($ag =~ /\d+/) {print "$ag "} ;
83         '
84 }
85
86 _get_stream_ags()
87 {
88         local directory_name=$1
89         local stream_ags=`xfs_bmap -vp ${directory_name}/* | _filter_agno`
90         echo $stream_ags
91 }
92
93 _check_for_dupes()
94 {
95         # check for duplicate numbers between two space seperated vars
96         local num_str_one=$1
97         local num_str_two=$2
98
99         local this_num_one
100         local this_num_two
101         for this_num_one in $num_str_one; do
102                 for this_num_two in $num_str_two; do
103                         if [ "$this_num_one" == "$this_num_two" ]; then
104                                 echo "duplicate AG $this_num_one found" \
105                                         >> $here/$seq.full
106                                 return 1
107                         fi
108                 done
109         done
110         return 0
111 }
112
113 _test_streams() {
114
115         echo "# testing $* ...."
116         local agcount="$1"
117         local agsize="$2" # in MB
118         local stream_count="$3"
119         local stream_files="$4"
120         local stream_file_size=`expr $5 \* 1024 \* 1024`
121         local use_iflag="$6"
122         local use_directio="$7"
123         local expected_result="$8"      # "fail" if failure is expected
124
125         local size=`expr $agsize \* 1024 \* 1024 \* $agcount`
126         _scratch_mkfs_xfs -dsize=$size,agcount=$agcount >/dev/null 2>&1 \
127                 || _fail "mkfs failed"
128
129         if [ "$use_iflag" = "0" -o "$HOSTOS" == "IRIX" ]; then
130                 # mount using filestreams mount option
131                 _scratch_mount "-o filestreams" \
132                         || _fail "filestreams mount failed"
133         else
134                 # test will set inode flag
135                 _scratch_mount || _fail "mount failed"
136         fi
137
138         cd $SCRATCH_MNT
139
140         # start $stream_count streams
141         # each stream writes ($stream_files x $stream_file_size)M
142         echo "# streaming"
143         local stream_pids=""
144         local stream_index=1
145         while [ $stream_index -le $stream_count ]; do
146                 _do_stream stream${stream_index}-dir $stream_files \
147                         $stream_file_size 1048576 $use_iflag $use_directio &
148                 stream_pids="$stream_pids $!"
149                 stream_index=`expr $stream_index + 1`
150         done
151
152         # wait for streams to finish
153         # XXX wait here not needed? -dgc
154         wait $stream_pids
155
156         # sync the buffered streams out in parallel
157         # _get_stream_ags does a xfs_bmap which syncs delayed allocations
158         echo "# sync AGs..."
159         local ag_sync_pids=""
160         stream_index=1
161         while [ $stream_index -le $stream_count ]; do
162                 _get_stream_ags stream${stream_index}-dir > /dev/null 2>&1 &
163                 ag_sync_pids="$ag_sync_pids $!"
164                 stream_index=`expr $stream_index + 1`
165         done
166
167         # wait for syncs to finish
168         wait $ag_sync_pids
169
170         # confirm streams are in seperate AGs
171         echo "# checking stream AGs..."
172         local this_stream_ags=""
173         local ags_seen=""
174         local num_streams_with_matching_ags=0
175         stream_index=1
176         while [ $stream_index -le $stream_count ]; do
177                 this_stream_ags=`_get_stream_ags stream${stream_index}-dir`
178                 echo "stream $stream_index AGs: $this_stream_ags" >> $here/$seq.full
179                 _check_for_dupes "$ags_seen" "$this_stream_ags"
180                 if [ $? -ne 0 ]; then
181                         # this stream is not in seperate AGs to previous streams
182                         num_streams_with_matching_ags=`expr $num_streams_with_matching_ags + 1`
183                 fi
184                 ags_seen="$ags_seen $this_stream_ags"
185                 stream_index=`expr $stream_index + 1`
186         done
187
188         _cleanup_streams_umount
189         if [ "$expected_result" != "fail" ]; then
190                 if [ $num_streams_with_matching_ags -eq 0 ]; then
191                         # all streams in seperate AGs, as expected
192                         echo "+ passed, streams are in seperate AGs"
193                 else
194                         # streams with matching AGs, should be seperate
195                         _fail "- failed, $num_streams_with_matching_ags streams with matching AGs"
196                 fi
197         else
198                 # expecting streams to have overlapped
199                 if [ $num_streams_with_matching_ags -eq 0 ]; then
200                         # all streams in seperate AGs, should have overlapped
201                         _fail "- streams are in seperate AGs, expected _matching_"
202                 else
203                         # streams with matching AGs, as expected
204                         echo "+ expected failure, matching AGs"
205                 fi
206         fi
207         return 0
208 }
209
210 _cleanup_streams_umount()
211 {
212         cd /
213         rm -rf ${SCRATCH_MNT}/stream*
214         umount $SCRATCH_DEV 2>/dev/null
215 }