overlay/075: fix wrong invocation of t_immutable
[xfstests-dev.git] / tests / overlay / 034
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test 034
6 #
7 # Test overlay nlink when adding lower hardlinks.
8 #
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.
12 #
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.
18 #
19 # Commit 5f8415d6b87e ("ovl: persistent overlay inode nlink for indexed
20 # inodes") fixes this issue, although the issue was never exposed in any
21 # released kernel.
22 #
23 # With overlayfs indexed copy up and without the fix, the test triggers
24 # WARN_ON(inode->i_nlink == 0) in drop_link().
25 #
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # remove previous $seqres.full before test
45 rm -f $seqres.full
46
47 # real QA test starts here
48 _supported_fs overlay
49 _require_scratch
50 # Without overlay index feature hardlinks are broken on copy up
51 _require_scratch_feature index
52
53 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
54 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
55
56 # Remove all files from previous tests
57 _scratch_mkfs
58
59 # Create lower hardlink
60 mkdir -p $lowerdir
61 touch $lowerdir/0
62 ln $lowerdir/0 $lowerdir/1
63
64 # Enable overlay index feature to prevent breaking hardlinks on copy up
65 _scratch_mount -o index=on
66
67 # Copy up lower hardlink - overlay inode nlink 2 is copied from lower
68 touch $SCRATCH_MNT/0
69
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
74
75 # Unlink the 2 un-accounted lower hardlinks - overlay inode nlinks
76 # drops 2 and may reach 0 if the situation is not detected
77 rm $SCRATCH_MNT/2
78 rm $SCRATCH_MNT/3
79
80 # Check if getting ENOENT when trying to link !I_LINKABLE with nlink 0
81 ln $SCRATCH_MNT/0 $SCRATCH_MNT/4
82
83 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
84 # WARN_ON() in drop_nlink()
85 rm $SCRATCH_MNT/0
86 rm $SCRATCH_MNT/1
87 rm $SCRATCH_MNT/4
88
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
94
95 echo "Silence is golden"
96 status=0
97 exit