generic/405: test mkfs against thin provision device
[xfstests-dev.git] / tests / generic / 318
1 #! /bin/bash
2 # FS QA Test No. 318
3 #
4 # Check get/set ACLs to/from disk with a user namespace. A new file
5 # will be created and ACLs set on it from both inside a userns and
6 # from init_user_ns. We check that the ACL is is correct from both
7 # inside the userns and also from init_user_ns. We will then unmount
8 # and remount the file system and check the ACL from both inside the
9 # userns and from init_user_ns to show that the correct uid/gid in
10 # the ACL was flushed and brought back from disk.
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (C) 2013 Oracle, Inc.  All Rights Reserved.
14 #
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
18 #
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27 #-----------------------------------------------------------------------
28 #
29
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 here=`pwd`
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37
38 _cleanup()
39 {
40     cd /
41     _scratch_unmount >/dev/null 2>&1
42 }
43 trap "_cleanup; exit \$status" 0 1 2 3 15
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48 . ./common/attr
49
50 nsexec=$here/src/nsexec
51 file=$SCRATCH_MNT/file1
52
53 # real QA test starts here
54 _supported_fs generic
55 # only Linux supports user namespace
56 _supported_os Linux
57
58 rm -f $seqres.full
59
60 _require_scratch
61 _acl_setup_ids
62 _require_acls
63 _require_ugid_map
64 _require_userns
65 ns_acl1=0
66 ns_acl2=`expr $acl2 - $acl1`
67 ns_acl3=`expr $acl3 - $acl1`
68
69 _getfacl_filter_nsid()
70 {
71     sed \
72        -e "s/user:$ns_acl1/user:nsid1/" \
73        -e "s/user:$ns_acl2/user:nsid2/" \
74        -e "s/user:$ns_acl3/user:nsid3/" \
75        -e "s/group:$ns_acl1/group:nsid1/" \
76        -e "s/group:$ns_acl2/group:nsid2/" \
77        -e "s/group:$ns_acl3/group:nsid3/" \
78        -e "s/: $ns_acl1/: nsid1/" \
79        -e "s/: $ns_acl2/: nsid2/" \
80        -e "s/: $ns_acl3/: nsid3/"
81 }
82
83 _print_getfacls()
84 {
85     echo "From init_user_ns"
86     getfacl --absolute-names -n $file 2>/dev/null | _filter_scratch | _getfacl_filter_id
87
88     echo "From user_ns"
89     $nsexec -U -M "0 $acl1 1000" -G "0 $acl1 1000" getfacl --absolute-names -n $file 2>/dev/null | _filter_scratch | _getfacl_filter_nsid
90 }
91
92 _scratch_unmount >/dev/null 2>&1
93 echo "*** MKFS ***" >>$seqres.full
94 echo ""             >>$seqres.full
95 _scratch_mkfs       >>$seqres.full 2>&1 || _fail "mkfs failed"
96 _scratch_mount      >>$seqres.full 2>&1 || _fail "mount failed"
97
98 touch $file
99 chown $acl1.$acl1 $file
100
101 # set acls from init_user_ns, to be checked from inside the userns
102 setfacl -n -m u:$acl2:rw,g:$acl2:r $file
103 # set acls from inside userns, to be checked from init_user_ns
104 $nsexec -s -U -M "0 $acl1 1000" -G "0 $acl1 1000" setfacl -n -m u:root:rx,g:$ns_acl2:x $file
105
106 _print_getfacls
107
108 echo "*** Remounting ***"
109 echo ""
110 sync
111 _scratch_cycle_mount      >>$seqres.full 2>&1 || _fail "remount failed"
112
113 _print_getfacls
114
115 _scratch_unmount >/dev/null 2>&1
116 status=0
117 exit