fstests: move test group info to test files
[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 . ./common/preamble
10 _begin_fstest auto quick copyup
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/attr
15
16 # real QA test starts here
17 _supported_fs overlay
18 # Use non-default scratch underlying overlay dirs, we need to check
19 # them explicity after test.
20 _require_scratch_nocheck
21 _require_attrs trusted
22 _require_test_program "t_dir_type"
23
24 _scratch_mkfs >>$seqres.full 2>&1
25
26 # Create our test files.
27 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
28 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
29 mkdir -p $lowerdir
30
31 mkdir -p $lowerdir/test_dir/pure_lower_dir/subdir
32
33 touch $lowerdir/test_file
34
35 _scratch_mount
36
37 test_dir=$SCRATCH_MNT/test_dir/
38
39 # Verify d_ino of '.' and '..' before and after dir becomes impure.
40 impure_dir=$test_dir/impure_dir
41 mkdir -p $impure_dir/subdir
42
43 impure_dir_st_ino=$(stat -c '%i' $impure_dir)
44 impure_dir_parent_st_ino=$(stat -c '%i' $test_dir)
45 impure_subdir_st_ino=$(stat -c '%i' $impure_dir/subdir)
46
47 # Before $impure_dir becomes impure
48 parent_d=$($here/src/t_dir_type $impure_dir $impure_dir_parent_st_ino)
49 [[ $parent_d == ".. d" ]] || \
50     echo "Pure upper dir: Invalid d_ino reported for .."
51
52 current_d=$($here/src/t_dir_type $impure_dir $impure_dir_st_ino)
53 [[ $current_d == ". d" ]] || \
54     echo "Pure upper dir: Invalid d_ino reported for ."
55
56 subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino)
57 [[ $subdir_d == "subdir d" ]] || \
58     echo "Pure upper dir: Invalid d_ino reported for subdir"
59
60 # Move a copied up file into pure dir to make it impure
61 mv $SCRATCH_MNT/test_file $impure_dir
62 test_file_st_ino=$(stat -c '%i' $impure_dir/test_file)
63
64 impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \
65                         $upperdir/test_dir/impure_dir)
66 [[ $impure == "y" ]] || echo "Impure directory missing impure xattr"
67
68 # After $impure_dir becomes impure
69 parent_d=$($here/src/t_dir_type $impure_dir $impure_dir_parent_st_ino)
70 [[ $parent_d == ".. d" ]] || \
71     echo "Impure dir: Invalid d_ino reported for .."
72
73 current_d=$($here/src/t_dir_type $impure_dir $impure_dir_st_ino)
74 [[ $current_d == ". d" ]] || \
75     echo "Impure dir: Invalid d_ino reported for ."
76
77 subdir_d=$($here/src/t_dir_type $impure_dir $impure_subdir_st_ino)
78 [[ $subdir_d == "subdir d" ]] || \
79     echo "Impure dir: Invalid d_ino reported for subdir"
80
81 # Verify copy up file's d_ino
82 file_d=$($here/src/t_dir_type $impure_dir $test_file_st_ino)
83 [[ $file_d == "test_file f" ]] || \
84         echo "Impure dir: Invalid d_ino reported for entry with copy-up origin"
85
86 # Make $impure_dir pure
87 rm -rf $impure_dir/test_file
88 rm -rf $impure_dir/subdir
89
90 # Verify invalidation of readdir cache
91 $here/src/t_dir_type $impure_dir $test_file_st_ino
92 [[ $? != 0 ]] || echo "Directory's readdir cache has stale file entries"
93 $here/src/t_dir_type $impure_dir $impure_subdir_st_ino
94 [[ $? != 0 ]] || echo "Directory's readdir cache has stale subdir entries"
95
96 impure=$(_getfattr --absolute-names --only-values -n 'trusted.overlay.impure' \
97                         $upperdir/test_dir/impure_dir 2>/dev/null)
98 [[ -z $impure ]] || echo "Pure directory has impure xattr"
99
100 # Verify d_ino values of subdir entries of a pure lower dir.
101 parent_st_ino=$(stat -c '%i' $test_dir)
102 pure_lower_dir=$SCRATCH_MNT/test_dir/pure_lower_dir
103 pure_lower_dir_st_ino=$(stat -c '%i' $pure_lower_dir)
104 pure_lower_subdir_st_ino=$(stat -c '%i' $pure_lower_dir/subdir)
105
106 parent_d=$($here/src/t_dir_type $pure_lower_dir $parent_st_ino)
107 [[ $parent_d == ".. d" ]] || \
108         echo "Pure lower dir: Invalid d_ino reported for .."
109
110 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
111 [[ $current_d == ". d" ]] || \
112         echo "Pure lower dir: Invalid d_ino reported for ."
113
114 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
115 [[ $subdir_d == "subdir d" ]] || \
116         echo "Pure lower dir: Invalid d_ino reported for subdir"
117
118 # Create a file in pure lower dir to make it a merge dir
119 touch $pure_lower_dir/newfile
120
121 parent_d=$($here/src/t_dir_type $pure_lower_dir $parent_st_ino)
122 [[ $parent_d == ".. d" ]] || \
123         echo "Merged 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 "Merged 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 "Merged dir: Invalid d_ino reported for subdir"
132
133 _scratch_unmount
134
135 # check overlayfs
136 _check_scratch_fs
137
138 # Verify pure lower residing in dir which has another lower layer
139 _scratch_mkfs
140
141 OVL_LOWER0=${OVL_LOWER}0
142 OVL_LOWER1=${OVL_LOWER}1
143
144 middir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER0
145 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER1
146 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
147 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
148
149 mkdir -p $middir
150 mkdir -p $lowerdir
151 mkdir -p $upperdir
152 mkdir -p $workdir
153
154 mkdir -p $lowerdir/test_dir/pure_lower_dir/subdir
155
156 _overlay_scratch_mount_dirs "$middir:$lowerdir" $upperdir $workdir
157
158 # Copy up test_dir
159 touch $test_dir/test_file
160
161 test_dir_st_ino=$(stat -c '%i' $test_dir)
162 pure_lower_dir=$test_dir/pure_lower_dir
163 pure_lower_dir_st_ino=$(stat -c '%i' $pure_lower_dir)
164 pure_lower_subdir_st_ino=$(stat -c '%i' $pure_lower_dir/subdir)
165
166 parent_d=$($here/src/t_dir_type $pure_lower_dir $test_dir_st_ino)
167 [[ $parent_d == ".. d" ]] || \
168         echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for .."
169 current_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_dir_st_ino)
170 [[ $current_d == ". d" ]] || \
171         echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for ."
172
173 subdir_d=$($here/src/t_dir_type $pure_lower_dir $pure_lower_subdir_st_ino)
174 [[ $subdir_d == "subdir d" ]] || \
175         echo "Pure lower in dir which has another lower layer: Invalid d_ino reported for subdir"
176
177 # check overlayfs
178 _overlay_check_scratch_dirs "$middir:$lowerdir" $upperdir $workdir
179
180 echo "Silence is golden"
181 status=0
182 exit