xfs: fix old fuzz test invocations of xfs_repair
[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 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 rm -f $seqres.full
32
33 # real QA test starts here
34 _supported_fs overlay
35 _require_scratch_nocheck
36
37 # Use small getdents bufsize to fit less than 10 entries
38 # stuct linux_dirent64 is 20 bytes not including d_name
39 bufsize=200
40
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.
44 create_files() {
45         for n in {1..100}; do
46                 touch ${1}/${2}${n}
47         done
48 }
49
50 # remove all files from previous runs
51 _scratch_mkfs
52
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
58
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
66
67 _scratch_mount
68
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/
75
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
80 _scratch_mount
81
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)"
89
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)"
97
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)"
105
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)"
113
114 # success, all done
115 echo "Silence is golden"
116 status=0
117 exit