xfs/{263,106}: erase max warnings printout
[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 _supported_os Linux
43 _require_scratch
44 # Require index dir to test if workdir/work is not in use
45 # which implies that whiteout sharing is supported
46 _require_scratch_overlay_features index
47
48 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
49 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
50 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
51
52 # Make some testing files in lowerdir.
53 # Argument:
54 # $1: Testing file number
55 make_lower_files()
56 {
57         mkdir $lowerdir/dir
58         for name in `seq ${1}`; do
59                 touch $lowerdir/${name} &>/dev/null
60         done
61 }
62
63 # Delete all copied-up files in upperdir.
64 make_whiteout_files()
65 {
66         # whiteout inode sharing implies that workdir/work is not in use
67         # If workdir/work is in use, delete of lower dir will fail and
68         # we won't run the test.
69         rmdir $workdir/work
70         rmdir $SCRATCH_MNT/dir &>/dev/null || \
71                 _notrun "overlay does not support whiteout inode sharing"
72         rm $SCRATCH_MNT/* &>/dev/null
73 }
74
75 # Check link count of whiteout files.
76 # Arguments:
77 # $1: Testing file number
78 # $2: Expected link count
79 check_whiteout_files()
80 {
81         for name in dir `seq ${1}`; do
82                 local real_count=`stat -c %h $upperdir/${name} 2>/dev/null`
83                 if [[ ${2} != $real_count ]]; then
84                         echo "Expected link count is ${2} but real count is $real_count, file name is ${name}"
85                 fi
86         done
87         local tmpfile_count=`ls $workdir/index/\#* 2>/dev/null |wc -l 2>/dev/null`
88         if [[ -n "$tmpfile_count" && $tmpfile_count > 1 ]]; then
89                 echo "There are more than one whiteout tmpfile in index dir!"
90                 ls -l $workdir/index/\#* 2>/dev/null
91         fi
92 }
93
94 # Run test case with specific arguments.
95 # Arguments:
96 # $1: Testing file number
97 # $2: Expected link count
98 run_test_case()
99 {
100         _scratch_mkfs
101         make_lower_files ${1}
102         _scratch_mount -o "index=on"
103         make_whiteout_files
104         check_whiteout_files ${1} ${2}
105         _scratch_unmount
106 }
107
108 # Test case
109 file_count=10
110 # +1 for dir +1 for temp whiteout
111 link_count=12
112 run_test_case $file_count $link_count
113
114 # success, all done
115 echo "Silence is golden"
116 status=0
117 exit