xfs: Check for extent overflow when trivally adding a new extent
[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 _require_scratch
37 _require_scratch_feature index
38
39 report_nlink()
40 {
41         when=$1
42
43         # mount and check nlink after overlay offline modification
44         _scratch_mount -o index=on
45
46         # List <nlink> <name>
47         echo "== $when offline =="
48         for f in $HARDLINKS; do
49                 _ls_l $SCRATCH_MNT/$f | awk '{ print $2, $9 }' | _filter_scratch
50         done
51
52         $UMOUNT_PROG $SCRATCH_MNT
53 }
54
55 # Create lower hardlinks
56 create_hardlinks()
57 {
58         mkdir -p $lowerdir
59         touch $lowerdir/0
60         ln $lowerdir/0 $lowerdir/1
61         ln $lowerdir/0 $lowerdir/2
62 }
63
64 test_hardlinks_offline()
65 {
66         HARDLINKS=`seq 0 2`
67         report_nlink "all upper"
68
69         # Unlink copied up hardlink
70         rm $upperdir/0
71         HARDLINKS=`seq 1 2`
72         report_nlink "unlink upper"
73
74         # Link to copied up hardlink
75         ln $upperdir/2 $upperdir/3
76         HARDLINKS=`seq 1 3`
77         report_nlink "link upper"
78
79         # Rename over copied up hardlink
80         touch $upperdir/new
81         mv $upperdir/new $upperdir/1
82         HARDLINKS=`seq 2 3`
83         report_nlink "rename over upper"
84
85         # Unlink new upper hardlink
86         rm $upperdir/3
87         HARDLINKS=2
88         report_nlink "unlink new upper"
89
90         # Unlink last upper and drop union nlink to zero
91         rm $upperdir/2
92
93         HARDLINKS=
94         report_nlink "unlink last lower"
95
96         # Verify that orphan index is cleaned when dropping nlink to zero
97         # With nfs_export=on index will contain a whiteout index entry, so allow
98         # chardev entries in index dir.
99         find $workdir/index -mindepth 1 -type c -o -print
100 }
101
102 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
103 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
104 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
105
106 # Remove all files from previous tests
107 _scratch_mkfs
108
109 # Create lower hardlinks
110 create_hardlinks
111
112 # Enable overlay index feature to prevent breaking hardlinks on copy up
113 _scratch_mount -o index=on
114
115 # Copy up and index hardlinks
116 touch $SCRATCH_MNT/0
117 touch $SCRATCH_MNT/1
118 touch $SCRATCH_MNT/2
119
120 # Perform the rest of the changes offline
121 $UMOUNT_PROG $SCRATCH_MNT
122
123 test_hardlinks_offline
124
125 status=0
126 exit