tests: remove udf/101
[xfstests-dev.git] / tests / overlay / 033
1 #! /bin/bash
2 # FS QA Test 033
3 #
4 # Test nlink accounting of overlay hardlinks.
5 #
6 # nlink of overlay inode should account for the union of lower and upper
7 # hardlinks.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
11 # Author: Amir Goldstein <amir73il@gmail.com>
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         cd /
39         rm -f $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45
46 # remove previous $seqres.full before test
47 rm -f $seqres.full
48
49 # real QA test starts here
50 _supported_fs overlay
51 _supported_os Linux
52 _require_scratch
53 _require_scratch_feature index
54
55 report_nlink()
56 {
57         when=$1
58
59         [ $DCACHETEMP != cold ] || echo 2 > /proc/sys/vm/drop_caches
60
61         # check nlink with warm dcache after overlay modification
62         # List <nlink> <name>
63         echo "== $when - $DCACHETEMP dcache =="
64         for f in $HARDLINKS; do
65                 _ls_l $SCRATCH_MNT/$f | awk '{ print $2, $9 }' | _filter_scratch
66         done
67 }
68
69 # Create lower hardlinks
70 create_hardlinks()
71 {
72         lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
73         mkdir -p $lowerdir
74         touch $lowerdir/0
75         ln $lowerdir/0 $lowerdir/1
76         ln $lowerdir/0 $lowerdir/2
77         ln $lowerdir/0 $lowerdir/3
78 }
79
80 test_hardlinks()
81 {
82         HARDLINKS=`seq 0 3`
83         report_nlink "all lower"
84
85         # Unlink lower hardlink
86         rm $SCRATCH_MNT/0
87         HARDLINKS=`seq 1 3`
88         report_nlink "unlink lower"
89
90         # Link to lower hardlink
91         ln $SCRATCH_MNT/3 $SCRATCH_MNT/4
92         HARDLINKS=`seq 1 4`
93         report_nlink "link lower"
94
95         # Link to upper hardlink
96         ln $SCRATCH_MNT/4 $SCRATCH_MNT/5
97         HARDLINKS=`seq 1 5`
98         report_nlink "link upper"
99
100         # Rename over lower hardlink
101         touch $SCRATCH_MNT/new
102         mv $SCRATCH_MNT/new $SCRATCH_MNT/1
103         HARDLINKS=`seq 2 5`
104         report_nlink "cover lower"
105
106         # Unlink upper hardlink
107         rm $SCRATCH_MNT/5
108         HARDLINKS=`seq 2 4`
109         report_nlink "unlink upper"
110
111         # Rename over upper hardlink
112         touch $SCRATCH_MNT/new
113         mv $SCRATCH_MNT/new $SCRATCH_MNT/4
114         HARDLINKS=`seq 2 3`
115         report_nlink "cover upper"
116
117         # Unlink last upper (union still has one lower)
118         rm $SCRATCH_MNT/3
119         HARDLINKS=2
120         report_nlink "unlink last upper"
121
122         # Unlink last lower and drop union nlink to zero (and hopefully not below)
123         rm $SCRATCH_MNT/2
124
125         # Verify that orphan index is cleaned when dropping nlink to zero
126         ls $OVL_BASE_SCRATCH_MNT/$OVL_WORK/index
127 }
128
129 # Remove all files from previous tests
130 _scratch_mkfs
131
132 # Create lower hardlinks
133 create_hardlinks
134
135 # Enable overlay index feature to prevent breaking hardlinks on copy up
136 _scratch_mount -o index=on
137 # Test hardlinks with warm dcache
138 DCACHETEMP=warm
139 test_hardlinks
140
141 # Reset to lower hardlinks
142 _scratch_unmount
143 _scratch_mkfs
144 create_hardlinks
145 _scratch_mount -o index=on
146
147 # Test hardlinks with cold dcache
148 DCACHETEMP=cold
149 test_hardlinks
150
151 status=0
152 exit