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 # Make sure $SCRATCH_MNT is unfreezed
20 xfs_freeze -u $SCRATCH_MNT 2>/dev/null
21 $KILLALL_PROG -9 fsstress 2>/dev/null
27 # Use the information exported by XFS to sysfs to determine whether the log has
28 # active reservations after a filesystem freeze.
29 _check_scratch_log_state()
31 devname=`_short_dev $SCRATCH_DEV`
32 attrpath="/sys/fs/xfs/$devname/log"
34 # freeze the fs to ensure data is synced and the log is flushed. this
35 # means no outstanding transactions, and thus no outstanding log
36 # reservations, should exist
37 xfs_freeze -f $SCRATCH_MNT
39 # the log head is exported in basic blocks and the log grant heads in
40 # bytes. convert the log head to bytes for precise comparison
41 log_head_cycle=`awk -F : '{ print $1 }' $attrpath/log_head_lsn`
42 log_head_bytes=`awk -F : '{ print $2 }' $attrpath/log_head_lsn`
43 log_head_bytes=$((log_head_bytes * 512))
45 for attr in "reserve_grant_head" "write_grant_head"; do
46 cycle=`cat $attrpath/$attr | awk -F : '{ print $1 }'`
47 bytes=`cat $attrpath/$attr | awk -F : '{ print $2 }'`
49 if [ $cycle != $log_head_cycle ] ||
50 [ $bytes != $log_head_bytes ]
52 echo "$attr ($cycle:$bytes) does not match" \
53 "log_head_lsn ($log_head_cycle:$log_head_bytes)," \
54 "possible leak detected."
58 xfs_freeze -u $SCRATCH_MNT
61 # real QA test starts here
66 _require_xfs_sysfs $(_short_dev $TEST_DEV)/log
67 _require_command "$KILLALL_PROG" killall
69 echo "Silence is golden."
71 _scratch_mkfs_xfs >> $seqres.full 2>&1
74 _check_scratch_log_state
76 $FSSTRESS_PROG -d $SCRATCH_MNT/fsstress -n 9999999 -p 2 -S t \
77 >> $seqres.full 2>&1 &
80 while [ $iters -gt 0 ]; do
82 _check_scratch_log_state
86 $KILLALL_PROG $FSSTRESS_PROG