overlay/029: fix test failure with nfs_export feature enabled
[xfstests-dev.git] / tests / overlay / 062
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test No. 062
6 #
7 # Test file handle decode with multi lower layers on same fs
8 #
9 # This test is for a regression that was introduced in kernel v4.17 by
10 # commit 8b58924ad55c ("ovl: lookup in inode cache first when decoding
11 # lower file handle").
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26         $UMOUNT_PROG $lowertestdir
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32
33 # real QA test starts here
34
35 _supported_fs overlay
36 _supported_os Linux
37 _require_scratch
38 _require_test_program "open_by_handle"
39 # We need to require all features together, because nfs_export cannot
40 # be enabled when index is disabled
41 _require_scratch_overlay_features index nfs_export
42
43 NUMFILES=1
44
45 # Create test dir and empty test files
46 create_test_files()
47 {
48         local dir=$1
49
50         mkdir -p $dir
51         $here/src/open_by_handle -cwp $dir $NUMFILES
52 }
53
54 # Test encode/decode file handles on overlay mount
55 test_file_handles()
56 {
57         local dir=$1
58
59         $here/src/open_by_handle -rp $dir $NUMFILES
60 }
61
62 _scratch_mkfs
63
64 # All lower layers are on scratch partition
65 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
66 lower2=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER.2
67 lowertestdir=$lower2/testdir
68
69 create_test_files $lowertestdir
70
71 # bind mount to pin lower test dir dentry to dcache
72 $MOUNT_PROG --bind $lowertestdir $lowertestdir
73
74 # For non-upper overlay mount, nfs_export requires disabling redirect_dir.
75 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
76         -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$lower:$lower2
77
78 # Decode an overlay directory file handle, whose underlying lower dir dentry
79 # is in dcache and connected and does not belong to the upper most lower layer.
80 # The test program drops caches, but $lowertestdir dcache in pinned, so only
81 # the overlay dentry is dropped.
82 test_file_handles $SCRATCH_MNT/testdir -rp
83
84 echo "Silence is golden"
85 status=0
86 exit