xfs: new test default user/group quota
[xfstests-dev.git] / tests / xfs / 260
1 #! /bin/bash
2 # FS QA Test 260
3 #
4 # When default quota is set, all different quota types inherits the
5 # same default value, include group quota. So if a user quota limit
6 # larger than the default user quota value, it will still be limited
7 # by the group default quota value.
8 #
9 # There's a patch from Upstream can fix this bug:
10 #
11 #    [PATCH] xfs: Split default quota limits by quota type V4
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 here=`pwd`
36 tmp=/tmp/$$
37 status=1        # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
39
40 _cleanup()
41 {
42         cd /
43         rm -f $tmp.*
44 }
45
46 # get standard environment, filters and checks
47 . ./common/rc
48 . ./common/filter
49 . ./common/quota
50
51 # remove previous $seqres.full before test
52 rm -f $seqres.full
53
54 # real QA test starts here
55 _supported_fs xfs
56 _supported_os Linux
57 _require_scratch
58 _require_quota
59 _require_user
60 _require_group
61
62 do_test()
63 {
64         local qname=$1
65         local type
66
67         if [ "$qname" = "user" ];then
68                 type="-u"
69                 echo "=== user quota test ==="
70         elif [ "$qname" = "group" ];then
71                 type="-g"
72                 echo "=== group quota test ==="
73         else
74                 echo "wrong quota type name - $qname"
75                 return 1
76         fi
77
78         $XFS_QUOTA_PROG -x -c "limit bsoft=20M bhard=20M isoft=20 ihard=20 $type -d" $SCRATCH_MNT
79         $XFS_QUOTA_PROG -x -c "limit bsoft=40M bhard=40M isoft=40 ihard=40 $type fsgqa" $SCRATCH_MNT
80         echo "$qname blocks and inode limit"
81         $XFS_QUOTA_PROG -x -c "report $type -N -bi" $SCRATCH_MNT | _filter_spaces
82
83         ## blocks default quota test ##
84         _user_do "$XFS_IO_PROG -f -c \"pwrite 0 30M\" -c \"fsync\" $SCRATCH_MNT/data" | _filter_xfs_io
85         echo "$qname blocks quota after write 30M data"
86         $XFS_QUOTA_PROG -x -c "report $type -N -b" $SCRATCH_MNT | _filter_spaces
87
88         rm -f ${SCRATCH_MNT}/* >/dev/null 2>&1
89
90         ## inode default quota test ##
91         for ((i=0; i<30; i++));do
92                 _user_do "echo -n > ${SCRATCH_MNT}/file${i}"
93         done
94         sync
95
96         echo "$qname inode quota after create 300 inodes"
97         $XFS_QUOTA_PROG -x -c "report $type -N -i" $SCRATCH_MNT | _filter_spaces
98
99         rm -f ${SCRATCH_MNT}/* >/dev/null 2>&1
100 }
101
102 ### user default quota test ###
103 _scratch_mkfs_xfs >/dev/null 2>&1
104 _qmount_option "uquota,gquota"
105 _qmount
106
107 do_test user
108
109 ### group default quota test ###
110 _scratch_unmount
111 _scratch_mkfs_xfs >/dev/null 2>&1
112 _qmount_option "gquota,uquota"
113 _qmount
114
115 do_test group
116
117 # success, all done
118 status=0
119 exit