xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / overlay / 042
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test 042
6 #
7 # Test creating lower hardlinks for copied up files.
8 #
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.
13 #
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.
17 #
18 # This test verifies that behavior is sane after creating lower hardlinks
19 # for copied up files while overlayfs is offline.
20 #
21 seq=`basename $0`
22 seqres=$RESULT_DIR/$seq
23 echo "QA output created by $seq"
24
25 tmp=/tmp/$$
26 status=1        # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31         cd /
32         rm -f $tmp.*
33 }
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38
39 # remove previous $seqres.full before test
40 rm -f $seqres.full
41
42 # real QA test starts here
43 _supported_fs overlay
44 _supported_os Linux
45 _require_scratch
46 # Without overlay index feature hardlinks are broken on copy up
47 _require_scratch_feature index
48
49 # Remove all files from previous tests
50 _scratch_mkfs
51
52 # Create lower file
53 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
54 mkdir -p $lowerdir
55 touch $lowerdir/0
56
57 # Disable overlay index feature to copy up with no index
58 _scratch_mount -o index=off
59
60 # Copy up lower and create upper hardlink with no index
61 ln $SCRATCH_MNT/0 $SCRATCH_MNT/1
62
63 $UMOUNT_PROG $SCRATCH_MNT
64
65 # Add lower hardlinks while overlay is offline
66 ln $lowerdir/0 $lowerdir/2
67 ln $lowerdir/0 $lowerdir/3
68
69 # Enable overlay index feature to lookup copied up upper aliases
70 _scratch_mount -o index=on
71
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"
78
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
82 # a hardlink.
83 ln $SCRATCH_MNT/2 $SCRATCH_MNT/4
84
85 # Mount cycle to reset inode/dentry cache
86 _scratch_cycle_mount index=on
87
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"
104
105 # Mount cycle to reset inode/dentry cache
106 _scratch_cycle_mount index=on
107
108 # Unlink all hardlinks - if overlay inode nlink is 0, this will trigger
109 # WARN_ON() in drop_nlink()
110 rm $SCRATCH_MNT/0
111 rm $SCRATCH_MNT/1
112 rm $SCRATCH_MNT/2
113 rm $SCRATCH_MNT/3
114 rm $SCRATCH_MNT/4
115
116 echo "Silence is golden"
117 status=0
118 exit