4 # Test hardlink breakage
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
11 #-----------------------------------------------------------------------
13 # Copyright (C) 2016 CTERA Networks. All Rights Reserved.
14 # Author: Amir Goldstein <amir73il@gmail.com>
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.
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.
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 #-----------------------------------------------------------------------
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
36 status=1 # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
44 # get standard environment, filters and checks
48 # real QA test starts here
55 _scratch_mkfs >>$seqres.full 2>&1
57 # Create 2 hardlinked files in lower
58 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
60 echo "zero" >> $lowerdir/foo
61 ln $lowerdir/foo $lowerdir/bar
64 # Record inode numbers in format <ino> <nlink>
65 function record_ino_nlink()
67 ls -li $FILES | awk '{ print $1, $3 }' > $1
70 # Check inode numbers match recorded inode numbers
71 function check_ino_nlink()
76 record_ino_nlink $after
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
94 echo "== Before copy up =="
96 record_ino_nlink $tmp.before
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
103 echo "== After write one =="
105 check_ino_nlink $tmp.before $tmp.after_one
107 # Verify that the hardlinks survive a mount cycle
110 echo "== After mount cycle =="
112 check_ino_nlink $tmp.after_one $tmp.after_cycle