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
37 _require_scratch_feature index
43 # mount and check nlink after overlay offline modification
44 _scratch_mount -o index=on
47 echo "== $when offline =="
48 for f in $HARDLINKS; do
49 _ls_l $SCRATCH_MNT/$f | awk '{ print $2, $9 }' | _filter_scratch
52 $UMOUNT_PROG $SCRATCH_MNT
55 # Create lower hardlinks
60 ln $lowerdir/0 $lowerdir/1
61 ln $lowerdir/0 $lowerdir/2
64 test_hardlinks_offline()
67 report_nlink "all upper"
69 # Unlink copied up hardlink
72 report_nlink "unlink upper"
74 # Link to copied up hardlink
75 ln $upperdir/2 $upperdir/3
77 report_nlink "link upper"
79 # Rename over copied up hardlink
81 mv $upperdir/new $upperdir/1
83 report_nlink "rename over upper"
85 # Unlink new upper hardlink
88 report_nlink "unlink new upper"
90 # Unlink last upper and drop union nlink to zero
94 report_nlink "unlink last lower"
96 # Verify that orphan index is cleaned when dropping nlink to zero
97 # With nfs_export=on index will contain a whiteout index entry, so allow
98 # chardev entries in index dir.
99 find $workdir/index -mindepth 1 -type c -o -print
102 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
103 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
104 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
106 # Remove all files from previous tests
109 # Create lower hardlinks
112 # Enable overlay index feature to prevent breaking hardlinks on copy up
113 _scratch_mount -o index=on
115 # Copy up and index hardlinks
120 # Perform the rest of the changes offline
121 $UMOUNT_PROG $SCRATCH_MNT
123 test_hardlinks_offline