2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Chengguang Xu <cgxu519@mykernel.net>.
8 # Test whiteout inode sharing functionality.
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.
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.
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
24 status=1 # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # get standard environment, filters and checks
37 # remove previous $seqres.full before test
40 # real QA test starts here
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
47 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
48 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
49 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
51 # Make some testing files in lowerdir.
53 # $1: Testing file number
57 for name in `seq ${1}`; do
58 touch $lowerdir/${name} &>/dev/null
62 # Delete all copied-up files in upperdir.
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.
69 rmdir $SCRATCH_MNT/dir &>/dev/null || \
70 _notrun "overlay does not support whiteout inode sharing"
71 rm $SCRATCH_MNT/* &>/dev/null
74 # Check link count of whiteout files.
76 # $1: Testing file number
77 # $2: Expected link count
78 check_whiteout_files()
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}"
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
93 # Run test case with specific arguments.
95 # $1: Testing file number
96 # $2: Expected link count
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"
105 check_whiteout_files ${1} ${2}
111 # +1 for dir +1 for temp whiteout
113 run_test_case $file_count $link_count
116 echo "Silence is golden"