common: kill _supported_os
[xfstests-dev.git] / tests / overlay / 044
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 IBM Corporation. All Rights Reserved.
4 #
5 # FSQA Test No. 044
6 #
7 # Test hardlink breakage on non-samefs setup
8 # This is a variant of overlay/018 to test.
9 #
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
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # real QA test starts here
33 _supported_fs overlay
34 # Use non-default scratch underlying overlay dirs, we need to check
35 # them explicity after test.
36 _require_scratch_nocheck
37 _require_test
38 _require_scratch_feature index
39 _require_test_program "t_dir_type"
40
41 rm -f $seqres.full
42
43 # Record inode numbers in format <ino> <nlink>
44 function record_ino_nlink()
45 {
46         ls -li $FILES | awk '{ print $1, $3, $10}' > $1
47 }
48
49 # Check inode numbers match recorded inode numbers
50 function check_ino_nlink()
51 {
52         dir=$1
53         before=$2
54         after=$3
55
56         record_ino_nlink $after
57
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
62
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)"
68         done
69 }
70
71 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
72 rm -rf $lowerdir
73 mkdir $lowerdir
74
75 # Create 2 hardlinked files in lower
76 echo "zero" >> $lowerdir/foo
77 ln $lowerdir/foo $lowerdir/bar
78
79 _scratch_mkfs >>$seqres.full 2>&1
80
81 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
82 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
83
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"
93
94 rm -f $tmp.*
95
96 foo=$SCRATCH_MNT/foo
97 bar=$SCRATCH_MNT/bar
98
99 FILES="$foo $bar"
100
101 echo "== Before copy up =="
102 cat $FILES
103 record_ino_nlink $tmp.before
104
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
108 echo "one" >> $bar
109
110 echo "== After write one =="
111 cat $FILES
112 check_ino_nlink $SCRATCH_MNT $tmp.before $tmp.after_one
113
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
118
119 echo "== After mount cycle =="
120 cat $FILES
121 check_ino_nlink $SCRATCH_MNT $tmp.after_one $tmp.after_cycle
122
123 # Drop caches to get the copied up hardlink out of cache
124 echo 3 > /proc/sys/vm/drop_caches
125
126 # Modify content of the other hardlink
127 echo "two" >> $foo
128
129 echo "== After write two =="
130 cat $FILES
131 check_ino_nlink $SCRATCH_MNT $tmp.after_one $tmp.after_two
132
133 # check overlayfs
134 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir -o index=on
135
136 status=0
137 exit