overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / xfs / 442
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 442
6 #
7 # Force enable all XFS quotas, run fsstress until the fs runs out of
8 # space, and make sure the quotas are still correct when we're done.
9 # This is a general regression/stress test for numerous quota bugs with
10 # reflink and copy on write.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25         $KILLALL_PROG -9 fsstress > /dev/null 2>&1
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/quota
31 . ./common/filter
32 . ./common/reflink
33
34 # Modify as appropriate.
35 _supported_fs xfs
36 _supported_os Linux
37
38 _require_scratch_reflink
39 _require_quota
40 _require_command "$KILLALL_PROG" "killall"
41
42 rm -f $seqres.full
43
44 report_quota_blocks() {
45         $XFS_QUOTA_PROG -x -c "report $1" $SCRATCH_MNT | \
46                         awk '{x += $2;} END { print(x); }'
47 }
48
49 compare_quota_to_du() {
50         test $1 -eq $2 || echo "$3 quota $2 blocks does not match du $1 blocks?"
51 }
52
53 # Make sure the user/group/project quota block counts match the du output.
54 # This ensures that we did the quota accounting correctly and that we're
55 # accurately reporting cow preallocation blocks in stat.
56 check_quota_du_blocks() {
57         sync
58         #$XFS_QUOTA_PROG -x -c 'report' $SCRATCH_MNT >> $seqres.full
59         du_rep=$(du -ks $SCRATCH_MNT | awk '{print $1}')
60         u_rep=$(report_quota_blocks -u)
61         g_rep=$(report_quota_blocks -g)
62         p_rep=$(report_quota_blocks -p)
63
64         compare_quota_to_du $du_rep $u_rep "user"
65         compare_quota_to_du $du_rep $g_rep "group"
66         compare_quota_to_du $du_rep $p_rep "project"
67 }
68
69 echo "Format and fsstress"
70
71 _qmount_option "usrquota,grpquota,prjquota"
72 # We use a small volume so that we hit ENOSPC.  This is critical for
73 # regression testing a bug in the directio write code that could result in fs
74 # corruption ("xfs: check reflink allocation mappings").
75 #
76 # This started as a test for quota accounting problems ("xfs: treat CoW fork
77 # operations as delalloc for quota accounting") and ("xfs: call
78 # xfs_qm_dqattach before performing reflink operations") though each of those
79 # tests now have separate faster-running regression tests.
80 _scratch_mkfs_sized $((1600 * 1048576)) > $seqres.full 2>&1
81 _scratch_mount >> $seqres.full 2>&1
82
83 nr_cpus=$((LOAD_FACTOR * 4))
84 nr_ops=$((25000 * nr_cpus * TIME_FACTOR))
85 $FSSTRESS_PROG $FSSTRESS_AVOID -w -d $SCRATCH_MNT -n $nr_ops -p $nr_cpus >> $seqres.full
86
87 echo "Check quota before remount"
88 check_quota_du_blocks
89
90 # Clear out all the preallocations before we quotacheck.
91 # The count comparison in _check_quota_usage will be unhappy if we don't
92 # manage to clean out all the cow preallocations before the remount.
93 _scratch_unmount
94 _scratch_mount
95
96 # Make sure the usage doesn't change after quotacheck.
97 echo "Check quota after remount"
98 _check_quota_usage
99
100 check_quota_du_blocks
101
102 # success, all done
103 status=0
104 exit