generic: Verify the inheritance behavior of FS_XFLAG_DAX flag in various combinations
[xfstests-dev.git] / tests / generic / 230
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2010 Jan Kara.  All Rights Reserved.
4 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # FS QA Test No. 230
7 #
8 # Simple quota enforcement test.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
18
19 # get standard environment, filters and checks
20 . ./common/rc
21 . ./common/filter
22 . ./common/quota
23
24 # real QA test starts here
25 _supported_fs generic
26 _supported_os Linux
27 _require_scratch
28 _require_quota
29 _require_user
30
31 test_files()
32 {
33         echo; echo "### create files, setting up ownership (type=$type)"
34         touch $SCRATCH_MNT/file{1,2} 2>/dev/null
35         chown $qa_user $SCRATCH_MNT/file{1,2} 2>/dev/null
36         chgrp $qa_user $SCRATCH_MNT/file{1,2} 2>/dev/null
37         chmod 777 $SCRATCH_MNT 2>/dev/null
38 }
39
40 test_enforcement()
41 {
42         echo "### some buffered IO (type=$type)"
43         echo "--- initiating IO..." >>$seqres.full
44         # Firstly fit below block soft limit
45         echo "Write 225 blocks..."
46         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((225 * $BLOCK_SIZE))' -c fsync \
47                 $SCRATCH_MNT/file1" 2>&1 >>$seqres.full | \
48                 _filter_xfs_io_error | tee -a $seqres.full
49         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
50         # Secondly overcome block soft limit
51         echo "Rewrite 250 blocks plus 1 byte..."
52         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((250 * $BLOCK_SIZE + 1))' -c fsync \
53                 $SCRATCH_MNT/file1" 2>&1 >>$seqres.full | \
54                 _filter_xfs_io_error | tee -a $seqres.full
55         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
56         # Now try to overcome block hardlimit
57         # Reset grace time here due to the repquota will invoke Q_SYNC on
58         # old quota which may be time consuming on the low speed or busy
59         # scratch device that may leed to grace time exceed.
60         setquota -$type $qa_user -T $grace $grace $SCRATCH_MNT 2>/dev/null
61         echo "Write 250 blocks..."
62         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((250 * $BLOCK_SIZE))' -c fsync \
63                 $SCRATCH_MNT/file2" 2>&1 >>$seqres.full | \
64                 _filter_xfs_io_error | tee -a $seqres.full
65         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
66         # Now sleep for grace time and check that softlimit got enforced
67         sleep $((grace+1))
68         echo "Write 1 block..."
69         su $qa_user -c "$XFS_IO_PROG -c 'truncate 0' -c 'pwrite 0 $BLOCK_SIZE' \
70                 $SCRATCH_MNT/file2" 2>&1 >>$seqres.full | \
71                 _filter_xfs_io_error | tee -a $seqres.full
72         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
73         # And now the softlimit test for inodes
74         # First reset space limits so that we don't have problems with
75         # space reservations on XFS
76         setquota -$type $qa_user 0 0 3 5 $SCRATCH_MNT
77         echo "Touch 3+4"
78         su $qa_user -c "touch $SCRATCH_MNT/file3 $SCRATCH_MNT/file4" \
79                 2>&1 >>$seqres.full | _filter_scratch | tee -a $seqres.full
80         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
81         # Try to exceed inode hardlimit
82         # Reset grace time here due to the repquota will invoke Q_SYNC on
83         # old quota which may be time consuming on the low speed or busy
84         # scratch device that may leed to grace time exceed.
85         setquota -$type $qa_user -T $grace $grace $SCRATCH_MNT 2>/dev/null
86         echo "Touch 5+6"
87         su $qa_user -c "touch $SCRATCH_MNT/file5 $SCRATCH_MNT/file6" \
88                 2>&1 >>$seqres.full | _filter_scratch | tee -a $seqres.full
89         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
90         # Wait and check grace time enforcement
91         rm -f $SCRATCH_MNT/file5 >>$seqres.full 2>&1
92         sleep $((grace+1))
93         echo "Touch 5"
94         su $qa_user -c "touch $SCRATCH_MNT/file5" 2>&1 >>$seqres.full |
95                 _filter_scratch | tee -a $seqres.full
96         repquota -$type $SCRATCH_MNT  | grep -v "^root" >>$seqres.full 2>&1
97         echo "--- completed IO ($type)" >>$seqres.full
98 }
99
100 cleanup_files()
101 {
102         rm -f $SCRATCH_MNT/file{1,2,3,4,5,6}
103 }
104
105 # real QA test starts here
106 rm -f $seqres.full
107
108 grace=2
109
110 # Test only the quota type specified in each _scratch_mount clause below.
111 _qmount_option 'defaults'
112
113 _scratch_mkfs >> $seqres.full 2>&1
114 _scratch_mount "-o usrquota,grpquota"
115 BLOCK_SIZE=$(_get_file_block_size $SCRATCH_MNT)
116 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
117 quotaon $SCRATCH_MNT 2>/dev/null
118 setquota -u $qa_user $((250 * $BLOCK_SIZE / 1024)) \
119          $((500 * $BLOCK_SIZE / 1024)) 3 5 $SCRATCH_MNT
120 setquota -u -t $grace $grace $SCRATCH_MNT
121 setquota -g $qa_user $((250 * $BLOCK_SIZE / 1024)) \
122          $((500 * $BLOCK_SIZE / 1024)) 3 5 $SCRATCH_MNT
123 setquota -g -t $grace $grace $SCRATCH_MNT
124 _scratch_unmount
125
126 echo; echo "### test user limit enforcement"
127 _scratch_mount "-o usrquota"
128 quotaon $SCRATCH_MNT 2>/dev/null
129 type=u
130 test_files
131 test_enforcement
132 cleanup_files
133 _scratch_unmount 2>/dev/null
134
135 echo; echo "### test group limit enforcement"
136 _scratch_mount "-o grpquota"
137 quotaon $SCRATCH_MNT 2>/dev/null
138 type=g
139 test_files
140 test_enforcement
141 cleanup_files
142 _scratch_unmount 2>/dev/null
143
144 status=0
145 exit