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.
8 # Simple quota enforcement test.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
19 # get standard environment, filters and checks
24 # real QA test starts here
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
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
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
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
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
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
102 rm -f $SCRATCH_MNT/file{1,2,3,4,5,6}
105 # real QA test starts here
110 # Test only the quota type specified in each _scratch_mount clause below.
111 _qmount_option 'defaults'
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
126 echo; echo "### test user limit enforcement"
127 _scratch_mount "-o usrquota"
128 quotaon $SCRATCH_MNT 2>/dev/null
133 _scratch_unmount 2>/dev/null
135 echo; echo "### test group limit enforcement"
136 _scratch_mount "-o grpquota"
137 quotaon $SCRATCH_MNT 2>/dev/null
142 _scratch_unmount 2>/dev/null