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
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
48 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
49 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
50 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
52 # Make some testing files in lowerdir.
54 # $1: Testing file number
58 for name in `seq ${1}`; do
59 touch $lowerdir/${name} &>/dev/null
63 # Delete all copied-up files in upperdir.
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.
70 rmdir $SCRATCH_MNT/dir &>/dev/null || \
71 _notrun "overlay does not support whiteout inode sharing"
72 rm $SCRATCH_MNT/* &>/dev/null
75 # Check link count of whiteout files.
77 # $1: Testing file number
78 # $2: Expected link count
79 check_whiteout_files()
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}"
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
94 # Run test case with specific arguments.
96 # $1: Testing file number
97 # $2: Expected link count
101 make_lower_files ${1}
102 _scratch_mount -o "index=on"
104 check_whiteout_files ${1} ${2}
110 # +1 for dir +1 for temp whiteout
112 run_test_case $file_count $link_count
115 echo "Silence is golden"