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
32 echo; echo "### create files, setting up ownership (type=$type)"
33 touch $SCRATCH_MNT/file{1,2} 2>/dev/null
34 chown $qa_user $SCRATCH_MNT/file{1,2} 2>/dev/null
35 chgrp $qa_user $SCRATCH_MNT/file{1,2} 2>/dev/null
36 chmod 777 $SCRATCH_MNT 2>/dev/null
41 echo "### some buffered IO (type=$type)"
42 echo "--- initiating IO..." >>$seqres.full
43 # Firstly fit below block soft limit
44 echo "Write 225 blocks..."
45 su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((225 * $BLOCK_SIZE))' -c fsync \
46 $SCRATCH_MNT/file1" 2>&1 >>$seqres.full | \
47 _filter_xfs_io_error | tee -a $seqres.full
48 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
49 # Secondly overcome block soft limit
50 echo "Rewrite 250 blocks plus 1 byte..."
51 su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((250 * $BLOCK_SIZE + 1))' -c fsync \
52 $SCRATCH_MNT/file1" 2>&1 >>$seqres.full | \
53 _filter_xfs_io_error | tee -a $seqres.full
54 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
55 # Now try to overcome block hardlimit
56 # Reset grace time here due to the repquota will invoke Q_SYNC on
57 # old quota which may be time consuming on the low speed or busy
58 # scratch device that may leed to grace time exceed.
59 setquota -$type $qa_user -T $grace $grace $SCRATCH_MNT 2>/dev/null
60 echo "Write 250 blocks..."
61 su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((250 * $BLOCK_SIZE))' -c fsync \
62 $SCRATCH_MNT/file2" 2>&1 >>$seqres.full | \
63 _filter_xfs_io_error | tee -a $seqres.full
64 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
65 # Now sleep for grace time and check that softlimit got enforced
67 echo "Write 1 block..."
68 su $qa_user -c "$XFS_IO_PROG -c 'truncate 0' -c 'pwrite 0 $BLOCK_SIZE' \
69 $SCRATCH_MNT/file2" 2>&1 >>$seqres.full | \
70 _filter_xfs_io_error | tee -a $seqres.full
71 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
72 # And now the softlimit test for inodes
73 # First reset space limits so that we don't have problems with
74 # space reservations on XFS
75 setquota -$type $qa_user 0 0 3 5 $SCRATCH_MNT
77 su $qa_user -c "touch $SCRATCH_MNT/file3 $SCRATCH_MNT/file4" \
78 2>&1 >>$seqres.full | _filter_scratch | tee -a $seqres.full
79 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
80 # Try to exceed inode hardlimit
81 # Reset grace time here due to the repquota will invoke Q_SYNC on
82 # old quota which may be time consuming on the low speed or busy
83 # scratch device that may leed to grace time exceed.
84 setquota -$type $qa_user -T $grace $grace $SCRATCH_MNT 2>/dev/null
86 su $qa_user -c "touch $SCRATCH_MNT/file5 $SCRATCH_MNT/file6" \
87 2>&1 >>$seqres.full | _filter_scratch | tee -a $seqres.full
88 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
89 # Wait and check grace time enforcement
90 rm -f $SCRATCH_MNT/file5 >>$seqres.full 2>&1
93 su $qa_user -c "touch $SCRATCH_MNT/file5" 2>&1 >>$seqres.full |
94 _filter_scratch | tee -a $seqres.full
95 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
96 echo "--- completed IO ($type)" >>$seqres.full
101 rm -f $SCRATCH_MNT/file{1,2,3,4,5,6}
104 # real QA test starts here
109 # Test only the quota type specified in each _scratch_mount clause below.
110 _qmount_option 'defaults'
112 _scratch_mkfs >> $seqres.full 2>&1
113 _scratch_mount "-o usrquota,grpquota"
114 BLOCK_SIZE=$(_get_file_block_size $SCRATCH_MNT)
115 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
116 quotaon $SCRATCH_MNT 2>/dev/null
117 setquota -u $qa_user $((250 * $BLOCK_SIZE / 1024)) \
118 $((500 * $BLOCK_SIZE / 1024)) 3 5 $SCRATCH_MNT
119 setquota -u -t $grace $grace $SCRATCH_MNT
120 setquota -g $qa_user $((250 * $BLOCK_SIZE / 1024)) \
121 $((500 * $BLOCK_SIZE / 1024)) 3 5 $SCRATCH_MNT
122 setquota -g -t $grace $grace $SCRATCH_MNT
125 echo; echo "### test user limit enforcement"
126 _scratch_mount "-o usrquota"
127 quotaon $SCRATCH_MNT 2>/dev/null
132 _scratch_unmount 2>/dev/null
134 echo; echo "### test group limit enforcement"
135 _scratch_mount "-o grpquota"
136 quotaon $SCRATCH_MNT 2>/dev/null
141 _scratch_unmount 2>/dev/null