05cffe98456d2b37323b3111f0f82fcf541103df
[xfstests-dev.git] / tests / xfs / 442
1 #! /bin/bash
2 # FS QA Test No. 442
3 #
4 # Force enable all XFS quotas, run fsstress until the fs runs out of
5 # space, and make sure the quotas are still correct when we're done.
6 # This is a general regression/stress test for numerous quota bugs with
7 # reflink and copy on write.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2018 Oracle, Inc.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         cd /
39         rm -f $tmp.*
40         $KILLALL_PROG -9 fsstress > /dev/null 2>&1
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/quota
46 . ./common/filter
47 . ./common/reflink
48
49 # Modify as appropriate.
50 _supported_fs xfs
51 _supported_os Linux
52
53 _require_scratch_reflink
54 _require_quota
55 _require_command "$KILLALL_PROG" "killall"
56
57 rm -f $seqres.full
58
59 report_quota_blocks() {
60         $XFS_QUOTA_PROG -x -c "report $1" $SCRATCH_MNT | \
61                         awk '{x += $2;} END { print(x); }'
62 }
63
64 compare_quota_to_du() {
65         test $1 -eq $2 || echo "$3 quota $2 blocks does not match du $1 blocks?"
66 }
67
68 # Make sure the user/group/project quota block counts match the du output.
69 # This ensures that we did the quota accounting correctly and that we're
70 # accurately reporting cow preallocation blocks in stat.
71 check_quota_du_blocks() {
72         sync
73         #$XFS_QUOTA_PROG -x -c 'report' $SCRATCH_MNT >> $seqres.full
74         du_rep=$(du -ks $SCRATCH_MNT | awk '{print $1}')
75         u_rep=$(report_quota_blocks -u)
76         g_rep=$(report_quota_blocks -g)
77         p_rep=$(report_quota_blocks -p)
78
79         compare_quota_to_du $du_rep $u_rep "user"
80         compare_quota_to_du $du_rep $g_rep "group"
81         compare_quota_to_du $du_rep $p_rep "project"
82 }
83
84 echo "Format and fsstress"
85
86 _qmount_option "usrquota,grpquota,prjquota"
87 # We use a small volume so that we hit ENOSPC.  This is critical for
88 # regression testing a bug in the directio write code that could result in fs
89 # corruption ("xfs: check reflink allocation mappings").
90 #
91 # This started as a test for quota accounting problems ("xfs: treat CoW fork
92 # operations as delalloc for quota accounting") and ("xfs: call
93 # xfs_qm_dqattach before performing reflink operations") though each of those
94 # tests now have separate faster-running regression tests.
95 _scratch_mkfs_sized $((1600 * 1048576)) > $seqres.full 2>&1
96 _scratch_mount >> $seqres.full 2>&1 || _fail "mount failed..."
97
98 nr_cpus=$((LOAD_FACTOR * 4))
99 nr_ops=$((25000 * nr_cpus * TIME_FACTOR))
100 $FSSTRESS_PROG $FSSTRESS_AVOID -w -d $SCRATCH_MNT -n $nr_ops -p $nr_cpus >> $seqres.full
101
102 echo "Check quota before remount"
103 check_quota_du_blocks
104
105 # Clear out all the preallocations before we quotacheck.
106 # The count comparison in _check_quota_usage will be unhappy if we don't
107 # manage to clean out all the cow preallocations before the remount.
108 _scratch_unmount
109 _scratch_mount
110
111 # Make sure the usage doesn't change after quotacheck.
112 echo "Check quota after remount"
113 _check_quota_usage
114
115 check_quota_du_blocks
116
117 # success, all done
118 status=0
119 exit