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 _begin_fstest auto quick quota
13 # Override the default cleanup function.
16 _restore_project_quota
21 # Import common functions.
29 echo "### Initialize files, and their mode and ownership"
30 touch $dir/file{1,2} 2>/dev/null
31 chown $qa_user $dir/file{1,2} 2>/dev/null
32 chgrp $qa_user $dir/file{1,2} 2>/dev/null
33 chmod 777 $dir 2>/dev/null
38 echo "### Remove all files"
39 rm -f ${1}/file{1,2,3,4,5,6}
42 # When project quota is exceeded, some filesystems return ENOSPC (e.g. XFS),
43 # some filsystems return EDQUOT(e.g. ext4). The behavior isn't definitized.
44 # So filter the ENOSPC and EDQUOT output.
45 filter_enospc_edquot()
47 # The filter is only for project quota
48 if [ "$1" = "P" ];then
49 sed -e "s,Disk quota exceeded,EDQUOT|ENOSPC,g" \
50 -e "s,No space left on device,EDQUOT|ENOSPC,g"
64 echo "--- Test block quota ---"
65 # Firstly fit below block soft limit
66 echo "Write 225 blocks..."
67 su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((225 * $BLOCK_SIZE))' \
68 -c fsync $dir/file1" 2>&1 >>$seqres.full | \
69 _filter_xfs_io_error | tee -a $seqres.full
70 repquota -v -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
71 # Secondly overcome block soft limit
72 echo "Rewrite 250 blocks plus 1 byte, over the block softlimit..."
73 su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 $((250 * $BLOCK_SIZE + 1))' \
74 -c fsync $dir/file1" 2>&1 >>$seqres.full | \
75 _filter_xfs_io_error | tee -a $seqres.full
76 repquota -v -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
77 # Reset grace time here, make below grace time test more accurate
78 setquota -$type $qa_user -T $bgrace $igrace $SCRATCH_MNT 2>/dev/null
79 # Now sleep enough grace time and check that softlimit got enforced
81 echo "Try to write 1 one more block after grace..."
82 su $qa_user -c "$XFS_IO_PROG -c 'truncate 0' -c 'pwrite 0 $BLOCK_SIZE' \
83 $dir/file2" 2>&1 >>$seqres.full | _filter_xfs_io_error | \
84 filter_enospc_edquot $type | tee -a $seqres.full
85 repquota -v -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
86 echo "--- Test inode quota ---"
87 # And now the softlimit test for inodes
88 # First reset space limits so that we don't have problems with
89 # space reservations on XFS
90 setquota -$type $qa_user 0 0 3 100 $SCRATCH_MNT
91 echo "Create 2 more files, over the inode softlimit..."
92 su $qa_user -c "touch $dir/file3 $dir/file4" 2>&1 >>$seqres.full | \
93 _filter_scratch | tee -a $seqres.full
94 repquota -v -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
95 # Reset grace time here, make below grace time test more accurate
96 setquota -$type $qa_user -T $bgrace $igrace $SCRATCH_MNT 2>/dev/null
97 # Wait and check grace time enforcement
99 echo "Try to create one more inode after grace..."
100 su $qa_user -c "touch $dir/file5" 2>&1 >>$seqres.full | \
101 filter_enospc_edquot $type | _filter_scratch | \
103 repquota -v -$type $SCRATCH_MNT | grep -v "^root" >>$seqres.full 2>&1
107 # real QA test starts here
108 _supported_fs generic
110 # xfs requires v5 format to support all three quota types at the same time
111 if [ "$FSTYP" = "xfs" ]; then
112 _require_scratch_xfs_crc
114 _require_setquota_project
119 _scratch_mkfs >$seqres.full 2>&1
120 _scratch_enable_pquota
121 _qmount_option "usrquota,grpquota,prjquota"
123 _require_prjquota $SCRATCH_DEV
124 BLOCK_SIZE=$(_get_file_block_size $SCRATCH_MNT)
125 rm -rf $SCRATCH_MNT/t
127 $XFS_IO_PROG -r -c "chproj 100" -c "chattr +P" $SCRATCH_MNT/t
128 _create_project_quota $SCRATCH_MNT/t 100 $qa_user
130 echo "### Set up different grace timers to each type of quota"
138 setquota -u $qa_user $((250 * $BLOCK_SIZE / 1024)) \
139 $((1000 * $BLOCK_SIZE / 1024)) 3 100 $SCRATCH_MNT
140 setquota -u -t $UBGRACE $UIGRACE $SCRATCH_MNT
141 echo; echo "### Test user quota softlimit and grace time"
142 test_grace u $SCRATCH_MNT $UBGRACE $UIGRACE
143 # Reset the user quota space & inode limits, avoid it affect later test
144 setquota -u $qa_user 0 0 0 0 $SCRATCH_MNT
146 setquota -g $qa_user $((250 * $BLOCK_SIZE / 1024)) \
147 $((1000 * $BLOCK_SIZE / 1024)) 3 100 $SCRATCH_MNT
148 setquota -g -t $GBGRACE $GIGRACE $SCRATCH_MNT
149 echo; echo "### Test group quota softlimit and grace time"
150 test_grace g $SCRATCH_MNT $GBGRACE $GIGRACE
151 # Reset the group quota space & inode limits, avoid it affect later test
152 setquota -g $qa_user 0 0 0 0 $SCRATCH_MNT
154 setquota -P $qa_user $((250 * $BLOCK_SIZE / 1024)) \
155 $((1000 * $BLOCK_SIZE / 1024)) 3 100 $SCRATCH_MNT
156 setquota -P -t $PBGRACE $PIGRACE $SCRATCH_MNT
157 echo; echo "### Test project quota softlimit and grace time"
158 test_grace P $SCRATCH_MNT/t $PBGRACE $PIGRACE
159 # Reset the project quota space & inode limits
160 setquota -P $qa_user 0 0 0 0 $SCRATCH_MNT