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 echo "Write 250 blocks..."
58 su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((250 * $BLOCK_SIZE))' -c fsync \
59 $SCRATCH_MNT/file2" 2>&1 >>$seqres.full | \
60 _filter_xfs_io_error | tee -a $seqres.full
61 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
62 # Now sleep for grace time and check that softlimit got enforced
64 echo "Write 1 block..."
65 su $qa_user -c "$XFS_IO_PROG -c 'truncate 0' -c 'pwrite 0 $BLOCK_SIZE' \
66 $SCRATCH_MNT/file2" 2>&1 >>$seqres.full | \
67 _filter_xfs_io_error | tee -a $seqres.full
68 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
69 # And now the softlimit test for inodes
70 # First reset space limits so that we don't have problems with
71 # space reservations on XFS
72 setquota -$type $qa_user 0 0 3 5 $SCRATCH_MNT
74 su $qa_user -c "touch $SCRATCH_MNT/file3 $SCRATCH_MNT/file4" \
75 2>&1 >>$seqres.full | _filter_scratch | tee -a $seqres.full
76 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
77 # Try to exceed inode hardlimit
79 su $qa_user -c "touch $SCRATCH_MNT/file5 $SCRATCH_MNT/file6" \
80 2>&1 >>$seqres.full | _filter_scratch | tee -a $seqres.full
81 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
82 # Wait and check grace time enforcement
83 rm -f $SCRATCH_MNT/file5 >>$seqres.full 2>&1
86 su $qa_user -c "touch $SCRATCH_MNT/file5" 2>&1 >>$seqres.full |
87 _filter_scratch | tee -a $seqres.full
88 repquota -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
89 echo "--- completed IO ($type)" >>$seqres.full
94 rm -f $SCRATCH_MNT/file{1,2,3,4,5,6}
97 # real QA test starts here
102 _scratch_mkfs >> $seqres.full 2>&1
103 _scratch_mount "-o usrquota,grpquota"
104 BLOCK_SIZE=$(_get_file_block_size $SCRATCH_MNT)
105 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
106 quotaon $SCRATCH_MNT 2>/dev/null
107 setquota -u $qa_user $((250 * $BLOCK_SIZE / 1024)) \
108 $((500 * $BLOCK_SIZE / 1024)) 3 5 $SCRATCH_MNT
109 setquota -u -t $grace $grace $SCRATCH_MNT
110 setquota -g $qa_user $((250 * $BLOCK_SIZE / 1024)) \
111 $((500 * $BLOCK_SIZE / 1024)) 3 5 $SCRATCH_MNT
112 setquota -g -t $grace $grace $SCRATCH_MNT
115 echo; echo "### test user limit enforcement"
116 _scratch_mount "-o usrquota"
117 quotaon $SCRATCH_MNT 2>/dev/null
122 _scratch_unmount 2>/dev/null
124 echo; echo "### test group limit enforcement"
125 _scratch_mount "-o grpquota"
126 quotaon $SCRATCH_MNT 2>/dev/null
131 _scratch_unmount 2>/dev/null