2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 IBM Corporation. All Rights Reserved.
7 # Test hardlink breakage on non-samefs setup
8 # This is a variant of overlay/018 to test.
10 # This simple test demonstrates a known issue with overlayfs:
11 # - file A and B are hardlinked in lower
12 # - modify A to trigger copy up
13 # - file A is no longer a hardlink of file B
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
20 status=1 # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
28 # get standard environment, filters and checks
32 # real QA test starts here
34 # Use non-default scratch underlying overlay dirs, we need to check
35 # them explicity after test.
36 _require_scratch_nocheck
38 _require_scratch_feature index
39 _require_test_program "t_dir_type"
43 # Record inode numbers in format <ino> <nlink>
44 function record_ino_nlink()
46 ls -li $FILES | awk '{ print $1, $3, $10}' > $1
49 # Check inode numbers match recorded inode numbers
50 function check_ino_nlink()
56 record_ino_nlink $after
58 # Test constant stat(2) st_ino/st_nlink -
59 # Compare before..after - expect silence
60 # We use diff -u so out.bad will tell us which stage failed
61 diff -u $before $after
63 # Test constant readdir(3)/getdents(2) d_ino -
64 # Expect to find file by inode number
65 cat $before | while read ino nlink f; do
66 $here/src/t_dir_type $dir $ino | grep -q $(basename $f) || \
67 echo "$(basename $f) not found by ino $ino (from $before)"
71 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
75 # Create 2 hardlinked files in lower
76 echo "zero" >> $lowerdir/foo
77 ln $lowerdir/foo $lowerdir/bar
79 _scratch_mkfs >>$seqres.full 2>&1
81 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
82 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
84 # Enable overlay index feature to prevent breaking hardlinks on copy up.
85 # Enabling xino in this test requires that base filesystem inode numbers will
86 # not use bit 63 in inode number of the test files, because bit 63 is used by
87 # overlayfs to indicate the layer. Let's just assume that this is true for all
88 # tested filesystems and if we are wrong, the test may fail.
89 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o index=on,xino=on || \
90 _notrun "cannot mount overlay with xino=on option"
91 _fs_options $SCRATCH_DEV | grep -q "xino=on" || \
92 _notrun "cannot enable xino feature"
101 echo "== Before copy up =="
103 record_ino_nlink $tmp.before
105 # Modify content of one of the hardlinks
106 # Intentionally modify the last hardlink in $FILES, so after mount cycle
107 # when reading the first file in $FILES, last file won't be in inode/dcache
110 echo "== After write one =="
112 check_ino_nlink $SCRATCH_MNT $tmp.before $tmp.after_one
114 # Verify that the hardlinks survive a mount cycle
115 $UMOUNT_PROG $SCRATCH_MNT
116 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir -o index=on,xino=on
117 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o index=on,xino=on
119 echo "== After mount cycle =="
121 check_ino_nlink $SCRATCH_MNT $tmp.after_one $tmp.after_cycle
123 # Drop caches to get the copied up hardlink out of cache
124 echo 3 > /proc/sys/vm/drop_caches
126 # Modify content of the other hardlink
129 echo "== After write two =="
131 check_ino_nlink $SCRATCH_MNT $tmp.after_one $tmp.after_two
134 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir -o index=on