2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
7 # Test creating lower hardlinks for copied up files.
9 # kernel v4.13 introduced the index=on feature for not breaking hardlinks
10 # on copy-up. With the index feature enabled a regression was introduced -
11 # lower files that are hardlined while overlay is offline can result in
12 # lookup error after overlay in mounted.
14 # The regression was fixed by upstream commit
15 # 6eaf011144af ovl: fix EIO from lookup of non-indexed upper
16 # that was merged to v4.14-rc7.
18 # This test verifies that behavior is sane after creating lower hardlinks
19 # for copied up files while overlayfs is offline.
22 seqres=$RESULT_DIR/$seq
23 echo "QA output created by $seq"
26 status=1 # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
39 # remove previous $seqres.full before test
42 # real QA test starts here
46 # Without overlay index feature hardlinks are broken on copy up
47 _require_scratch_feature index
49 # Remove all files from previous tests
53 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
57 # Disable overlay index feature to copy up with no index
58 _scratch_mount -o index=off
60 # Copy up lower and create upper hardlink with no index
61 ln $SCRATCH_MNT/0 $SCRATCH_MNT/1
63 $UMOUNT_PROG $SCRATCH_MNT
65 # Add lower hardlinks while overlay is offline
66 ln $lowerdir/0 $lowerdir/2
67 ln $lowerdir/0 $lowerdir/3
69 # Enable overlay index feature to lookup copied up upper aliases
70 _scratch_mount -o index=on
72 # Stat upper hardlink that were created with no index and whose copy up
73 # origin is now an hardlink - expect same st_ino
74 ino0=$(stat -c '%i' $SCRATCH_MNT/0)
75 ino1=$(stat -c '%i' $SCRATCH_MNT/1)
76 [[ $ino0 == $ino1 ]] || \
77 echo "Mismatch inode number for non-indexed upper hardlinks"
79 # Copy up lower and create new upper hardlink with index, because
80 # lower is a hardlink and index is enabled. The new hardlinks are not
81 # associated with the hardlinks that were created when lower was not
83 ln $SCRATCH_MNT/2 $SCRATCH_MNT/4
85 # Mount cycle to reset inode/dentry cache
86 _scratch_cycle_mount index=on
88 # Stat files that were copied up with index and whose copy up origin
89 # is now an hardlink - expect same st_ino as lower aliases and different
90 # st_ino from non-indexed upper aliases.
91 ino0=$(stat -c '%i' $SCRATCH_MNT/0)
92 ino1=$(stat -c '%i' $SCRATCH_MNT/1)
93 ino2=$(stat -c '%i' $SCRATCH_MNT/2)
94 ino3=$(stat -c '%i' $SCRATCH_MNT/3)
95 ino4=$(stat -c '%i' $SCRATCH_MNT/4)
96 [[ $ino0 == $ino1 ]] || \
97 echo "Mismatch inode number for non-indexed upper hardlinks"
98 [[ $ino2 == $ino4 ]] || \
99 echo "Mismatch inode number for indexed upper hardlinks"
100 [[ $ino2 == $ino3 ]] || \
101 echo "Mismatch inode number for indexed upper and lower hardlinks"
102 [[ $ino2 != $ino0 ]] || \
103 echo "Unexpected matching inode number for indexed and non-indexed upper hardlinks"
105 # Mount cycle to reset inode/dentry cache
106 _scratch_cycle_mount index=on
108 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
109 # WARN_ON() in drop_nlink()
116 echo "Silence is golden"