2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
7 # Test nlink accounting of overlay hardlinks.
9 # nlink of overlay inode should account for the union of lower and upper
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
26 # get standard environment, filters and checks
30 # remove previous $seqres.full before test
33 # real QA test starts here
36 _require_scratch_feature index
42 [ $DCACHETEMP != cold ] || echo 2 > /proc/sys/vm/drop_caches
44 # check nlink with warm dcache after overlay modification
46 echo "== $when - $DCACHETEMP dcache =="
47 for f in $HARDLINKS; do
48 _ls_l $SCRATCH_MNT/$f | awk '{ print $2, $9 }' | _filter_scratch
52 # Create lower hardlinks
57 ln $lowerdir/0 $lowerdir/1
58 ln $lowerdir/0 $lowerdir/2
59 ln $lowerdir/0 $lowerdir/3
65 report_nlink "all lower"
67 # Unlink lower hardlink
70 report_nlink "unlink lower"
72 # Link to lower hardlink
73 ln $SCRATCH_MNT/3 $SCRATCH_MNT/4
75 report_nlink "link lower"
77 # Link to upper hardlink
78 ln $SCRATCH_MNT/4 $SCRATCH_MNT/5
80 report_nlink "link upper"
82 # Rename over lower hardlink
83 touch $SCRATCH_MNT/new
84 mv $SCRATCH_MNT/new $SCRATCH_MNT/1
86 report_nlink "cover lower"
88 # Unlink upper hardlink
91 report_nlink "unlink upper"
93 # Rename over upper hardlink
94 touch $SCRATCH_MNT/new
95 mv $SCRATCH_MNT/new $SCRATCH_MNT/4
97 report_nlink "cover upper"
99 # Unlink last upper (union still has one lower)
102 report_nlink "unlink last upper"
104 # Unlink last lower and drop union nlink to zero (and hopefully not below)
107 # Verify that orphan index is cleaned when dropping nlink to zero
108 # With nfs_export=on index will contain a whiteout index entry, so allow
109 # chardev entries in index dir.
110 find $workdir/index -mindepth 1 -type c -o -print
113 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
114 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
116 # Remove all files from previous tests
119 # Create lower hardlinks
122 # Enable overlay index feature to prevent breaking hardlinks on copy up
123 _scratch_mount -o index=on
124 # Test hardlinks with warm dcache
128 # Reset to lower hardlinks
132 _scratch_mount -o index=on
134 # Test hardlinks with cold dcache