generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / overlay / 058
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. 058
6 #
7 # Test decoding overlay file handles with warm/cold dentry cache
8 #
9 # When opening a non-dir by file handle and the decoded inode/dentry
10 # are not in cache, the resulting dentry is "disconnected" (i.e. unknown
11 # path). This is a common case that is already covered by previous tests.
12 # This test covers the case of decoding an overlay file handle, while a
13 # disconnected dentry is still in cache.
14 #
15 # This test requires and enables overlayfs NFS export support.
16 # NFS export support depends on and requires overlayfs index feature.
17 #
18 seq=`basename $0`
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
21
22 here=`pwd`
23 tmp=/tmp/$$
24 status=1        # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
26
27 _cleanup()
28 {
29         $KILLALL_PROG -9 open_by_handle >/dev/null 2>&1
30         wait
31         cd /
32         rm -f $tmp.*
33 }
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38
39 # real QA test starts here
40
41 _supported_fs overlay
42 _require_scratch
43 _require_test_program "open_by_handle"
44 # We need to require all features together, because nfs_export cannot
45 # be enabled when index is disabled
46 _require_scratch_overlay_features index nfs_export
47 _require_command "$KILLALL_PROG" killall
48
49 # All overlay dirs are on scratch partition
50 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
51 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
52 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
53
54 # Keep this number > 1, because open_by_handle -rp does faccessat()
55 # on file file000000, which makes that dentry connected
56 NUMFILES=10
57
58 # Create test dir and empty test files
59 create_test_files()
60 {
61         local dir=$1
62         local opt=$2
63
64         mkdir -p $dir
65         $here/src/open_by_handle -cp $opt $dir $NUMFILES
66 }
67
68 # Test encode/decode file handles on overlay mount
69 test_file_handles()
70 {
71         local dir=$1
72         shift
73
74         echo test_file_handles $dir $* | _filter_scratch | \
75                                 sed -e "s,$tmp\.,,g"
76         $here/src/open_by_handle $* $dir $NUMFILES
77 }
78
79 # Create lower/upper dir and files
80 _scratch_mkfs
81 create_test_files $upper/uppertestdir -w
82 create_test_files $lower/lowertestdir -w
83 _scratch_mount -o "index=on,nfs_export=on"
84 # Encode upper file handles
85 test_file_handles $SCRATCH_MNT/uppertestdir -p -o $tmp.upper_file_handles
86 # Encode lower file handles
87 test_file_handles $SCRATCH_MNT/lowertestdir -p -o $tmp.lower_file_handles
88
89 # Check decode and read from stored file handles with warm caches -
90 # At this time, all non-dir dentries are connected, because the entries
91 # were created on lookup, before encoding the file handles.
92 test_file_handles $SCRATCH_MNT -rnp -i $tmp.upper_file_handles
93 test_file_handles $SCRATCH_MNT -rnp -i $tmp.lower_file_handles
94
95 # Check decode and read/readdir from stored file handles with cold caches -
96 # -s sleeps in the background to keep files open and keep disconnected
97 # overlay dentries in cache
98 _scratch_cycle_mount "index=on,nfs_export=on"
99 test_file_handles $SCRATCH_MNT -rnps -i $tmp.upper_file_handles &
100 # Give the above 1 second to get to sleep loop
101 sleep 1
102 test_file_handles $SCRATCH_MNT -rnps -i $tmp.lower_file_handles &
103 # Give the above 1 second to get to sleep loop
104 sleep 1
105
106 # Check decode and read/readdir from stored file handles with warm caches -
107 # At this time, all non-dir dentries are disconnected, because there was
108 # no lookup to the files since drop caches. The expection to this rule
109 # is lower and upper file000000. open_by_handle -rp above did faccessat()
110 # on file file000000, which created a connected dentry alias in addition
111 # to the disconnected dentry alias.
112 test_file_handles $SCRATCH_MNT -rnp -i $tmp.upper_file_handles
113 test_file_handles $SCRATCH_MNT -rnp -i $tmp.lower_file_handles
114
115 # SIGPIPE avoids Terminated/Killed message from bash
116 $KILLALL_PROG -q -13 open_by_handle
117 wait
118
119 status=0
120 exit