common/xfs: refactor commands to select a particular xfs backing device
[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 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18
19 # get standard environment, filters and checks
20 . ./common/rc
21
22 _cleanup()
23 {
24         $KILLALL_PROG -9 fsstress 2>/dev/null
25         wait
26         cd /
27         _scratch_unmount 2>/dev/null
28         rm -f $tmp.*
29 }
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 # Use the information exported by XFS to sysfs to determine whether the log has
33 # active reservations after a filesystem freeze.
34 _check_scratch_log_state()
35 {
36         devname=`_short_dev $SCRATCH_DEV`
37         attrpath="/sys/fs/xfs/$devname/log"
38
39         # freeze the fs to ensure data is synced and the log is flushed. this
40         # means no outstanding transactions, and thus no outstanding log
41         # reservations, should exist
42         xfs_freeze -f $SCRATCH_MNT
43
44         # the log head is exported in basic blocks and the log grant heads in
45         # bytes. convert the log head to bytes for precise comparison
46         log_head_cycle=`awk -F : '{ print $1 }' $attrpath/log_head_lsn`
47         log_head_bytes=`awk -F : '{ print $2 }' $attrpath/log_head_lsn`
48         log_head_bytes=$((log_head_bytes * 512))
49
50         for attr in "reserve_grant_head" "write_grant_head"; do
51                 cycle=`cat $attrpath/$attr | awk -F : '{ print $1 }'`
52                 bytes=`cat $attrpath/$attr | awk -F : '{ print $2 }'`
53
54                 if [ $cycle != $log_head_cycle ] ||
55                    [ $bytes != $log_head_bytes ]
56                 then
57                         echo "$attr ($cycle:$bytes) does not match" \
58                                 "log_head_lsn ($log_head_cycle:$log_head_bytes)," \
59                                 "possible leak detected."
60                 fi
61         done
62
63         xfs_freeze -u $SCRATCH_MNT
64 }
65
66 # real QA test starts here
67 _supported_fs xfs
68
69 _require_scratch
70 _require_freeze
71 _require_xfs_sysfs $(_short_dev $TEST_DEV)/log
72 _require_command "$KILLALL_PROG" killall
73
74 rm -f $seqres.full
75
76 echo "Silence is golden."
77
78 _scratch_mkfs_xfs >> $seqres.full 2>&1
79 _scratch_mount
80
81 _check_scratch_log_state
82
83 $FSSTRESS_PROG -d $SCRATCH_MNT/fsstress -n 9999999 -p 2 -S t \
84         >> $seqres.full 2>&1 &
85
86 iters=5
87 while [ $iters -gt 0 ]; do
88         sleep 3
89         _check_scratch_log_state
90         iters=$((iters - 1))
91 done
92
93 $KILLALL_PROG $FSSTRESS_PROG
94 wait
95
96 _scratch_unmount
97
98 status=0
99 exit