xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / overlay / 048
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test 048
6 #
7 # Test nlink accounting of overlay hardlinks with offline modifications.
8 #
9 # nlink of overlay inode should account for the union of lower and upper
10 # hardlinks. Orphan index inodes with union nlink 0 should be cleaned on
11 # mount.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35 _supported_fs overlay
36 _supported_os Linux
37 _require_scratch
38 _require_scratch_feature index
39
40 report_nlink()
41 {
42         when=$1
43
44         # mount and check nlink after overlay offline modification
45         _scratch_mount -o index=on
46
47         # List <nlink> <name>
48         echo "== $when offline =="
49         for f in $HARDLINKS; do
50                 _ls_l $SCRATCH_MNT/$f | awk '{ print $2, $9 }' | _filter_scratch
51         done
52
53         $UMOUNT_PROG $SCRATCH_MNT
54 }
55
56 # Create lower hardlinks
57 create_hardlinks()
58 {
59         mkdir -p $lowerdir
60         touch $lowerdir/0
61         ln $lowerdir/0 $lowerdir/1
62         ln $lowerdir/0 $lowerdir/2
63 }
64
65 test_hardlinks_offline()
66 {
67         HARDLINKS=`seq 0 2`
68         report_nlink "all upper"
69
70         # Unlink copied up hardlink
71         rm $upperdir/0
72         HARDLINKS=`seq 1 2`
73         report_nlink "unlink upper"
74
75         # Link to copied up hardlink
76         ln $upperdir/2 $upperdir/3
77         HARDLINKS=`seq 1 3`
78         report_nlink "link upper"
79
80         # Rename over copied up hardlink
81         touch $upperdir/new
82         mv $upperdir/new $upperdir/1
83         HARDLINKS=`seq 2 3`
84         report_nlink "rename over upper"
85
86         # Unlink new upper hardlink
87         rm $upperdir/3
88         HARDLINKS=2
89         report_nlink "unlink new upper"
90
91         # Unlink last upper and drop union nlink to zero
92         rm $upperdir/2
93
94         HARDLINKS=
95         report_nlink "unlink last lower"
96
97         # Verify that orphan index is cleaned when dropping nlink to zero
98         # With nfs_export=on index will contain a whiteout index entry, so allow
99         # chardev entries in index dir.
100         find $workdir/index -mindepth 1 -type c -o -print
101 }
102
103 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
104 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
105 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
106
107 # Remove all files from previous tests
108 _scratch_mkfs
109
110 # Create lower hardlinks
111 create_hardlinks
112
113 # Enable overlay index feature to prevent breaking hardlinks on copy up
114 _scratch_mount -o index=on
115
116 # Copy up and index hardlinks
117 touch $SCRATCH_MNT/0
118 touch $SCRATCH_MNT/1
119 touch $SCRATCH_MNT/2
120
121 # Perform the rest of the changes offline
122 $UMOUNT_PROG $SCRATCH_MNT
123
124 test_hardlinks_offline
125
126 status=0
127 exit