lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 230
1 #! /bin/bash
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.
5 #
6 # FS QA Test No. 230
7 #
8 # Simple quota enforcement test.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
18
19 # get standard environment, filters and checks
20 . ./common/rc
21 . ./common/filter
22 . ./common/quota
23
24 # real QA test starts here
25 _supported_fs generic
26 _supported_os Linux
27 _require_scratch
28 _require_quota
29 _require_user
30
31 test_files()
32 {
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
38 }
39
40 test_enforcement()
41 {
42         echo "### some buffered IO (type=$type)"
43         echo "--- initiating IO..." >>$seqres.full
44         # Firstly fit below block soft limit
45         echo "Write 900k..."
46         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 900k' -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 1001k..."
52         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 1001k' -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 1000k..."
58         su $qa_user -c "$XFS_IO_PROG -c 'pwrite 0 1000k' -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
63         sleep $((grace+1))
64         echo "Write 4096..."
65         su $qa_user -c "$XFS_IO_PROG -c 'truncate 0' -c 'pwrite 0 4096' \
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
73         echo "Touch 3+4"
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
78         echo "Touch 5+6"
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
84         sleep $((grace+1))
85         echo "Touch 5"
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
90 }
91
92 cleanup_files()
93 {
94         rm -f $SCRATCH_MNT/file{1,2,3,4,5,6}
95 }
96
97 # real QA test starts here
98 rm -f $seqres.full
99
100 grace=2
101
102 _scratch_mkfs >> $seqres.full 2>&1
103 _scratch_mount "-o usrquota,grpquota"
104 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
105 quotaon $SCRATCH_MNT 2>/dev/null
106 setquota -u $qa_user 1000 2000 3 5 $SCRATCH_MNT
107 setquota -u -t $grace $grace $SCRATCH_MNT
108 setquota -g $qa_user 1000 2000 3 5 $SCRATCH_MNT
109 setquota -g -t $grace $grace $SCRATCH_MNT
110 _scratch_unmount
111
112 echo; echo "### test user limit enforcement"
113 _scratch_mount "-o usrquota"
114 quotaon $SCRATCH_MNT 2>/dev/null
115 type=u
116 test_files
117 test_enforcement
118 cleanup_files
119 _scratch_unmount 2>/dev/null
120
121 echo; echo "### test group limit enforcement"
122 _scratch_mount "-o grpquota"
123 quotaon $SCRATCH_MNT 2>/dev/null
124 type=g
125 test_files
126 test_enforcement
127 cleanup_files
128 _scratch_unmount 2>/dev/null
129
130 status=0
131 exit