fstests: _fail test by default when _scratch_mount fails
[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 _require_user
62 _require_ugid_map
63 _require_userns
64 qa_user_id=`id -u $qa_user`
65
66 _filter_output()
67 {
68     sed \
69       -e "s/$qa_user_id/qa_user/g" \
70       -e "s!$SCRATCH_MNT!\$SCRATCH_MNT!"
71 }
72
73 _print_numeric_uid()
74 {
75     echo "From init_user_ns"
76     src/lstat64 $file |head -3 |_filter_output
77
78     echo "From user_ns"
79     src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" src/lstat64 $file |head -3 |_filter_output
80 }
81
82 _scratch_unmount >/dev/null 2>&1
83 echo "*** MKFS ***" >>$seqres.full
84 echo ""             >>$seqres.full
85 _scratch_mkfs       >>$seqres.full 2>&1 || _fail "mkfs failed"
86 _scratch_mount
87 chmod 777 $SCRATCH_MNT
88
89 # create $file as "root" in userns, which is $qa_user in parent namespace
90 src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" touch $file
91
92 _print_numeric_uid
93
94 echo ""
95 echo "*** Remounting ***"
96 echo ""
97 sync
98 _scratch_cycle_mount      >>$seqres.full 2>&1 || _fail "remount failed"
99
100 _print_numeric_uid
101
102 _scratch_unmount >/dev/null 2>&1
103 status=0
104 exit