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