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 commits:
10 # 65cd913ec9d9 ("ovl: invalidate readdir cache on changes to dir with origin")
11 # 9011c2791e63 ("ovl: skip stale entries in merge dir cache iteration")
14 _begin_fstest auto quick dir
16 # Import common functions.
19 # real QA test starts here
21 _require_scratch_nocheck
23 # Use small getdents bufsize to fit less than 10 entries
24 # stuct linux_dirent64 is 20 bytes not including d_name
27 # Create enough files to be returned in multiple gendents() calls.
28 # At least one of the files that we delete will not be listed in the
29 # first call, so we may encounter stale entries in following calls.
36 # remove all files from previous runs
39 # Create test area with a merge dir, a "former" merge dir,
40 # a pure upper dir and impure upper dir. For each case, overlayfs
41 # readdir cache is used a bit differently.
42 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
43 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
45 mkdir -p $lowerdir/merge $lowerdir/former $upperdir/pure $upperdir/impure
46 # Lower files in merge dir are listed first
47 create_files $lowerdir/merge m
48 # Files to be moved into impure upper dir
49 create_files $lowerdir o
50 # File to be moved into former merge dir to make it impure
55 create_files $SCRATCH_MNT/pure p
56 create_files $SCRATCH_MNT/former f
57 # Copy up file so readdir will need to lookup its origin d_ino
58 touch $SCRATCH_MNT/merge/m100
59 # Move copied up files so readdir will need to lookup origin d_ino
60 mv $SCRATCH_MNT/o* $SCRATCH_MNT/impure/
61 mv $SCRATCH_MNT/f100 $SCRATCH_MNT/former/
63 # Remove the lower directory and mount overlay again to create
64 # a "former merge dir"
65 $UMOUNT_PROG $SCRATCH_MNT
66 rm -rf $lowerdir/former
69 # Check readdir cache invalidate on pure upper dir
70 echo -e "\nCreate file in pure upper dir:" >> $seqres.full
71 $here/src/t_dir_offset2 $SCRATCH_MNT/pure $bufsize "+p0" 2>&1 >> $seqres.full || \
72 echo "Missing created file in pure upper dir (see $seqres.full for details)"
73 echo -e "\nRemove file in pure upper dir:" >> $seqres.full
74 $here/src/t_dir_offset2 $SCRATCH_MNT/pure $bufsize "-p100" 2>&1 >> $seqres.full || \
75 echo "Found unlinked file in pure upper dir (see $seqres.full for details)"
77 # Check readdir cache invalidate on impure upper dir
78 echo -e "\nCreate file in impure upper dir:" >> $seqres.full
79 $here/src/t_dir_offset2 $SCRATCH_MNT/impure $bufsize "+o0" 2>&1 >> $seqres.full || \
80 echo "Missing created file in impure upper dir (see $seqres.full for details)"
81 echo -e "\nRemove file in impure upper dir:" >> $seqres.full
82 $here/src/t_dir_offset2 $SCRATCH_MNT/impure $bufsize "-o100" 2>&1 >> $seqres.full || \
83 echo "Found unlinked file in impure upper dir (see $seqres.full for details)"
85 # Check readdir cache invalidate on merge dir
86 echo -e "\nCreate file in merge dir:" >> $seqres.full
87 $here/src/t_dir_offset2 $SCRATCH_MNT/merge $bufsize "+m0" 2>&1 >> $seqres.full || \
88 echo "Missing created file in merge dir (see $seqres.full for details)"
89 echo -e "\nRemove file in merge dir:" >> $seqres.full
90 $here/src/t_dir_offset2 $SCRATCH_MNT/merge $bufsize "-m100" 2>&1 >> $seqres.full || \
91 echo "Found unlinked file in merge dir (see $seqres.full for details)"
93 # Check readdir cache invalidate on former merge dir
94 echo -e "\nCreate file in former merge dir:" >> $seqres.full
95 $here/src/t_dir_offset2 $SCRATCH_MNT/former $bufsize "+f0" 2>&1 >> $seqres.full || \
96 echo "Missing created file in former merge dir (see $seqres.full for details)"
97 echo -e "\nRemove file in former merge dir:" >> $seqres.full
98 $here/src/t_dir_offset2 $SCRATCH_MNT/former $bufsize "-f100" 2>&1 >> $seqres.full || \
99 echo "Found unlinked file in former merge dir (see $seqres.full for details)"
102 echo "Silence is golden"