generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
15 _begin_fstest auto metadata quick
16
17 # Override the default cleanup function.
18 _cleanup()
19 {
20     cd /
21     _scratch_unmount >/dev/null 2>&1
22 }
23
24 # Import common functions.
25 . ./common/filter
26 . ./common/attr
27
28 file=$SCRATCH_MNT/file1
29
30 # real QA test starts here
31 _supported_fs generic
32 # only Linux supports user namespace
33
34 [ -x $lstat64 ] || _notrun "$lstat64 executable not found"
35
36 _require_scratch
37 _require_user
38 _require_ugid_map
39 _require_userns
40 _require_chown
41 qa_user_id=`id -u $qa_user`
42
43 _filter_output()
44 {
45     sed \
46       -e "s/$qa_user_id/qa_user/g" \
47       -e "s!$SCRATCH_MNT!\$SCRATCH_MNT!"
48 }
49
50 _print_numeric_uid()
51 {
52     echo "From init_user_ns"
53     $here/src/lstat64 $file |head -3 |_filter_output
54
55     echo "From user_ns"
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
60 }
61
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"
66 _scratch_mount
67 chmod 777 $SCRATCH_MNT
68
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
71
72 _print_numeric_uid
73
74 echo ""
75 echo "*** Remounting ***"
76 echo ""
77 sync
78 _scratch_cycle_mount      >>$seqres.full 2>&1 || _fail "remount failed"
79
80 _print_numeric_uid
81
82 _scratch_unmount >/dev/null 2>&1
83 status=0
84 exit