197752c74ec824758d643550a35412a439417266
[xfstests-dev.git] / tests / xfs / 011
1 #!/bin/bash
2 # FS QA Test No. xfs/011
3 #
4 # Test the xfs log reservation mechanism for leaks. Run an fsstress workload to
5 # include a variety of fs operations, freeze the filesystem and verify that
6 # there are no oustanding reservations against the log.
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34
35 # get standard environment, filters and checks
36 . ./common/rc
37
38 _cleanup()
39 {
40         killall -9 fsstress 2>/dev/null
41         wait
42         cd /
43         umount $SCRATCH_MNT 2>/dev/null
44         rm -f $tmp.*
45 }
46 trap "_cleanup; exit \$status" 0 1 2 3 15
47
48 # Use the information exported by XFS to sysfs to determine whether the log has
49 # active reservations after a filesystem freeze.
50 _check_scratch_log_state()
51 {
52         devname=`_short_dev $SCRATCH_DEV`
53         attrpath="/sys/fs/xfs/$devname/log"
54
55         # freeze the fs to ensure data is synced and the log is flushed. this
56         # means no outstanding transactions, and thus no outstanding log
57         # reservations, should exist
58         xfs_freeze -f $SCRATCH_MNT
59
60         # the log head is exported in basic blocks and the log grant heads in
61         # bytes. convert the log head to bytes for precise comparison
62         log_head_cycle=`awk -F : '{ print $1 }' $attrpath/log_head_lsn`
63         log_head_bytes=`awk -F : '{ print $2 }' $attrpath/log_head_lsn`
64         log_head_bytes=$((log_head_bytes * 512))
65
66         for attr in "reserve_grant_head" "write_grant_head"; do
67                 cycle=`cat $attrpath/$attr | awk -F : '{ print $1 }'`
68                 bytes=`cat $attrpath/$attr | awk -F : '{ print $2 }'`
69
70                 if [ $cycle != $log_head_cycle ] ||
71                    [ $bytes != $log_head_bytes ]
72                 then
73                         echo "$attr ($cycle:$bytes) does not match" \
74                                 "log_head_lsn ($log_head_cycle:$log_head_bytes)," \
75                                 "possible leak detected."
76                 fi
77         done
78
79         xfs_freeze -u $SCRATCH_MNT
80 }
81
82 # real QA test starts here
83 _supported_fs xfs
84 _supported_os Linux
85
86 _require_scratch
87 _require_freeze
88 _require_xfs_sysfs $(_short_dev $TEST_DEV)/log
89
90 rm -f $seqres.full
91
92 echo "Silence is golden."
93
94 _scratch_mkfs_xfs >> $seqres.full 2>&1
95 _scratch_mount
96
97 _check_scratch_log_state
98
99 $FSSTRESS_PROG -d $SCRATCH_MNT/fsstress -n 9999999 -p 2 -S t \
100         >> $seqres.full 2>&1 &
101
102 iters=5
103 while [ $iters -gt 0 ]; do
104         sleep 3
105         _check_scratch_log_state
106         iters=$((iters - 1))
107 done
108
109 killall $FSSTRESS_PROG
110 wait
111
112 umount $SCRATCH_MNT
113
114 status=0
115 exit