A recent change to XFSQA to resolve mkfs option conflicts means mkfs can be run twice...
[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 _do_stream()
9 {
10         local directory_name=$1
11         local files=$2
12         local file_size=$3
13         local bsize=$4
14         local iflag=$5
15         local dio=$6
16
17         local count=`expr $file_size / $bsize`
18         mkdir $directory_name
19         if [ "$iflag" = "1" ]; then
20                 $XFS_IO_PROG -x -c "chattr +S" $directory_name \
21                         || _fail "chattr of filestream flag"
22         fi
23         cd $directory_name
24         local i=1
25         local oflags=""
26         if [ "$dio" = "1" ]; then
27                 oflags="oflag=direct"
28         fi
29         while [ $i -le $files ]; do
30                 dd if=/dev/zero of=frame-${i} $oflags \
31                         bs=$bsize count=$count >/dev/null 2>&1
32                 i=`expr $i + 1`
33         done
34 }
35
36 _filter_agno()
37 {
38         # the ag number is in column 4 of xfs_bmap output
39         perl -ne '
40                 $ag = (split /\s+/)[4] ;
41                 if ($ag =~ /\d+/) {print "$ag "} ;
42         '
43 }
44
45 _get_stream_ags()
46 {
47         local directory_name=$1
48         local stream_ags=`xfs_bmap -vp ${directory_name}/* | _filter_agno`
49         echo $stream_ags
50 }
51
52 _check_for_dupes()
53 {
54         # check for duplicate numbers between two space seperated vars
55         local num_str_one=$1
56         local num_str_two=$2
57
58         local this_num_one
59         local this_num_two
60         for this_num_one in $num_str_one; do
61                 for this_num_two in $num_str_two; do
62                         if [ "$this_num_one" == "$this_num_two" ]; then
63                                 echo "duplicate AG $this_num_one found" \
64                                         >> $here/$seq.full
65                                 return 1
66                         fi
67                 done
68         done
69         return 0
70 }
71
72 rm -f $here/$seq.full
73
74 # test that filestreams are available
75 umount $SCRATCH_MNT > /dev/null 2>&1
76
77 _scratch_mkfs_xfs > /dev/null 2>&1 \
78         || _fail "mkfs failed"
79
80 _scratch_mount "-o filestreams" \
81         || _notrun "filestreams mount not available"
82
83 sync
84 umount $SCRATCH_MNT > /dev/null 2>&1
85
86 _test_streams() {
87
88         echo "# testing $* ...."
89         local agcount="$1"
90         local agsize="$2" # in MB
91         local stream_count="$3"
92         local stream_files="$4"
93         local stream_file_size=`expr $5 \* 1024 \* 1024`
94         local use_iflag="$6"
95         local use_directio="$7"
96         local expected_result="$8"
97
98         local size=`expr $agsize \* 1024 \* 1024 \* $agcount`
99         _scratch_mkfs_xfs -dsize=$size,agcount=$agcount >/dev/null 2>&1 \
100                 || _fail "mkfs failed"
101
102         if [ "$use_iflag" = "0" ]; then
103                 # mount using filestreams mount option
104                 _scratch_mount "-o filestreams" \
105                         || _notrun "filestreams mount not available"
106         else
107                 # test will set inode flag
108                 _scratch_mount
109         fi
110
111
112         cd $SCRATCH_MNT
113
114         # start four streams, each writing 24m (8 x 3m files)
115         echo "# streaming"
116         stream_pids=""
117         stream_index=1
118         while [ $stream_index -le $stream_count ]; do
119                 _do_stream stream${stream_index}-dir $stream_files \
120                         $stream_file_size 1048576 $use_iflag $use_directio &
121                 stream_pids="$stream_pids $!"
122                 stream_index=`expr $stream_index + 1`
123         done
124
125         # wait for streams to finish
126         # XXX wait here not needed? -dgc
127         wait $stream_pids
128
129         # sync the buffered streams out in parallel
130         echo "# sync AGs..."
131         stream_pids=""
132         stream_index=1
133         while [ $stream_index -le $stream_count ]; do
134                 _get_stream_ags stream${stream_index}-dir > /dev/null 2>&1 &
135                 stream_pids="$stream_pids $!"
136                 stream_index=`expr $stream_index + 1`
137         done
138
139         # wait for streams to finish
140         wait $stream_pids
141
142         # confirm streams are in seperate AGs
143         echo "# checking stream AGs..."
144         ags_seen=""
145         stream_index=1
146         while [ $stream_index -le $stream_count ]; do
147                 _get_stream_ags stream${stream_index}-dir > $tmp.${stream_index} &
148                 this_stream_ags=`_get_stream_ags stream${stream_index}-dir`
149                 echo "stream $stream_index AGs: $this_stream_ags" >> $here/$seq.full
150                 _check_for_dupes "$ags_seen" "$this_stream_ags"
151                 if [ $? -ne 0 ]; then
152                         if [ "$expected_result" = "fail" ]; then
153                                 echo "+ expected failure, matching AGs"
154                                 expected_result="failed"
155                                 break
156                         else
157                                 _fail "- failed, streams with matching AGs"
158                         fi
159                 fi
160                 ags_seen="$ags_seen $this_stream_ags"
161                 stream_index=`expr $stream_index + 1`
162         done
163         if [ "$expected_result" != "failed" ]; then
164                 echo "+ passed, streams are in seperate AGs"
165         fi
166         cd $here
167         umount $SCRATCH_MNT
168 }