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