xfs/144: Use _qsetup instead of qsetup
[xfstests-dev.git] / tests / overlay / 073
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Chengguang Xu <cgxu519@mykernel.net>.
4 # All Rights Reserved.
5 #
6 # FS QA Test 073
7 #
8 # Test whiteout inode sharing functionality.
9 #
10 # A "whiteout" is an object that has special meaning in overlayfs.
11 # A whiteout on an upper layer will effectively hide a matching file
12 # in the lower layer, making it appear as if the file didn't exist.
13 #
14 # Whiteout inode sharing means multiple whiteout objects will share
15 # one inode in upper layer, without this feature every whiteout object
16 # will consume one inode in upper layer.
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         cd /
30         rm -f $tmp.*
31 }
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36
37 # remove previous $seqres.full before test
38 rm -f $seqres.full
39
40 # real QA test starts here
41 _supported_fs overlay
42 _require_scratch
43 # Require index dir to test if workdir/work is not in use
44 # which implies that whiteout sharing is supported
45 _require_scratch_overlay_features index
46
47 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
48 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
49 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
50
51 # Make some testing files in lowerdir.
52 # Argument:
53 # $1: Testing file number
54 make_lower_files()
55 {
56         mkdir $lowerdir/dir
57         for name in `seq ${1}`; do
58                 touch $lowerdir/${name} &>/dev/null
59         done
60 }
61
62 # Delete all copied-up files in upperdir.
63 make_whiteout_files()
64 {
65         # whiteout inode sharing implies that workdir/work is not in use
66         # If workdir/work is in use, delete of lower dir will fail and
67         # we won't run the test.
68         rmdir $workdir/work
69         rmdir $SCRATCH_MNT/dir &>/dev/null || \
70                 _notrun "overlay does not support whiteout inode sharing"
71         rm $SCRATCH_MNT/* &>/dev/null
72 }
73
74 # Check link count of whiteout files.
75 # Arguments:
76 # $1: Testing file number
77 # $2: Expected link count
78 check_whiteout_files()
79 {
80         for name in dir `seq ${1}`; do
81                 local real_count=`stat -c %h $upperdir/${name} 2>/dev/null`
82                 if [[ ${2} != $real_count ]]; then
83                         echo "Expected link count is ${2} but real count is $real_count, file name is ${name}"
84                 fi
85         done
86         local tmpfile_count=`ls $workdir/index/\#* 2>/dev/null |wc -l 2>/dev/null`
87         if [[ -n "$tmpfile_count" && $tmpfile_count > 1 ]]; then
88                 echo "There are more than one whiteout tmpfile in index dir!"
89                 ls -l $workdir/index/\#* 2>/dev/null
90         fi
91 }
92
93 # Run test case with specific arguments.
94 # Arguments:
95 # $1: Testing file number
96 # $2: Expected link count
97 run_test_case()
98 {
99         _scratch_mkfs
100         make_lower_files ${1}
101         # There will be extra hard links with nfs_export enabled which
102         # is expected. Turn it off explicitly to avoid the false alarm.
103         _scratch_mount -o "index=on,nfs_export=off"
104         make_whiteout_files
105         check_whiteout_files ${1} ${2}
106         _scratch_unmount
107 }
108
109 # Test case
110 file_count=10
111 # +1 for dir +1 for temp whiteout
112 link_count=12
113 run_test_case $file_count $link_count
114
115 # success, all done
116 echo "Silence is golden"
117 status=0
118 exit