1aded76868d9593b48103c1bde808a8b6ada2410
[xfstests-dev.git] / tests / generic / 317
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2013 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 317
6 #
7 # Check uid/gid to/from disk with a user namespace. A new file
8 # will be created from inside a userns. We check that the uid/gid
9 # is correct from both inside the userns and also from init_user_ns.
10 # We will then unmount and remount the file system and check the
11 # uid/gid from both inside the userns and from init_user_ns to show
12 # that the correct uid was flushed and brought back from disk.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21
22 _cleanup()
23 {
24     cd /
25     _scratch_unmount >/dev/null 2>&1
26 }
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/attr
33
34 file=$SCRATCH_MNT/file1
35
36 # real QA test starts here
37 _supported_fs generic
38 # only Linux supports user namespace
39 _supported_os Linux
40
41 [ -x $lstat64 ] || _notrun "$lstat64 executable not found"
42
43 rm -f $seqres.full
44
45 _require_scratch
46 _require_user
47 _require_ugid_map
48 _require_userns
49 qa_user_id=`id -u $qa_user`
50
51 _filter_output()
52 {
53     sed \
54       -e "s/$qa_user_id/qa_user/g" \
55       -e "s!$SCRATCH_MNT!\$SCRATCH_MNT!"
56 }
57
58 _print_numeric_uid()
59 {
60     echo "From init_user_ns"
61     src/lstat64 $file |head -3 |_filter_output
62
63     echo "From user_ns"
64     src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" src/lstat64 $file |head -3 |_filter_output
65 }
66
67 _scratch_unmount >/dev/null 2>&1
68 echo "*** MKFS ***" >>$seqres.full
69 echo ""             >>$seqres.full
70 _scratch_mkfs       >>$seqres.full 2>&1 || _fail "mkfs failed"
71 _scratch_mount
72 chmod 777 $SCRATCH_MNT
73
74 # create $file as "root" in userns, which is $qa_user in parent namespace
75 src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" touch $file
76
77 _print_numeric_uid
78
79 echo ""
80 echo "*** Remounting ***"
81 echo ""
82 sync
83 _scratch_cycle_mount      >>$seqres.full 2>&1 || _fail "remount failed"
84
85 _print_numeric_uid
86
87 _scratch_unmount >/dev/null 2>&1
88 status=0
89 exit