2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2007 Silicon Graphics, Inc. All Rights Reserved.
5 # Core of filestreams tests.
7 _check_filestreams_support()
9 [ -f /proc/sys/fs/xfs/filestream_centisecs ]
12 _set_stream_timeout_centisecs()
14 echo $1 > /proc/sys/fs/xfs/filestream_centisecs
19 local directory_name=$1
25 local blocks_in_file=`expr $file_size / $bsize`
28 if [ "$iflag" = "1" ]; then
29 $XFS_IO_PROG -x -c "chattr +S" $directory_name \
30 || _fail "chattr of filestream flag"
35 [ "$dio" = "1" ] && dd_cmd="$dd_cmd oflag=direct"
36 dd_cmd="$dd_cmd if=/dev/zero bs=${bsize} count=${blocks_in_file}"
39 while [ $i -le $files ]; do
40 $dd_cmd of=frame-${i} 2>&1 | grep -v records | grep -v secs
47 # the ag number is in column 4 of xfs_bmap output
49 $ag = (split /\s+/)[4] ;
50 if ($ag =~ /\d+/) {print "$ag "} ;
56 local directory_name=$1
57 local stream_ags=`xfs_bmap -vp ${directory_name}/* | _filter_agno`
63 # check for duplicate numbers between two space seperated vars
69 for this_num_one in $num_str_one; do
70 for this_num_two in $num_str_two; do
71 if [ "$this_num_one" == "$this_num_two" ]; then
72 echo "duplicate AG $this_num_one found" \
83 echo "# testing $* ...."
85 local agsize="$2" # in MB
86 local stream_count="$3"
87 local stream_files="$4"
88 local stream_file_size=`expr $5 \* 1024 \* 1024`
90 local use_directio="$7"
91 local expected_result="$8" # "fail" if failure is expected
93 local size=`expr $agsize \* 1024 \* 1024 \* $agcount`
94 _scratch_mkfs_xfs -dsize=$size,agcount=$agcount >/dev/null 2>&1 \
95 || _fail "mkfs failed"
97 if [ "$use_iflag" = "0" ]; then
98 # mount using filestreams mount option
99 _try_scratch_mount "-o filestreams" \
100 || _fail "filestreams mount failed"
102 # test will set inode flag
108 # start $stream_count streams
109 # each stream writes ($stream_files x $stream_file_size)M
113 while [ $stream_index -le $stream_count ]; do
114 _do_stream stream${stream_index}-dir $stream_files \
115 $stream_file_size 1048576 $use_iflag $use_directio &
116 stream_pids="$stream_pids $!"
117 stream_index=`expr $stream_index + 1`
120 # wait for streams to finish
121 # XXX wait here not needed? -dgc
124 # sync the buffered streams out in parallel
125 # _get_stream_ags does a xfs_bmap which syncs delayed allocations
127 local ag_sync_pids=""
129 while [ $stream_index -le $stream_count ]; do
130 _get_stream_ags stream${stream_index}-dir > /dev/null 2>&1 &
131 ag_sync_pids="$ag_sync_pids $!"
132 stream_index=`expr $stream_index + 1`
135 # wait for syncs to finish
138 # confirm streams are in seperate AGs
139 echo "# checking stream AGs..."
140 local this_stream_ags=""
142 local num_streams_with_matching_ags=0
144 while [ $stream_index -le $stream_count ]; do
145 this_stream_ags=`_get_stream_ags stream${stream_index}-dir`
146 echo "stream $stream_index AGs: $this_stream_ags" >> $seqres.full
147 _check_for_dupes "$ags_seen" "$this_stream_ags"
148 if [ $? -ne 0 ]; then
149 # this stream is not in seperate AGs to previous streams
150 num_streams_with_matching_ags=`expr $num_streams_with_matching_ags + 1`
152 ags_seen="$ags_seen $this_stream_ags"
153 stream_index=`expr $stream_index + 1`
156 _cleanup_streams_umount
157 if [ "$expected_result" != "fail" ]; then
158 if [ $num_streams_with_matching_ags -eq 0 ]; then
159 # all streams in seperate AGs, as expected
160 echo "+ passed, streams are in seperate AGs"
162 # streams with matching AGs, should be seperate
163 _fail "- failed, $num_streams_with_matching_ags streams with matching AGs"
166 # expecting streams to have overlapped
167 if [ $num_streams_with_matching_ags -eq 0 ]; then
168 # all streams in seperate AGs, should have overlapped
169 _fail "- streams are in seperate AGs, expected _matching_"
171 # streams with matching AGs, as expected
172 echo "+ expected failure, matching AGs"
178 _cleanup_streams_umount()
181 rm -rf ${SCRATCH_MNT}/stream*
182 _scratch_unmount 2>/dev/null