generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
13 _begin_fstest auto stress clone quota
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18         cd /
19         rm -f $tmp.*
20         $KILLALL_PROG -9 fsstress > /dev/null 2>&1
21 }
22
23 # Import common functions.
24 . ./common/quota
25 . ./common/filter
26 . ./common/reflink
27
28 # Modify as appropriate.
29 _supported_fs xfs
30
31 _require_scratch_reflink
32 _require_quota
33 _require_command "$KILLALL_PROG" "killall"
34
35 report_quota_blocks() {
36         $XFS_QUOTA_PROG -x -c "report $1" $SCRATCH_MNT | \
37                         awk '{x += $2;} END { print(x); }'
38 }
39
40 compare_quota_to_du() {
41         test $1 -eq $2 || echo "$3 quota $2 blocks does not match du $1 blocks?"
42 }
43
44 # Make sure the user/group/project quota block counts match the du output.
45 # This ensures that we did the quota accounting correctly and that we're
46 # accurately reporting cow preallocation blocks in stat.
47 check_quota_du_blocks() {
48         sync
49         #$XFS_QUOTA_PROG -x -c 'report' $SCRATCH_MNT >> $seqres.full
50         du_rep=$(du -ks $SCRATCH_MNT | awk '{print $1}')
51         u_rep=$(report_quota_blocks -u)
52         g_rep=$(report_quota_blocks -g)
53         p_rep=$(report_quota_blocks -p)
54
55         compare_quota_to_du $du_rep $u_rep "user"
56         compare_quota_to_du $du_rep $g_rep "group"
57         compare_quota_to_du $du_rep $p_rep "project"
58 }
59
60 echo "Format and fsstress"
61
62 _qmount_option "usrquota,grpquota,prjquota"
63 # We use a small volume so that we hit ENOSPC.  This is critical for
64 # regression testing a bug in the directio write code that could result in fs
65 # corruption ("xfs: check reflink allocation mappings").
66 #
67 # This started as a test for quota accounting problems ("xfs: treat CoW fork
68 # operations as delalloc for quota accounting") and ("xfs: call
69 # xfs_qm_dqattach before performing reflink operations") though each of those
70 # tests now have separate faster-running regression tests.
71 _scratch_mkfs_sized $((1600 * 1048576)) > $seqres.full 2>&1
72 _scratch_mount >> $seqres.full 2>&1
73
74 nr_cpus=$((LOAD_FACTOR * 4))
75 nr_ops=$((25000 * nr_cpus * TIME_FACTOR))
76 $FSSTRESS_PROG $FSSTRESS_AVOID -w -d $SCRATCH_MNT -n $nr_ops -p $nr_cpus >> $seqres.full
77
78 echo "Check quota before remount"
79 check_quota_du_blocks
80
81 # Clear out all the preallocations before we quotacheck.
82 # The count comparison in _check_quota_usage will be unhappy if we don't
83 # manage to clean out all the cow preallocations before the remount.
84 _scratch_unmount
85 _scratch_mount
86
87 # Make sure the usage doesn't change after quotacheck.
88 echo "Check quota after remount"
89 _check_quota_usage
90
91 check_quota_du_blocks
92
93 # success, all done
94 status=0
95 exit