2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Red Hat, Inc. All Rights Reserved.
7 # Test per-type(user, group and project) filesystem quota timers, make sure
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
26 # get standard environment, filters and checks
31 # remove previous $seqres.full before test
36 rm -f $tmp.projects $tmp.projid
37 if [ -f /etc/projects ];then
38 cat /etc/projects > $tmp.projects
40 if [ -f /etc/projid ];then
41 cat /etc/projid > $tmp.projid
44 cat >/etc/projects <<EOF
47 cat >/etc/projid <<EOF
55 if [ "$PROJECT_CHANGED" = "1" ];then
56 rm -f /etc/projects /etc/projid
57 if [ -f $tmp.projects ];then
58 cat $tmp.projects > /etc/projects
60 if [ -f $tmp.projid ];then
61 cat $tmp.projid > /etc/projid
70 echo "### Initialize files, and their mode and ownership"
71 touch $dir/file{1,2} 2>/dev/null
72 chown $qa_user $dir/file{1,2} 2>/dev/null
73 chgrp $qa_user $dir/file{1,2} 2>/dev/null
74 chmod 777 $dir 2>/dev/null
79 echo "### Remove all files"
80 rm -f ${1}/file{1,2,3,4,5,6}
83 # When project quota is exceeded, some filesystems return ENOSPC (e.g. XFS),
84 # some filsystems return EDQUOT(e.g. ext4). The behavior isn't definitized.
85 # So filter the ENOSPC and EDQUOT output.
86 filter_enospc_edquot()
88 # The filter is only for project quota
89 if [ "$1" = "P" ];then
90 sed -e "s,Disk quota exceeded,EDQUOT|ENOSPC,g" \
91 -e "s,No space left on device,EDQUOT|ENOSPC,g"
105 echo "--- Test block quota ---"
106 # Firstly fit below block soft limit
107 echo "Write 225 blocks..."
108 su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((225 * $BLOCK_SIZE))' \
109 -c fsync $dir/file1" 2>&1 >>$seqres.full | \
110 _filter_xfs_io_error | tee -a $seqres.full
111 repquota -v -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
112 # Secondly overcome block soft limit
113 echo "Rewrite 250 blocks plus 1 byte, over the block softlimit..."
114 su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((250 * $BLOCK_SIZE + 1))' \
115 -c fsync $dir/file1" 2>&1 >>$seqres.full | \
116 _filter_xfs_io_error | tee -a $seqres.full
117 repquota -v -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
118 # Reset grace time here, make below grace time test more accurate
119 setquota -$type $qa_user -T $bgrace $igrace $SCRATCH_MNT 2>/dev/null
120 # Now sleep enough grace time and check that softlimit got enforced
121 sleep $((bgrace + 1))
122 echo "Try to write 1 one more block after grace..."
123 su $qa_user -c "$XFS_IO_PROG -c 'truncate 0' -c 'pwrite 0 $BLOCK_SIZE' \
124 $dir/file2" 2>&1 >>$seqres.full | _filter_xfs_io_error | \
125 filter_enospc_edquot $type | tee -a $seqres.full
126 repquota -v -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
127 echo "--- Test inode quota ---"
128 # And now the softlimit test for inodes
129 # First reset space limits so that we don't have problems with
130 # space reservations on XFS
131 setquota -$type $qa_user 0 0 3 100 $SCRATCH_MNT
132 echo "Create 2 more files, over the inode softlimit..."
133 su $qa_user -c "touch $dir/file3 $dir/file4" 2>&1 >>$seqres.full | \
134 _filter_scratch | tee -a $seqres.full
135 repquota -v -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
136 # Reset grace time here, make below grace time test more accurate
137 setquota -$type $qa_user -T $bgrace $igrace $SCRATCH_MNT 2>/dev/null
138 # Wait and check grace time enforcement
140 echo "Try to create one more inode after grace..."
141 su $qa_user -c "touch $dir/file5" 2>&1 >>$seqres.full | \
142 filter_enospc_edquot $type | _filter_scratch | \
144 repquota -v -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
148 # real QA test starts here
149 _supported_fs generic
152 # xfs requires v5 format to support all three quota types at the same time
153 if [ "$FSTYP" = "xfs" ]; then
154 _require_scratch_xfs_crc
156 _require_setquota_project
161 _scratch_mkfs >$seqres.full 2>&1
162 _scratch_enable_pquota
163 _qmount_option "usrquota,grpquota,prjquota"
165 _require_prjquota $SCRATCH_DEV
166 BLOCK_SIZE=$(_get_file_block_size $SCRATCH_MNT)
167 rm -rf $SCRATCH_MNT/t
169 $XFS_IO_PROG -r -c "chproj 100" -c "chattr +P" $SCRATCH_MNT/t
172 echo "### Set up different grace timers to each type of quota"
180 setquota -u $qa_user $((250 * $BLOCK_SIZE / 1024)) \
181 $((1000 * $BLOCK_SIZE / 1024)) 3 100 $SCRATCH_MNT
182 setquota -u -t $UBGRACE $UIGRACE $SCRATCH_MNT
183 echo; echo "### Test user quota softlimit and grace time"
184 test_grace u $SCRATCH_MNT $UBGRACE $UIGRACE
185 # Reset the user quota space & inode limits, avoid it affect later test
186 setquota -u $qa_user 0 0 0 0 $SCRATCH_MNT
188 setquota -g $qa_user $((250 * $BLOCK_SIZE / 1024)) \
189 $((1000 * $BLOCK_SIZE / 1024)) 3 100 $SCRATCH_MNT
190 setquota -g -t $GBGRACE $GIGRACE $SCRATCH_MNT
191 echo; echo "### Test group quota softlimit and grace time"
192 test_grace g $SCRATCH_MNT $GBGRACE $GIGRACE
193 # Reset the group quota space & inode limits, avoid it affect later test
194 setquota -g $qa_user 0 0 0 0 $SCRATCH_MNT
196 setquota -P $qa_user $((250 * $BLOCK_SIZE / 1024)) \
197 $((1000 * $BLOCK_SIZE / 1024)) 3 100 $SCRATCH_MNT
198 setquota -P -t $PBGRACE $PIGRACE $SCRATCH_MNT
199 echo; echo "### Test project quota softlimit and grace time"
200 test_grace P $SCRATCH_MNT/t $PBGRACE $PIGRACE
201 # Reset the project quota space & inode limits
202 setquota -P $qa_user 0 0 0 0 $SCRATCH_MNT