6510f81f6411736cd33a1758c34ec96964d9ef3f
[xfstests-dev.git] / tests / overlay / 077
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test 077
6 #
7 # Test invalidate of readdir cache
8 #
9 # This is a regression test for kernel commit 65cd913ec9d9
10 # ("ovl: invalidate readdir cache on changes to dir with origin")
11 #
12 . ./common/preamble
13 _begin_fstest auto quick dir
14
15 # Import common functions.
16 . ./common/filter
17
18 # real QA test starts here
19 _supported_fs overlay
20 _require_scratch_nocheck
21
22 # Use small getdents bufsize to fit less than 10 entries
23 # stuct linux_dirent64 is 20 bytes not including d_name
24 bufsize=200
25
26 # Create enough files to be returned in multiple gendents() calls.
27 # At least one of the files that we delete will not be listed in the
28 # first call, so we may encounter stale entries in following calls.
29 create_files() {
30         for n in {1..100}; do
31                 touch ${1}/${2}${n}
32         done
33 }
34
35 # remove all files from previous runs
36 _scratch_mkfs
37
38 # Create test area with a merge dir, a "former" merge dir,
39 # a pure upper dir and impure upper dir. For each case, overlayfs
40 # readdir cache is used a bit differently.
41 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
42 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
43
44 mkdir -p $lowerdir/merge $lowerdir/former $upperdir/pure $upperdir/impure
45 # Lower files in merge dir are listed first
46 create_files $lowerdir/merge m
47 # Files to be moved into impure upper dir
48 create_files $lowerdir o
49 # File to be copied up to make former merge dir impure
50 touch $lowerdir/former/f100
51
52 _scratch_mount
53
54 create_files $SCRATCH_MNT/pure p
55 create_files $SCRATCH_MNT/former f
56 # Copy up file so readdir will need to lookup its origin d_ino
57 touch $SCRATCH_MNT/merge/m100
58 # Move copied up files so readdir will need to lookup origin d_ino
59 mv $SCRATCH_MNT/o* $SCRATCH_MNT/impure/
60
61 # Remove the lower directory and mount overlay again to create
62 # a "former merge dir"
63 $UMOUNT_PROG $SCRATCH_MNT
64 rm -rf $lowerdir/former
65 _scratch_mount
66
67 # Check readdir cache invalidate on pure upper dir
68 echo -e "\nCreate file in pure upper dir:" >> $seqres.full
69 $here/src/t_dir_offset2 $SCRATCH_MNT/pure $bufsize "+p0" 2>&1 >> $seqres.full || \
70         echo "Missing created file in pure upper dir (see $seqres.full for details)"
71 echo -e "\nRemove file in pure upper dir:" >> $seqres.full
72 $here/src/t_dir_offset2 $SCRATCH_MNT/pure $bufsize "-p100" 2>&1 >> $seqres.full || \
73         echo "Found unlinked file in pure upper dir (see $seqres.full for details)"
74
75 # Check readdir cache invalidate on impure upper dir
76 echo -e "\nCreate file in impure upper dir:" >> $seqres.full
77 $here/src/t_dir_offset2 $SCRATCH_MNT/impure $bufsize "+o0" 2>&1 >> $seqres.full || \
78         echo "Missing created file in impure upper dir (see $seqres.full for details)"
79 echo -e "\nRemove file in impure upper dir:" >> $seqres.full
80 $here/src/t_dir_offset2 $SCRATCH_MNT/impure $bufsize  "-o100" 2>&1 >> $seqres.full || \
81         echo "Found unlinked file in impure upper dir (see $seqres.full for details)"
82
83 # Check readdir cache invalidate on merge dir
84 echo -e "\nCreate file in merge dir:" >> $seqres.full
85 $here/src/t_dir_offset2 $SCRATCH_MNT/merge $bufsize "+m0" 2>&1 >> $seqres.full || \
86         echo "Missing created file in merge dir (see $seqres.full for details)"
87 echo -e "\nRemove file in merge dir:" >> $seqres.full
88 $here/src/t_dir_offset2 $SCRATCH_MNT/merge $bufsize "-m100" 2>&1 >> $seqres.full || \
89         echo "Found unlinked file in merge dir (see $seqres.full for details)"
90
91 # Check readdir cache invalidate on former merge dir
92 echo -e "\nCreate file in former merge dir:" >> $seqres.full
93 $here/src/t_dir_offset2 $SCRATCH_MNT/former $bufsize "+f0" 2>&1 >> $seqres.full || \
94         echo "Missing created file in former merge dir (see $seqres.full for details)"
95 echo -e "\nRemove file in former merge dir:" >> $seqres.full
96 $here/src/t_dir_offset2 $SCRATCH_MNT/former $bufsize "-f100" 2>&1 >> $seqres.full || \
97         echo "Found unlinked file in former merge dir (see $seqres.full for details)"
98
99 # success, all done
100 echo "Silence is golden"
101 status=0
102 exit