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 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
27 # get standard environment, filters and checks
33 # real QA test starts here
35 _require_scratch_nocheck
37 # Use small getdents bufsize to fit less than 10 entries
38 # stuct linux_dirent64 is 20 bytes not including d_name
41 # Create enough files to be returned in multiple gendents() calls.
42 # At least one of the files that we delete will not be listed in the
43 # first call, so we may encounter stale entries in following calls.
50 # remove all files from previous runs
53 # Create test area with a merge dir, a "former" merge dir,
54 # a pure upper dir and impure upper dir. For each case, overlayfs
55 # readdir cache is used a bit differently.
56 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
57 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
59 mkdir -p $lowerdir/merge $lowerdir/former $upperdir/pure $upperdir/impure
60 # Lower files in merge dir are listed first
61 create_files $lowerdir/merge m
62 # Files to be moved into impure upper dir
63 create_files $lowerdir o
64 # File to be copied up to make former merge dir impure
65 touch $lowerdir/former/f100
69 create_files $SCRATCH_MNT/pure p
70 create_files $SCRATCH_MNT/former f
71 # Copy up file so readdir will need to lookup its origin d_ino
72 touch $SCRATCH_MNT/merge/m100
73 # Move copied up files so readdir will need to lookup origin d_ino
74 mv $SCRATCH_MNT/o* $SCRATCH_MNT/impure/
76 # Remove the lower directory and mount overlay again to create
77 # a "former merge dir"
78 $UMOUNT_PROG $SCRATCH_MNT
79 rm -rf $lowerdir/former
82 # Check readdir cache invalidate on pure upper dir
83 echo -e "\nCreate file in pure upper dir:" >> $seqres.full
84 $here/src/t_dir_offset2 $SCRATCH_MNT/pure $bufsize "+p0" 2>&1 >> $seqres.full || \
85 echo "Missing created file in pure upper dir (see $seqres.full for details)"
86 echo -e "\nRemove file in pure upper dir:" >> $seqres.full
87 $here/src/t_dir_offset2 $SCRATCH_MNT/pure $bufsize "-p100" 2>&1 >> $seqres.full || \
88 echo "Found unlinked file in pure upper dir (see $seqres.full for details)"
90 # Check readdir cache invalidate on impure upper dir
91 echo -e "\nCreate file in impure upper dir:" >> $seqres.full
92 $here/src/t_dir_offset2 $SCRATCH_MNT/impure $bufsize "+o0" 2>&1 >> $seqres.full || \
93 echo "Missing created file in impure upper dir (see $seqres.full for details)"
94 echo -e "\nRemove file in impure upper dir:" >> $seqres.full
95 $here/src/t_dir_offset2 $SCRATCH_MNT/impure $bufsize "-o100" 2>&1 >> $seqres.full || \
96 echo "Found unlinked file in impure upper dir (see $seqres.full for details)"
98 # Check readdir cache invalidate on merge dir
99 echo -e "\nCreate file in merge dir:" >> $seqres.full
100 $here/src/t_dir_offset2 $SCRATCH_MNT/merge $bufsize "+m0" 2>&1 >> $seqres.full || \
101 echo "Missing created file in merge dir (see $seqres.full for details)"
102 echo -e "\nRemove file in merge dir:" >> $seqres.full
103 $here/src/t_dir_offset2 $SCRATCH_MNT/merge $bufsize "-m100" 2>&1 >> $seqres.full || \
104 echo "Found unlinked file in merge dir (see $seqres.full for details)"
106 # Check readdir cache invalidate on former merge dir
107 echo -e "\nCreate file in former merge dir:" >> $seqres.full
108 $here/src/t_dir_offset2 $SCRATCH_MNT/former $bufsize "+f0" 2>&1 >> $seqres.full || \
109 echo "Missing created file in former merge dir (see $seqres.full for details)"
110 echo -e "\nRemove file in former merge dir:" >> $seqres.full
111 $here/src/t_dir_offset2 $SCRATCH_MNT/former $bufsize "-f100" 2>&1 >> $seqres.full || \
112 echo "Found unlinked file in former merge dir (see $seqres.full for details)"
115 echo "Silence is golden"