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 # Disable the scratch rt device to avoid test failures relating to the
94 # rt bitmap consuming free space in our small data device and throwing
95 # off the filestreams allocator.
98 local size=`expr $agsize \* 1024 \* 1024 \* $agcount`
99 _scratch_mkfs_xfs -dsize=$size,agcount=$agcount >/dev/null 2>&1 \
100 || _fail "mkfs failed"
102 if [ "$use_iflag" = "0" ]; then
103 # mount using filestreams mount option
104 _try_scratch_mount "-o filestreams" \
105 || _fail "filestreams mount failed"
107 # test will set inode flag
113 # start $stream_count streams
114 # each stream writes ($stream_files x $stream_file_size)M
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`
125 # wait for streams to finish
126 # XXX wait here not needed? -dgc
129 # sync the buffered streams out in parallel
130 # _get_stream_ags does a xfs_bmap which syncs delayed allocations
132 local ag_sync_pids=""
134 while [ $stream_index -le $stream_count ]; do
135 _get_stream_ags stream${stream_index}-dir > /dev/null 2>&1 &
136 ag_sync_pids="$ag_sync_pids $!"
137 stream_index=`expr $stream_index + 1`
140 # wait for syncs to finish
143 # confirm streams are in seperate AGs
144 echo "# checking stream AGs..."
145 local this_stream_ags=""
147 local num_streams_with_matching_ags=0
149 while [ $stream_index -le $stream_count ]; do
150 this_stream_ags=`_get_stream_ags stream${stream_index}-dir`
151 echo "stream $stream_index AGs: $this_stream_ags" >> $seqres.full
152 _check_for_dupes "$ags_seen" "$this_stream_ags"
153 if [ $? -ne 0 ]; then
154 # this stream is not in seperate AGs to previous streams
155 num_streams_with_matching_ags=`expr $num_streams_with_matching_ags + 1`
157 ags_seen="$ags_seen $this_stream_ags"
158 stream_index=`expr $stream_index + 1`
161 _cleanup_streams_umount
162 if [ "$expected_result" != "fail" ]; then
163 if [ $num_streams_with_matching_ags -eq 0 ]; then
164 # all streams in seperate AGs, as expected
165 echo "+ passed, streams are in seperate AGs"
167 # streams with matching AGs, should be seperate
168 _fail "- failed, $num_streams_with_matching_ags streams with matching AGs"
171 # expecting streams to have overlapped
172 if [ $num_streams_with_matching_ags -eq 0 ]; then
173 # all streams in seperate AGs, should have overlapped
174 _fail "- streams are in seperate AGs, expected _matching_"
176 # streams with matching AGs, as expected
177 echo "+ expected failure, matching AGs"
183 _cleanup_streams_umount()
186 rm -rf ${SCRATCH_MNT}/stream*
187 _scratch_unmount 2>/dev/null