4 # Test creating lower hardlinks for copied up files.
6 # kernel v4.13 introduced the index=on feature for not breaking hardlinks
7 # on copy-up. With the index feature enabled a regression was introduced -
8 # lower files that are hardlined while overlay is offline can result in
9 # lookup error after overlay in mounted.
11 # The regression was fixed by upstream commit
12 # 6eaf011144af ovl: fix EIO from lookup of non-indexed upper
13 # that was merged to v4.14-rc7.
15 # This test verifies that behavior is sane after creating lower hardlinks
16 # for copied up files while overlayfs is offline.
18 #-----------------------------------------------------------------------
19 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
20 # Author: Amir Goldstein <amir73il@gmail.com>
22 # This program is free software; you can redistribute it and/or
23 # modify it under the terms of the GNU General Public License as
24 # published by the Free Software Foundation.
26 # This program is distributed in the hope that it would be useful,
27 # but WITHOUT ANY WARRANTY; without even the implied warranty of
28 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 # GNU General Public License for more details.
31 # You should have received a copy of the GNU General Public License
32 # along with this program; if not, write the Free Software Foundation,
33 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #-----------------------------------------------------------------------
38 seqres=$RESULT_DIR/$seq
39 echo "QA output created by $seq"
42 status=1 # failure is the default!
43 trap "_cleanup; exit \$status" 0 1 2 3 15
51 # get standard environment, filters and checks
55 # remove previous $seqres.full before test
58 # real QA test starts here
62 # Without overlay index feature hardlinks are broken on copy up
63 _require_scratch_feature index
65 # Remove all files from previous tests
69 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
73 # Disable overlay index feature to copy up with no index
74 _scratch_mount -o index=off
76 # Copy up lower and create upper hardlink with no index
77 ln $SCRATCH_MNT/0 $SCRATCH_MNT/1
79 $UMOUNT_PROG $SCRATCH_MNT
81 # Add lower hardlinks while overlay is offline
82 ln $lowerdir/0 $lowerdir/2
83 ln $lowerdir/0 $lowerdir/3
85 # Enable overlay index feature to lookup copied up upper aliases
86 _scratch_mount -o index=on
88 # Stat upper hardlink that were created with no index and whose copy up
89 # origin is now an hardlink - expect same st_ino
90 ino0=$(stat -c '%i' $SCRATCH_MNT/0)
91 ino1=$(stat -c '%i' $SCRATCH_MNT/1)
92 [[ $ino0 == $ino1 ]] || \
93 echo "Mismatch inode number for non-indexed upper hardlinks"
95 # Copy up lower and create new upper hardlink with index, because
96 # lower is a hardlink and index is enabled. The new hardlinks are not
97 # associated with the hardlinks that were created when lower was not
99 ln $SCRATCH_MNT/2 $SCRATCH_MNT/4
101 # Mount cycle to reset inode/dentry cache
102 _scratch_cycle_mount index=on
104 # Stat files that were copied up with index and whose copy up origin
105 # is now an hardlink - expect same st_ino as lower aliases and different
106 # st_ino from non-indexed upper aliases.
107 ino0=$(stat -c '%i' $SCRATCH_MNT/0)
108 ino1=$(stat -c '%i' $SCRATCH_MNT/1)
109 ino2=$(stat -c '%i' $SCRATCH_MNT/2)
110 ino3=$(stat -c '%i' $SCRATCH_MNT/3)
111 ino4=$(stat -c '%i' $SCRATCH_MNT/4)
112 [[ $ino0 == $ino1 ]] || \
113 echo "Mismatch inode number for non-indexed upper hardlinks"
114 [[ $ino2 == $ino4 ]] || \
115 echo "Mismatch inode number for indexed upper hardlinks"
116 [[ $ino2 == $ino3 ]] || \
117 echo "Mismatch inode number for indexed upper and lower hardlinks"
118 [[ $ino2 != $ino0 ]] || \
119 echo "Unexpected matching inode number for indexed and non-indexed upper hardlinks"
121 # Mount cycle to reset inode/dentry cache
122 _scratch_cycle_mount index=on
124 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
125 # WARN_ON() in drop_nlink()
132 echo "Silence is golden"