2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
7 # Test overlay nlink when adding lower hardlinks.
9 # nlink of overlay inode could be dropped indefinitely by adding
10 # unaccounted lower hardlinks underneath a mounted overlay and
11 # trying to remove them.
13 # The simplest way to understand this test is this:
14 # Imagine that you have a tool (e.g. xfs_db) with which you can add
15 # hardlinks, without changing the value of nlink stored on-disk for the
16 # inode. This is exactly what this test does when it adds lower hardlinks
17 # underneath a mounted overlay.
19 # Commit 5f8415d6b87e ("ovl: persistent overlay inode nlink for indexed
20 # inodes") fixes this issue, although the issue was never exposed in any
23 # With overlayfs indexed copy up and without the fix, the test triggers
24 # WARN_ON(inode->i_nlink == 0) in drop_link().
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
44 # remove previous $seqres.full before test
47 # real QA test starts here
50 # Without overlay index feature hardlinks are broken on copy up
51 _require_scratch_feature index
53 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
54 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
56 # Remove all files from previous tests
59 # Create lower hardlink
62 ln $lowerdir/0 $lowerdir/1
64 # Enable overlay index feature to prevent breaking hardlinks on copy up
65 _scratch_mount -o index=on
67 # Copy up lower hardlink - overlay inode nlink 2 is copied from lower
70 # Add lower hardlinks while overlay is mounted - overlay inode nlink
71 # is not being updated
72 ln $lowerdir/0 $lowerdir/2
73 ln $lowerdir/0 $lowerdir/3
75 # Unlink the 2 un-accounted lower hardlinks - overlay inode nlinks
76 # drops 2 and may reach 0 if the situation is not detected
80 # Check if getting ENOENT when trying to link !I_LINKABLE with nlink 0
81 ln $SCRATCH_MNT/0 $SCRATCH_MNT/4
83 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
84 # WARN_ON() in drop_nlink()
89 # Verify that orphan index is cleaned on mount
90 _scratch_cycle_mount index=on
91 # With nfs_export=on index will contain a whiteout index entry, so allow
92 # chardev entries in index dir.
93 find $workdir/index -mindepth 1 -type c -o -print
95 echo "Silence is golden"