3 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it would be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write the Free Software Foundation,
16 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 # Checks that given_value is in range of correct_value +/- tolerance.
23 # Tolerance can be an absolute value or a percentage of the correct value
24 # (see examples with tolerances below).
25 # Outputs suitable message to stdout if it's not in range.
27 # A verbose option, -v, may be used as the LAST argument
30 # foo: 0.0298 = 0.03 +/- 5%
31 # _within_tolerance "foo" 0.0298 0.03 5%
33 # foo: 0.0298 = 0.03 +/- 0.01
34 # _within_tolerance "foo" 0.0298 0.03 0.01
36 # foo: 0.0298 = 0.03 -0.01 +0.002
37 # _within_tolerance "foo" 0.0298 0.03 0.01 0.002
39 # foo: verbose output of 0.0298 = 0.03 +/- 5%
40 # _within_tolerance "foo" 0.0298 0.03 5% -v
51 # maxtol arg is optional
52 # verbose arg is optional
64 [ "$6" = "-v" ] && _verbose=1
67 # find min with or without %
68 _mintolerance=`echo $_mintol | sed -e 's/%//'`
69 if [ $_mintol = $_mintolerance ]
71 _min=`echo "scale=5; $_correct_val-$_mintolerance" | bc`
73 _min=`echo "scale=5; $_correct_val-$_mintolerance*0.01*$_correct_val" | bc`
76 # find max with or without %
77 _maxtolerance=`echo $_maxtol | sed -e 's/%//'`
78 if [ $_maxtol = $_maxtolerance ]
80 _max=`echo "scale=5; $_correct_val+$_maxtolerance" | bc`
82 _max=`echo "scale=5; $_correct_val+$_maxtolerance*0.01*$_correct_val" | bc`
85 $_debug && echo "min = $_min"
86 $_debug && echo "max = $_max"
90 if ($_min <= $_given_val) 1;
91 if ($_min > $_given_val) 0;
96 if ($_given_val <= $_max) 1;
97 if ($_given_val > $_max) 0;
100 _above_min=`bc <$tmp.bc.1`
101 _below_max=`bc <$tmp.bc.2`
105 _in_range=`expr $_above_min \& $_below_max`
107 # fix up min, max precision for output
108 # can vary for 5.3, 6.2
110 # remove any trailing zeroes from min, max if they have fractional parts
111 _min=`echo $_min | sed -e '/\./s/0*$//' -e 's/\.$//'`
112 _max=`echo $_max | sed -e '/\./s/0*$//' -e 's/\.$//'`
114 if [ $_in_range -eq 1 ]
116 [ $_verbose -eq 1 ] && echo $_name is in range
119 [ $_verbose -eq 1 ] && echo $_name has value of $_given_val
120 [ $_verbose -eq 1 ] && echo $_name is NOT in range $_min .. $_max
130 -e 's/[A-Z][a-z][a-z] [A-z][a-z][a-z] *[0-9][0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]$/DATE/'
133 # prints filtered output on stdout, values (use eval) on stderr
134 # Non XFS filesystems always return a 4k block size and a 256 byte inode.
142 perl -e 'print STDERR "dbsize=4096\nisize=256\n"'
146 echo "_fs_has_crcs=0" >&2
149 if (/^meta-data=([\w,|\/.-]+)\s+isize=(\d+)\s+agcount=(\d+), agsize=(\d+) blks/) {
150 print STDERR "ddev=$1\nisize=$2\nagcount=$3\nagsize=$4\n";
151 print STDOUT "meta-data=DDEV isize=XXX agcount=N, agsize=XXX blks\n";
153 if (/^\s+=\s+sectsz=(\d+)\s+attr=(\d+)/) {
154 print STDERR "sectsz=$1\nattr=$2\n";
156 if (/^\s+=\s+crc=(\d)/) {
157 print STDERR "_fs_has_crcs=$1\n";
159 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+), imaxpct=(\d+)/) {
160 print STDERR "dbsize=$1\ndblocks=$2\nimaxpct=$3\n";
161 print STDOUT "data = bsize=XXX blocks=XXX, imaxpct=PCT\n";
163 if (/^\s+=\s+sunit=(\d+)\s+swidth=(\d+) blks/) {
164 print STDERR "sunit=$1\nswidth=$2\nunwritten=1\n";
165 print STDOUT " = sunit=XXX swidth=XXX, unwritten=X\n";
167 if (/^naming\s+=version\s+(\d+)\s+bsize=(\d+)/) {
168 print STDERR "dirversion=$1\ndirbsize=$2\n";
169 print STDOUT "naming =VERN bsize=XXX\n";
171 if (/^log\s+=(internal log|[\w|\/.-]+)\s+bsize=(\d+)\s+blocks=(\d+),\s+version=(\d+)/ ||
172 /^log\s+=(internal log|[\w|\/.-]+)\s+bsize=(\d+)\s+blocks=(\d+)/) {
173 print STDERR "ldev=\"$1\"\nlbsize=$2\nlblocks=$3\nlversion=$4\n";
174 print STDOUT "log =LDEV bsize=XXX blocks=XXX\n";
176 if (/^\s+=\s+sectsz=(\d+)\s+sunit=(\d+) blks/) {
177 print STDERR "logsectsz=$1\nlogsunit=$2\n\n";
179 if (/^realtime\s+=([\w|\/.-]+)\s+extsz=(\d+)\s+blocks=(\d+), rtextents=(\d+)/) {
180 print STDERR "rtdev=$1\nrtextsz=$2\nrtblocks=$3\nrtextents=$4\n";
181 print STDOUT "realtime =RDEV extsz=XXX blocks=XXX, rtextents=XXX\n";
186 # prints the bits we care about in growfs
191 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+), imaxpct=(\d+)/) {
192 print "xfs_growfs --BlockSize=$1 --Blocks=$2\n";
202 /records in/ { next }
203 /records out/ { next }
204 /No space left on device/ { print " !!! disk full (expected)"
212 perl -ne 'if (/.*:(.*)/) {
213 if ( "$last_line" ne "$1" ) { print "$_"; $first_match=1; }
214 elsif ( $first_match==1 ) { print "*\n"; $first_match=0; }
218 print $_; $last_line=$_;
224 # Apart from standard numeric values, we also filter out 'inf' and 'nan'
225 # which can result from division in some cases
226 sed -e "s/[0-9/.]* [GMKiBbytes]*, [0-9]* ops\; [0-9/:. sec]* ([infa0-9/.]* [EPGMKiBbytes]*\/sec and [infa0-9/.]* ops\/sec)/XXX Bytes, X ops\; XX:XX:XX.X (XXX YYY\/sec and XXX ops\/sec)/"
229 # stderr filter for xfs_io to handle change of error output format (e.g.
230 # pwrite64 -> pwrite).
231 _filter_xfs_io_error()
233 sed -e "s/^\(.*\)64\(: .*$\)/\1\2/"
236 _filter_xfs_io_unique()
238 common_line_filter | _filter_xfs_io
241 _filter_xfs_io_units_modified()
246 $AWK_PROG -v unit="$UNIT" -v unit_size=$UNIT_SIZE '
248 split($2, bytes, "/")
250 bytes_written = strtonum(bytes[1])
252 offset = strtonum($NF)
254 unit_start = offset / unit_size
255 unit_start = int(unit_start)
256 unit_end = (offset + bytes_written - 1) / unit_size
257 unit_end = int(unit_end)
259 printf("%ss modified: [%d - %d]\n", unit, unit_start, unit_end)
266 _filter_xfs_io_blocks_modified()
268 BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
270 _filter_xfs_io_units_modified "Block" $BLOCK_SIZE
273 _filter_xfs_io_pages_modified()
275 PAGE_SIZE=$(get_page_size)
277 _filter_xfs_io_units_modified "Page" $PAGE_SIZE
283 if ( echo $TEST_DIR | grep -q $TEST_DEV ); then
284 # TEST_DEV is substr of TEST_DIR (e.g. /mnt and /mnt/ovl-mnt)
285 # substitute TEST_DIR first
286 sed -e "s,$TEST_DIR,TEST_DIR,g" \
287 -e "s,$TEST_DEV,TEST_DEV,g"
289 # TEST_DIR maybe a substr of TEST_DIR (e.g. /vdc and /dev/vdc)
290 # substitute TEST_DEV first
291 sed -e "s,$TEST_DEV,TEST_DEV,g" \
292 -e "s,$TEST_DIR,TEST_DIR,g"
298 if ( echo $SCRATCH_MNT | grep -q $SCRATCH_DEV ); then
299 # SCRATCH_DEV is substr of SCRATCH_MNT
300 sed -e "s,$SCRATCH_MNT,SCRATCH_MNT,g" \
301 -e "s,$SCRATCH_DEV,SCRATCH_DEV,g" \
304 # SCRATCH_MNT maybe a substr of SCRATCH_DEV
305 sed -e "s,$SCRATCH_DEV,SCRATCH_DEV,g" \
306 -e "s,$SCRATCH_MNT,SCRATCH_MNT,g" \
311 # Turn any device in the scratch pool into SCRATCH_DEV
312 _filter_scratch_pool()
314 FILTER_STRINGS=`echo $SCRATCH_DEV_POOL | sed -e 's/\s\+/\\\|/g'`
315 sed -e "s,$FILTER_STRINGS,SCRATCH_DEV,g"
325 # Long dev name might be split onto its own line; last
326 # seds remove that newline if present
327 _filter_scratch | _filter_test_dir | _filter_spaces | \
328 sed -e 'N;s/SCRATCH_DEV\n/SCRATCH_DEV/g' | \
329 sed -e 'N;s/TEST_DEV\n/TEST_DEV/g'
332 _filter_project_quota()
334 # Project ID 0 is always present on disk but was not reported
335 # until the GETNEXTQUOTA ioctl came into use. Filter it out.
336 # But if you specify a name for ID 0, that means you want to
337 # deal with it by yourself, this function won't filter it out.
338 _filter_quota | grep -v "^\#0 \|^(null) "
341 # Account for different "ln" failure messages
344 sed -e "s,\(creating symbolic link .*\) to .*: ,\1: ," \
345 -e "s,failed to create,creating,"
348 # If given an arg, filter *that* UUID string
349 # Otherwise look for something that looks like a generic UUID
354 sed -e "s/\(uuid[ :=]\+\) $UUID/\1 <EXACTUUID>/i"
356 sed -e "s/\(uuid[ :=]\+\) [0-9a-f-][0-9a-f-]*/\1 <UUID>/ig"
360 # In mixed group the added disks may have zero used size
363 sed -e "s/0\.00/<SIZE>/g"
366 # Filter out sizes like 6.14MB etc
369 sed -e "s/[0-9\.]\+\s\?[b|k|m|g|t][i]\?[b]\?/<SIZE>/ig"
372 # Convert string read from stdin like 128K to bytes and print it to stdout
373 _filter_size_to_bytes()
376 suffix=${size:${#size}-1}
380 m|M) mul=$((1024*1024)) ;;
381 g|G) mul=$((1024*1024*1024)) ;;
382 t|T) mul=$((1024*1024*1024*1024)) ;;
384 echo $((${size:0:${#size}-1}*$mul))
387 # Print trimmed bytes of fstrim
388 # Starting from util-linux v2.23 fstrim usees human readable sizes in
392 egrep -o "[0-9]+ bytes" | $AWK_PROG '{print $1}'
395 # Older mount output referred to "block device" when mounting RO devices
396 # It's gone in newer versions
398 sed -e "s/mount: block device/mount:/g" \
399 -e "s/mount: cannot mount block device/mount: cannot mount/g"
404 BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
405 $AWK_PROG -v block_size=$BLOCK_SIZE '
407 offset = strtonum("0"$1);
408 $1 = sprintf("%o", offset / block_size);
415 # Remove quotes from failed mknod calls. Starting with Coreutils v8.25,
416 # mknod errors print unquoted filenames
419 sed -e "s/mknod: [\`']\(.*\)': File exists/mknod: \1: File exists/"
424 sed -e '/^lost+found$/d'
427 # make sure this script returns success