2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 IBM Corporation. All Rights Reserved.
7 # Test consistent d_ino numbers for samefs setup.
10 _begin_fstest auto quick copyup
12 # Import common functions.
16 # real QA test starts here
18 _fixed_in_kernel_version "v4.14"
20 # Use non-default scratch underlying overlay dirs, we need to check
21 # them explicity after test.
22 _require_scratch_nocheck
23 _require_attrs trusted
24 _require_test_program "t_dir_type"
26 _scratch_mkfs >>$seqres.full 2>&1
28 # Create our test files.
29 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
30 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
33 mkdir -p $lowerdir/test_dir/pure_lower_dir/subdir
35 touch $lowerdir/test_file
39 test_dir=$SCRATCH_MNT/test_dir/
41 # Verify d_ino of '.' and '..' before and after dir becomes impure.
42 impure_dir=$test_dir/impure_dir
43 mkdir -p $impure_dir/subdir
45 impure_dir_st_ino=$(stat -c '%i' $impure_dir)
46 impure_dir_parent_st_ino=$(stat -c '%i' $test_dir)
47 impure_subdir_st_ino=$(stat -c '%i' $impure_dir/subdir)
49 # Before $impure_dir becomes impure
50 parent_d=$($here/src/t_dir_type $impure_dir $impure_dir_parent_st_ino)
51 [[ $parent_d == ".. d" ]] || \
52 echo "Pure upper dir: Invalid d_ino reported for .."
54 current_d=$($here/src/t_dir_type $impure_dir $impure_dir_st_ino)
55 [[ $current_d == ". d" ]] || \
56 echo "Pure upper dir: Invalid d_ino reported for ."
58 subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino)
59 [[ $subdir_d == "subdir d" ]] || \
60 echo "Pure upper dir: Invalid d_ino reported for subdir"
62 # Move a copied up file into pure dir to make it impure
63 mv $SCRATCH_MNT/test_file $impure_dir
64 test_file_st_ino=$(stat -c '%i' $impure_dir/test_file)
66 impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \
67 $upperdir/test_dir/impure_dir)
68 [[ $impure == "y" ]] || echo "Impure directory missing impure xattr"
70 # After $impure_dir becomes impure
71 parent_d=$($here/src/t_dir_type $impure_dir $impure_dir_parent_st_ino)
72 [[ $parent_d == ".. d" ]] || \
73 echo "Impure dir: Invalid d_ino reported for .."
75 current_d=$($here/src/t_dir_type $impure_dir $impure_dir_st_ino)
76 [[ $current_d == ". d" ]] || \
77 echo "Impure dir: Invalid d_ino reported for ."
79 subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino)
80 [[ $subdir_d == "subdir d" ]] || \
81 echo "Impure dir: Invalid d_ino reported for subdir"
83 # Verify copy up file's d_ino
84 file_d=$($here/src/t_dir_type $impure_dir $test_file_st_ino)
85 [[ $file_d == "test_file f" ]] || \
86 echo "Impure dir: Invalid d_ino reported for entry with copy-up origin"
88 # Make $impure_dir pure
89 rm -rf $impure_dir/test_file
90 rm -rf $impure_dir/subdir
92 # Verify invalidation of readdir cache
93 $here/src/t_dir_type $impure_dir $test_file_st_ino
94 [[ $? != 0 ]] || echo "Directory's readdir cache has stale file entries"
95 $here/src/t_dir_type $impure_dir $impure_subdir_st_ino
96 [[ $? != 0 ]] || echo "Directory's readdir cache has stale subdir entries"
98 impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \
99 $upperdir/test_dir/impure_dir 2>/dev/null)
100 [[ -z $impure ]] || echo "Pure directory has impure xattr"
102 # Verify d_ino values of subdir entries of a pure lower dir.
103 parent_st_ino=$(stat -c '%i' $test_dir)
104 pure_lower_dir=$SCRATCH_MNT/test_dir/pure_lower_dir
105 pure_lower_dir_st_ino=$(stat -c '%i' $pure_lower_dir)
106 pure_lower_subdir_st_ino=$(stat -c '%i' $pure_lower_dir/subdir)
108 parent_d=$($here/src/t_dir_type $pure_lower_dir $parent_st_ino)
109 [[ $parent_d == ".. d" ]] || \
110 echo "Pure lower dir: Invalid d_ino reported for .."
112 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
113 [[ $current_d == ". d" ]] || \
114 echo "Pure lower dir: Invalid d_ino reported for ."
116 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
117 [[ $subdir_d == "subdir d" ]] || \
118 echo "Pure lower dir: Invalid d_ino reported for subdir"
120 # Create a file in pure lower dir to make it a merge dir
121 touch $pure_lower_dir/newfile
123 parent_d=$($here/src/t_dir_type $pure_lower_dir $parent_st_ino)
124 [[ $parent_d == ".. d" ]] || \
125 echo "Merged dir: Invalid d_ino reported for .."
127 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
128 [[ $current_d == ". d" ]] || \
129 echo "Merged dir: Invalid d_ino reported for ."
131 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
132 [[ $subdir_d == "subdir d" ]] || \
133 echo "Merged dir: Invalid d_ino reported for subdir"
140 # Verify pure lower residing in dir which has another lower layer
143 OVL_LOWER0=${OVL_LOWER}0
144 OVL_LOWER1=${OVL_LOWER}1
146 middir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER0
147 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER1
148 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
149 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
156 mkdir -p $lowerdir/test_dir/pure_lower_dir/subdir
158 _overlay_scratch_mount_dirs "$middir:$lowerdir" $upperdir $workdir
161 touch $test_dir/test_file
163 test_dir_st_ino=$(stat -c '%i' $test_dir)
164 pure_lower_dir=$test_dir/pure_lower_dir
165 pure_lower_dir_st_ino=$(stat -c '%i' $pure_lower_dir)
166 pure_lower_subdir_st_ino=$(stat -c '%i' $pure_lower_dir/subdir)
168 parent_d=$($here/src/t_dir_type $pure_lower_dir $test_dir_st_ino)
169 [[ $parent_d == ".. d" ]] || \
170 echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for .."
171 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
172 [[ $current_d == ". d" ]] || \
173 echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for ."
175 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
176 [[ $subdir_d == "subdir d" ]] || \
177 echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for subdir"
180 _overlay_check_scratch_dirs "$middir:$lowerdir" $upperdir $workdir
182 echo "Silence is golden"