2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
7 # Test nlink accounting of overlay hardlinks with offline modifications.
9 # nlink of overlay inode should account for the union of lower and upper
10 # hardlinks. Orphan index inodes with union nlink 0 should be cleaned on
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
27 # get standard environment, filters and checks
31 # remove previous $seqres.full before test
34 # real QA test starts here
38 _require_scratch_feature index
44 # mount and check nlink after overlay offline modification
45 _scratch_mount -o index=on
48 echo "== $when offline =="
49 for f in $HARDLINKS; do
50 _ls_l $SCRATCH_MNT/$f | awk '{ print $2, $9 }' | _filter_scratch
53 $UMOUNT_PROG $SCRATCH_MNT
56 # Create lower hardlinks
61 ln $lowerdir/0 $lowerdir/1
62 ln $lowerdir/0 $lowerdir/2
65 test_hardlinks_offline()
68 report_nlink "all upper"
70 # Unlink copied up hardlink
73 report_nlink "unlink upper"
75 # Link to copied up hardlink
76 ln $upperdir/2 $upperdir/3
78 report_nlink "link upper"
80 # Rename over copied up hardlink
82 mv $upperdir/new $upperdir/1
84 report_nlink "rename over upper"
86 # Unlink new upper hardlink
89 report_nlink "unlink new upper"
91 # Unlink last upper and drop union nlink to zero
95 report_nlink "unlink last lower"
97 # Verify that orphan index is cleaned when dropping nlink to zero
98 # With nfs_export=on index will contain a whiteout index entry, so allow
99 # chardev entries in index dir.
100 find $workdir/index -mindepth 1 -type c -o -print
103 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
104 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
105 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
107 # Remove all files from previous tests
110 # Create lower hardlinks
113 # Enable overlay index feature to prevent breaking hardlinks on copy up
114 _scratch_mount -o index=on
116 # Copy up and index hardlinks
121 # Perform the rest of the changes offline
122 $UMOUNT_PROG $SCRATCH_MNT
124 test_hardlinks_offline