46097a9342ffc625811c21cf28ec9da308f32b0f
[xfstests-dev.git] / tests / overlay / 018
1 #! /bin/bash
2 # FSQA Test No. 018
3 #
4 # Test hardlink breakage
5 #
6 # This simple test demonstrates a known issue with overlayfs:
7 # - file A and B are hardlinked in lower
8 # - modify A to trigger copy up
9 # - file A is no longer a hardlink of file B
10 #
11 #-----------------------------------------------------------------------
12 #
13 # Copyright (C) 2016 CTERA Networks. All Rights Reserved.
14 # Author: Amir Goldstein <amir73il@gmail.com>
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 # real QA test starts here
49 _supported_fs overlay
50 _supported_os Linux
51 _require_scratch
52
53 rm -f $seqres.full
54
55 _scratch_mkfs >>$seqres.full 2>&1
56
57 # Create 2 hardlinked files in lower
58 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
59 mkdir -p $lowerdir
60 echo "zero" >> $lowerdir/foo
61 ln $lowerdir/foo $lowerdir/bar
62
63
64 # Record inode numbers in format <ino> <nlink>
65 function record_ino_nlink()
66 {
67         ls -li $FILES | awk '{ print $1, $3 }' > $1
68 }
69
70 # Check inode numbers match recorded inode numbers
71 function check_ino_nlink()
72 {
73         before=$1
74         after=$2
75
76         record_ino_nlink $after
77
78         # Test constant stat(2) st_ino/st_nlink -
79         #   Compare before..after - expect silence
80         # We use diff -u so out.bad will tell us which stage failed
81         diff -u $before $after
82 }
83
84 _scratch_mount
85
86
87 rm -f $tmp.*
88
89 foo=$SCRATCH_MNT/foo
90 bar=$SCRATCH_MNT/bar
91
92 FILES="$foo $bar"
93
94 echo "== Before copy up =="
95 cat $FILES
96 record_ino_nlink $tmp.before
97
98 # Modify content of one of the hardlinks
99 # Intentionally modify the last hardlink in $FILES, so after mount cycle
100 # when reading the first file in $FILES, last file won't be in inode/dcache
101 echo "one" >> $bar
102
103 echo "== After write one =="
104 cat $FILES
105 check_ino_nlink $tmp.before $tmp.after_one
106
107 # Verify that the hardlinks survive a mount cycle
108 _scratch_cycle_mount
109
110 echo "== After mount cycle =="
111 cat $FILES
112 check_ino_nlink $tmp.after_one $tmp.after_cycle
113
114 status=0
115 exit