2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc. All Rights Reserved.
5 # FS QA Test No. xfs/011
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.
12 _begin_fstest auto freeze log metadata quick
14 # Import common functions.
16 # Override the default cleanup function.
19 $KILLALL_PROG -9 fsstress 2>/dev/null
22 _scratch_unmount 2>/dev/null
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()
30 devname=`_short_dev $SCRATCH_DEV`
31 attrpath="/sys/fs/xfs/$devname/log"
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
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))
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 }'`
48 if [ $cycle != $log_head_cycle ] ||
49 [ $bytes != $log_head_bytes ]
51 echo "$attr ($cycle:$bytes) does not match" \
52 "log_head_lsn ($log_head_cycle:$log_head_bytes)," \
53 "possible leak detected."
57 xfs_freeze -u $SCRATCH_MNT
60 # real QA test starts here
65 _require_xfs_sysfs $(_short_dev $TEST_DEV)/log
66 _require_command "$KILLALL_PROG" killall
68 echo "Silence is golden."
70 _scratch_mkfs_xfs >> $seqres.full 2>&1
73 _check_scratch_log_state
75 $FSSTRESS_PROG -d $SCRATCH_MNT/fsstress -n 9999999 -p 2 -S t \
76 >> $seqres.full 2>&1 &
79 while [ $iters -gt 0 ]; do
81 _check_scratch_log_state
85 $KILLALL_PROG $FSSTRESS_PROG