69b1cbe2d223defafedc47d5bd8d3182cb32a2ff
[xfstests-dev.git] / tests / generic / 026
1 #! /bin/bash
2 # FS QA Test No. generic/026
3 #
4 # Test out ACL count limits
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8 # Copyright (c) 2014 Red hat, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # FAILure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38 . ./common/attr
39
40 _cleanup()
41 {
42     cd /
43     rm -f $tmp.*
44     [ -n "$TEST_DIR" ] && rm -rf $TEST_DIR/$seq.dir1
45 }
46
47 # real QA test starts here
48 _supported_fs generic
49 _supported_os Linux
50 _require_test
51 _require_scratch
52 _acl_setup_ids
53 _require_acls
54 _require_acl_get_max
55
56 rm -f $seqres.full
57
58 # get dir
59 cd $TEST_DIR
60 rm -rf $seq.dir1
61 mkdir $seq.dir1
62 cd $seq.dir1
63
64 # we return E2BIG if hit the max acl limits on new kernel, but EINVAL
65 # on old kernel. So we need to filter out the error message in order
66 # to make the updated golden output works for both old and new kernels.
67 _filter_largeacl()
68 {
69         sed -e "s/Invalid argument/Argument list too long/"
70 }
71
72 # filter all the non-ace stuff from the acl output so the count is
73 # correct. Note that this assumes that _create_n_aces always creates rwx acls.
74 _filter_acls()
75 {
76         _filter_aces | grep ':rwx'
77 }
78
79 # store the output in seqres.full, then run again an count and filter the
80 # output.
81 check_acls()
82 {
83         _acl=$1
84         _count=$2
85
86         chacl $_acl largeaclfile 2>&1 | _filter_largeacl
87         getfacl --numeric largeaclfile | _filter_aces \
88                 >> $seqres.full 2> /dev/null
89         nacls=`getfacl --numeric largeaclfile | _filter_acls | wc -l`
90         if [ $nacls -ne $_count ]; then
91                 echo Wrong ACL count - $nacls != $_count
92         fi
93 }
94
95
96 echo ""
97 echo "=== Test out large ACLs  ==="
98 touch largeaclfile
99
100 ACL_MAX_ENTRIES=$(_acl_get_max)
101 num_aces_pre=$((ACL_MAX_ENTRIES - 1))
102 num_aces_post=$((ACL_MAX_ENTRIES + 1))
103
104 acl1=`_create_n_aces $num_aces_pre`
105 acl2=`_create_n_aces $ACL_MAX_ENTRIES`
106 acl3=`_create_n_aces $num_aces_post`
107 acl4=`_create_n_aces 16` # Andreas G. libacl size for initial get
108 acl5=`_create_n_aces 17` # 1 over A.G. libacl initial size
109
110 echo "1 below acl max"
111 check_acls $acl1 $num_aces_pre
112
113 echo "acl max"
114 check_acls $acl2 $ACL_MAX_ENTRIES
115
116 # we expect the ACL change to fail, so the old ACLs should remain on the
117 # file. Hence the expected ACL count is XFS_ACL_MAX_ENTRIES, not num_aces_post.
118 echo "1 above acl max"
119 check_acls $acl3 $ACL_MAX_ENTRIES
120
121 echo "use 16 aces"
122 check_acls $acl4 16
123
124 echo "use 17 aces"
125 check_acls $acl5 17
126
127 # success, all done
128 status=0
129 exit