2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 IBM Corporation. All Rights Reserved.
7 # Test consistent d_ino numbers on non-samefs setup
8 # This is a variant of overlay/038 to test consistent d_ino numbers
9 # for non-samefs setup.
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
26 # get standard environment, filters and checks
31 # real QA test starts here
33 # Use non-default scratch underlying overlay dirs, we need to check
34 # them explicity after test.
35 _require_scratch_nocheck
37 _require_attrs trusted
38 _require_test_program "t_dir_type"
42 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
46 # Create our test files.
47 mkdir -p $lowerdir/test_dir/pure_lower_dir/subdir
48 touch $lowerdir/test_file
52 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
53 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
55 # Enabling xino in this test requires that base filesystem inode numbers will
56 # not use bit 63 in inode number of the test files, because bit 63 is used by
57 # overlayfs to indicate the layer. Let's just assume that this is true for all
58 # tested filesystems and if we are wrong, the test may fail.
59 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o xino=on || \
60 _notrun "cannot mount overlay with xino=on option"
61 _fs_options $SCRATCH_DEV | grep -q "xino=on" || \
62 _notrun "cannot enable xino feature"
64 test_dir=$SCRATCH_MNT/test_dir/
66 # Verify d_ino of '.' and '..' before and after dir becomes impure.
67 impure_dir=$test_dir/impure_dir
68 mkdir -p $impure_dir/subdir
70 impure_dir_st_ino=$(stat -c '%i' $impure_dir)
71 impure_dir_parent_st_ino=$(stat -c '%i' $test_dir)
72 impure_subdir_st_ino=$(stat -c '%i' $impure_dir/subdir)
74 # Before $impure_dir becomes impure
75 parent_d=$($here/src/t_dir_type $impure_dir $impure_dir_parent_st_ino)
76 [[ $parent_d == ".. d" ]] || \
77 echo "Pure upper dir: Invalid d_ino reported for .."
79 current_d=$($here/src/t_dir_type $impure_dir $impure_dir_st_ino)
80 [[ $current_d == ". d" ]] || \
81 echo "Pure upper dir: Invalid d_ino reported for ."
83 subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino)
84 [[ $subdir_d == "subdir d" ]] || \
85 echo "Pure upper dir: Invalid d_ino reported for subdir"
87 # Move a copied up file into pure dir to make it impure
88 mv $SCRATCH_MNT/test_file $impure_dir
89 test_file_st_ino=$(stat -c '%i' $impure_dir/test_file)
91 impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \
92 $upperdir/test_dir/impure_dir)
93 [[ $impure == "y" ]] || echo "Impure directory missing impure xattr"
95 # After $impure_dir becomes impure
96 parent_d=$($here/src/t_dir_type $impure_dir $impure_dir_parent_st_ino)
97 [[ $parent_d == ".. d" ]] || \
98 echo "Impure dir: Invalid d_ino reported for .."
100 current_d=$($here/src/t_dir_type $impure_dir $impure_dir_st_ino)
101 [[ $current_d == ". d" ]] || \
102 echo "Impure dir: Invalid d_ino reported for ."
104 subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino)
105 [[ $subdir_d == "subdir d" ]] || \
106 echo "Impure dir: Invalid d_ino reported for subdir"
108 # Verify copy up file's d_ino
109 file_d=$($here/src/t_dir_type $impure_dir $test_file_st_ino)
110 [[ $file_d == "test_file f" ]] || \
111 echo "Impure dir: Invalid d_ino reported for entry with copy-up origin"
113 # Make $impure_dir pure
114 rm -rf $impure_dir/test_file
115 rm -rf $impure_dir/subdir
117 # Verify invalidation of readdir cache
118 $here/src/t_dir_type $impure_dir $test_file_st_ino
119 [[ $? != 0 ]] || echo "Directory's readdir cache has stale file entries"
120 $here/src/t_dir_type $impure_dir $impure_subdir_st_ino
121 [[ $? != 0 ]] || echo "Directory's readdir cache has stale subdir entries"
123 impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \
124 $upperdir/test_dir/impure_dir 2>/dev/null)
125 [[ -z $impure ]] || echo "Pure directory has impure xattr"
127 # Verify d_ino values of subdir entries of a pure lower dir.
128 parent_st_ino=$(stat -c '%i' $test_dir)
129 pure_lower_dir=$SCRATCH_MNT/test_dir/pure_lower_dir
130 pure_lower_dir_st_ino=$(stat -c '%i' $pure_lower_dir)
131 pure_lower_subdir_st_ino=$(stat -c '%i' $pure_lower_dir/subdir)
133 parent_d=$($here/src/t_dir_type $pure_lower_dir $parent_st_ino)
134 [[ $parent_d == ".. d" ]] || \
135 echo "Pure lower dir: Invalid d_ino reported for .."
137 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
138 [[ $current_d == ". d" ]] || \
139 echo "Pure lower dir: Invalid d_ino reported for ."
141 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
142 [[ $subdir_d == "subdir d" ]] || \
143 echo "Pure lower dir: Invalid d_ino reported for subdir"
145 # Create a file in pure lower dir to make it a merge dir
146 touch $pure_lower_dir/newfile
148 parent_d=$($here/src/t_dir_type $pure_lower_dir $parent_st_ino)
149 [[ $parent_d == ".. d" ]] || \
150 echo "Merged dir: Invalid d_ino reported for .."
152 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
153 [[ $current_d == ". d" ]] || \
154 echo "Merged dir: Invalid d_ino reported for ."
156 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
157 [[ $subdir_d == "subdir d" ]] || \
158 echo "Merged dir: Invalid d_ino reported for subdir"
160 $UMOUNT_PROG $SCRATCH_MNT
163 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir -o xino=on
165 # Verify pure lower residing in dir which has another lower layer
166 middir=$OVL_BASE_TEST_DIR/$seq-ovl-mid
167 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
173 mkdir -p $middir/test_dir
174 mkdir -p $lowerdir/test_dir/pure_lower_dir/subdir
178 _overlay_scratch_mount_dirs $middir:$lowerdir $upperdir $workdir -o xino=on
181 touch $test_dir/test_file
183 test_dir_st_ino=$(stat -c '%i' $test_dir)
184 pure_lower_dir=$test_dir/pure_lower_dir
185 pure_lower_dir_st_ino=$(stat -c '%i' $pure_lower_dir)
186 pure_lower_subdir_st_ino=$(stat -c '%i' $pure_lower_dir/subdir)
188 parent_d=$($here/src/t_dir_type $pure_lower_dir $test_dir_st_ino)
189 [[ $parent_d == ".. d" ]] || \
190 echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for .."
192 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
193 [[ $current_d == ". d" ]] || \
194 echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for ."
196 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
197 [[ $subdir_d == "subdir d" ]] || \
198 echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for subdir"
201 _overlay_check_scratch_dirs "$middir:$lowerdir" $upperdir $workdir -o xino=on
203 echo "Silence is golden"