generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 011
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. xfs/011
6 #
7 # Test the xfs log reservation mechanism for leaks. Run an fsstress workload to
8 # include a variety of fs operations, freeze the filesystem and verify that
9 # there are no oustanding reservations against the log.
10 #
11 . ./common/preamble
12 _begin_fstest auto freeze log metadata quick
13
14 # Import common functions.
15
16 # Override the default cleanup function.
17 _cleanup()
18 {
19         $KILLALL_PROG -9 fsstress 2>/dev/null
20         wait
21         cd /
22         _scratch_unmount 2>/dev/null
23         rm -f $tmp.*
24 }
25
26 # Use the information exported by XFS to sysfs to determine whether the log has
27 # active reservations after a filesystem freeze.
28 _check_scratch_log_state()
29 {
30         devname=`_short_dev $SCRATCH_DEV`
31         attrpath="/sys/fs/xfs/$devname/log"
32
33         # freeze the fs to ensure data is synced and the log is flushed. this
34         # means no outstanding transactions, and thus no outstanding log
35         # reservations, should exist
36         xfs_freeze -f $SCRATCH_MNT
37
38         # the log head is exported in basic blocks and the log grant heads in
39         # bytes. convert the log head to bytes for precise comparison
40         log_head_cycle=`awk -F : '{ print $1 }' $attrpath/log_head_lsn`
41         log_head_bytes=`awk -F : '{ print $2 }' $attrpath/log_head_lsn`
42         log_head_bytes=$((log_head_bytes * 512))
43
44         for attr in "reserve_grant_head" "write_grant_head"; do
45                 cycle=`cat $attrpath/$attr | awk -F : '{ print $1 }'`
46                 bytes=`cat $attrpath/$attr | awk -F : '{ print $2 }'`
47
48                 if [ $cycle != $log_head_cycle ] ||
49                    [ $bytes != $log_head_bytes ]
50                 then
51                         echo "$attr ($cycle:$bytes) does not match" \
52                                 "log_head_lsn ($log_head_cycle:$log_head_bytes)," \
53                                 "possible leak detected."
54                 fi
55         done
56
57         xfs_freeze -u $SCRATCH_MNT
58 }
59
60 # real QA test starts here
61 _supported_fs xfs
62
63 _require_scratch
64 _require_freeze
65 _require_xfs_sysfs $(_short_dev $TEST_DEV)/log
66 _require_command "$KILLALL_PROG" killall
67
68 echo "Silence is golden."
69
70 _scratch_mkfs_xfs >> $seqres.full 2>&1
71 _scratch_mount
72
73 _check_scratch_log_state
74
75 $FSSTRESS_PROG -d $SCRATCH_MNT/fsstress -n 9999999 -p 2 -S t \
76         >> $seqres.full 2>&1 &
77
78 iters=5
79 while [ $iters -gt 0 ]; do
80         sleep 3
81         _check_scratch_log_state
82         iters=$((iters - 1))
83 done
84
85 $KILLALL_PROG $FSSTRESS_PROG
86 wait
87
88 _scratch_unmount
89
90 status=0
91 exit