fstests: filter redundant output by getfattr
[xfstests-dev.git] / tests / overlay / 041
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 IBM Corporation. All Rights Reserved.
4 #
5 # FSQA Test No. 041
6 #
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.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/attr
30
31 # real QA test starts here
32 _supported_fs overlay
33 _supported_os Linux
34 # Use non-default scratch underlying overlay dirs, we need to check
35 # them explicity after test.
36 _require_scratch_nocheck
37 _require_test
38 _require_attrs
39 _require_test_program "t_dir_type"
40
41 rm -f $seqres.full
42
43 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
44 rm -rf $lowerdir
45 mkdir $lowerdir
46
47 # Create our test files.
48 mkdir -p $lowerdir/test_dir/pure_lower_dir/subdir
49 touch $lowerdir/test_file
50
51 _scratch_mkfs
52
53 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
54 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
55
56 # Enabling xino in this test requires that base filesystem inode numbers will
57 # not use bit 63 in inode number of the test files, because bit 63 is used by
58 # overlayfs to indicate the layer. Let's just assume that this is true for all
59 # tested filesystems and if we are wrong, the test may fail.
60 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o xino=on || \
61         _notrun "cannot mount overlay with xino=on option"
62 _fs_options $SCRATCH_DEV | grep -q "xino=on" || \
63         _notrun "cannot enable xino feature"
64
65 test_dir=$SCRATCH_MNT/test_dir/
66
67 # Verify d_ino of '.' and '..' before and after dir becomes impure.
68 impure_dir=$test_dir/impure_dir
69 mkdir -p $impure_dir/subdir
70
71 impure_dir_st_ino=$(stat -c '%i' $impure_dir)
72 impure_dir_parent_st_ino=$(stat -c '%i' $test_dir)
73 impure_subdir_st_ino=$(stat -c '%i' $impure_dir/subdir)
74
75 # Before $impure_dir becomes impure
76 parent_d=$($here/src/t_dir_type $impure_dir $impure_dir_parent_st_ino)
77 [[ $parent_d == ".. d" ]] || \
78     echo "Pure upper dir: Invalid d_ino reported for .."
79
80 current_d=$($here/src/t_dir_type $impure_dir $impure_dir_st_ino)
81 [[ $current_d == ". d" ]] || \
82     echo "Pure upper dir: Invalid d_ino reported for ."
83
84 subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino)
85 [[ $subdir_d == "subdir d" ]] || \
86     echo "Pure upper dir: Invalid d_ino reported for subdir"
87
88 # Move a copied up file into pure dir to make it impure
89 mv $SCRATCH_MNT/test_file $impure_dir
90 test_file_st_ino=$(stat -c '%i' $impure_dir/test_file)
91
92 impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \
93                         $upperdir/test_dir/impure_dir)
94 [[ $impure == "y" ]] || echo "Impure directory missing impure xattr"
95
96 # After $impure_dir becomes impure
97 parent_d=$($here/src/t_dir_type $impure_dir $impure_dir_parent_st_ino)
98 [[ $parent_d == ".. d" ]] || \
99     echo "Impure dir: Invalid d_ino reported for .."
100
101 current_d=$($here/src/t_dir_type $impure_dir $impure_dir_st_ino)
102 [[ $current_d == ". d" ]] || \
103     echo "Impure dir: Invalid d_ino reported for ."
104
105 subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino)
106 [[ $subdir_d == "subdir d" ]] || \
107     echo "Impure dir: Invalid d_ino reported for subdir"
108
109 # Verify copy up file's d_ino
110 file_d=$($here/src/t_dir_type $impure_dir $test_file_st_ino)
111 [[ $file_d == "test_file f" ]] || \
112         echo "Impure dir: Invalid d_ino reported for entry with copy-up origin"
113
114 # Make $impure_dir pure
115 rm -rf $impure_dir/test_file
116 rm -rf $impure_dir/subdir
117
118 # Verify invalidation of readdir cache
119 $here/src/t_dir_type $impure_dir $test_file_st_ino
120 [[ $? != 0 ]] || echo "Directory's readdir cache has stale file entries"
121 $here/src/t_dir_type $impure_dir $impure_subdir_st_ino
122 [[ $? != 0 ]] || echo "Directory's readdir cache has stale subdir entries"
123
124 impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \
125                         $upperdir/test_dir/impure_dir 2>/dev/null)
126 [[ -z $impure ]] || echo "Pure directory has impure xattr"
127
128 # Verify d_ino values of subdir entries of a pure lower dir.
129 parent_st_ino=$(stat -c '%i' $test_dir)
130 pure_lower_dir=$SCRATCH_MNT/test_dir/pure_lower_dir
131 pure_lower_dir_st_ino=$(stat -c '%i' $pure_lower_dir)
132 pure_lower_subdir_st_ino=$(stat -c '%i' $pure_lower_dir/subdir)
133
134 parent_d=$($here/src/t_dir_type $pure_lower_dir $parent_st_ino)
135 [[ $parent_d == ".. d" ]] || \
136         echo "Pure lower dir: Invalid d_ino reported for .."
137
138 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
139 [[ $current_d == ". d" ]] || \
140         echo "Pure lower dir: Invalid d_ino reported for ."
141
142 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
143 [[ $subdir_d == "subdir d" ]] || \
144         echo "Pure lower dir: Invalid d_ino reported for subdir"
145
146 # Create a file in pure lower dir to make it a merge dir
147 touch $pure_lower_dir/newfile
148
149 parent_d=$($here/src/t_dir_type $pure_lower_dir $parent_st_ino)
150 [[ $parent_d == ".. d" ]] || \
151         echo "Merged dir: Invalid d_ino reported for .."
152
153 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
154 [[ $current_d == ". d" ]] || \
155         echo "Merged dir: Invalid d_ino reported for ."
156
157 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
158 [[ $subdir_d == "subdir d" ]] || \
159         echo "Merged dir: Invalid d_ino reported for subdir"
160
161 $UMOUNT_PROG $SCRATCH_MNT
162
163 # check overlayfs
164 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir -o xino=on
165
166 # Verify pure lower residing in dir which has another lower layer
167 middir=$OVL_BASE_TEST_DIR/$seq-ovl-mid
168 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
169 rm -rf $middir
170 rm -rf $lowerdir
171 mkdir $middir
172 mkdir $lowerdir
173
174 mkdir -p $middir/test_dir
175 mkdir -p $lowerdir/test_dir/pure_lower_dir/subdir
176
177 _scratch_mkfs
178
179 _overlay_scratch_mount_dirs $middir:$lowerdir $upperdir $workdir -o xino=on
180
181 # Copy up test_dir
182 touch $test_dir/test_file
183
184 test_dir_st_ino=$(stat -c '%i' $test_dir)
185 pure_lower_dir=$test_dir/pure_lower_dir
186 pure_lower_dir_st_ino=$(stat -c '%i' $pure_lower_dir)
187 pure_lower_subdir_st_ino=$(stat -c '%i' $pure_lower_dir/subdir)
188
189 parent_d=$($here/src/t_dir_type $pure_lower_dir $test_dir_st_ino)
190 [[ $parent_d == ".. d" ]] || \
191         echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for .."
192
193 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
194 [[ $current_d == ". d" ]] || \
195         echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for ."
196
197 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
198 [[ $subdir_d == "subdir d" ]] || \
199         echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for subdir"
200
201 # check overlayfs
202 _overlay_check_scratch_dirs "$middir:$lowerdir" $upperdir $workdir -o xino=on
203
204 echo "Silence is golden"
205 status=0
206 exit