2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 CTERA Networks. All Rights Reserved.
7 # Test invalidate of readdir cache
9 # This is a regression test for kernel commit 65cd913ec9d9
10 # ("ovl: invalidate readdir cache on changes to dir with origin")
13 _begin_fstest auto quick dir
15 # Import common functions.
18 # real QA test starts here
20 _require_scratch_nocheck
22 # Use small getdents bufsize to fit less than 10 entries
23 # stuct linux_dirent64 is 20 bytes not including d_name
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.
35 # remove all files from previous runs
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
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 moved into former merge dir to make it impure
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 mv $SCRATCH_MNT/f100 $SCRATCH_MNT/former/
62 # Remove the lower directory and mount overlay again to create
63 # a "former merge dir"
64 $UMOUNT_PROG $SCRATCH_MNT
65 rm -rf $lowerdir/former
68 # Check readdir cache invalidate on pure upper dir
69 echo -e "\nCreate file in pure upper dir:" >> $seqres.full
70 $here/src/t_dir_offset2 $SCRATCH_MNT/pure $bufsize "+p0" 2>&1 >> $seqres.full || \
71 echo "Missing created file in pure upper dir (see $seqres.full for details)"
72 echo -e "\nRemove file in pure upper dir:" >> $seqres.full
73 $here/src/t_dir_offset2 $SCRATCH_MNT/pure $bufsize "-p100" 2>&1 >> $seqres.full || \
74 echo "Found unlinked file in pure upper dir (see $seqres.full for details)"
76 # Check readdir cache invalidate on impure upper dir
77 echo -e "\nCreate file in impure upper dir:" >> $seqres.full
78 $here/src/t_dir_offset2 $SCRATCH_MNT/impure $bufsize "+o0" 2>&1 >> $seqres.full || \
79 echo "Missing created file in impure upper dir (see $seqres.full for details)"
80 echo -e "\nRemove file in impure upper dir:" >> $seqres.full
81 $here/src/t_dir_offset2 $SCRATCH_MNT/impure $bufsize "-o100" 2>&1 >> $seqres.full || \
82 echo "Found unlinked file in impure upper dir (see $seqres.full for details)"
84 # Check readdir cache invalidate on merge dir
85 echo -e "\nCreate file in merge dir:" >> $seqres.full
86 $here/src/t_dir_offset2 $SCRATCH_MNT/merge $bufsize "+m0" 2>&1 >> $seqres.full || \
87 echo "Missing created file in merge dir (see $seqres.full for details)"
88 echo -e "\nRemove file in merge dir:" >> $seqres.full
89 $here/src/t_dir_offset2 $SCRATCH_MNT/merge $bufsize "-m100" 2>&1 >> $seqres.full || \
90 echo "Found unlinked file in merge dir (see $seqres.full for details)"
92 # Check readdir cache invalidate on former merge dir
93 echo -e "\nCreate file in former merge dir:" >> $seqres.full
94 $here/src/t_dir_offset2 $SCRATCH_MNT/former $bufsize "+f0" 2>&1 >> $seqres.full || \
95 echo "Missing created file in former merge dir (see $seqres.full for details)"
96 echo -e "\nRemove file in former merge dir:" >> $seqres.full
97 $here/src/t_dir_offset2 $SCRATCH_MNT/former $bufsize "-f100" 2>&1 >> $seqres.full || \
98 echo "Found unlinked file in former merge dir (see $seqres.full for details)"
101 echo "Silence is golden"