2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2013 Oracle, Inc. All Rights Reserved.
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.
15 _begin_fstest auto metadata quick
17 # Override the default cleanup function.
21 _scratch_unmount >/dev/null 2>&1
24 # Import common functions.
28 file=$SCRATCH_MNT/file1
30 # real QA test starts here
32 # only Linux supports user namespace
34 [ -x $lstat64 ] || _notrun "$lstat64 executable not found"
41 qa_user_id=`id -u $qa_user`
46 -e "s/$qa_user_id/qa_user/g" \
47 -e "s!$SCRATCH_MNT!\$SCRATCH_MNT!"
52 echo "From init_user_ns"
53 $here/src/lstat64 $file |head -3 |_filter_output
56 # don't use $here/src/lstat64, as we're running cmd(src/lstat64) in
57 # nsexec as a regular user, and $here may contain path component that
58 # a regular user doesn't have search permission
59 $here/src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" src/lstat64 $file |head -3 |_filter_output
62 _scratch_unmount >/dev/null 2>&1
63 echo "*** MKFS ***" >>$seqres.full
64 echo "" >>$seqres.full
65 _scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
67 chmod 777 $SCRATCH_MNT
69 # create $file as "root" in userns, which is $qa_user in parent namespace
70 $here/src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" touch $file
75 echo "*** Remounting ***"
78 _scratch_cycle_mount >>$seqres.full 2>&1 || _fail "remount failed"
82 _scratch_unmount >/dev/null 2>&1