xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / xfs / 516
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2020, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 516
6 #
7 # Update sunit and width and make sure that the filesystem still passes
8 # xfs_repair afterwards.
9
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1    # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         rm -f $tmp.*
22         cd /
23 }
24
25 rm -f $seqres.full
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/fuzzy
30
31 # real QA test starts here
32 _supported_fs xfs
33 _require_scratch_nocheck
34
35 # Assume that if we can run scrub on the test dev we can run it on the scratch
36 # fs too.
37 run_scrub=0
38 _supports_xfs_scrub $TEST_DIR $TEST_DEV && run_scrub=1
39
40 log()
41 {
42         echo "$@" | tee -a $seqres.full /dev/ttyprintk
43 }
44
45 __test_mount_opts()
46 {
47         local mounted=0
48
49         # Try to mount the fs with our test options.
50         _try_scratch_mount "$@" >> $seqres.full 2>&1 && mounted=1
51         if [ $mounted -gt 0 ]; then
52                 # Implant a sentinel file to see if repair nukes the directory
53                 # later.  Scrub, unmount, and check for errors.
54                 echo moo > $SCRATCH_MNT/a
55                 grep "$SCRATCH_MNT" /proc/mounts >> $seqres.full
56                 test $run_scrub -gt 0 && \
57                         _scratch_scrub -n >> $seqres.full
58                 _scratch_unmount
59                 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
60                         echo "Repair found problems."
61         else
62                 echo "mount failed" >> $seqres.full
63         fi
64         _scratch_xfs_get_sb_field unit >> $seqres.full
65         _scratch_xfs_get_sb_field width  >> $seqres.full
66
67         # Run xfs_repair in repair mode to see if it can be baited into nuking
68         # the root filesystem on account of the sunit update.
69         _scratch_xfs_repair >> $seqres.full 2>&1
70
71         # If the previous mount succeeded, mount the fs and look for the file
72         # we implanted.
73         if [ $mounted -gt 0 ]; then
74                 _scratch_mount
75                 test -f $SCRATCH_MNT/a || echo "Root directory got nuked."
76                 _scratch_unmount
77         fi
78
79         echo >> $seqres.full
80 }
81
82 test_sunit_opts()
83 {
84         echo "Format with 4k stripe unit; 1x stripe width" >> $seqres.full
85         _scratch_mkfs -b size=4k -d sunit=8,swidth=8 >> $seqres.full 2>&1
86
87         __test_mount_opts "$@"
88 }
89
90 test_su_opts()
91 {
92         local mounted=0
93
94         echo "Format with 256k stripe unit; 4x stripe width" >> $seqres.full
95         _scratch_mkfs -b size=1k -d su=256k,sw=4 >> $seqres.full 2>&1
96
97         __test_mount_opts "$@"
98 }
99
100 test_repair_detection()
101 {
102         local mounted=0
103
104         echo "Format with 256k stripe unit; 4x stripe width" >> $seqres.full
105         _scratch_mkfs -b size=1k -d su=256k,sw=4 >> $seqres.full 2>&1
106
107         # Try to mount the fs with our test options.
108         _try_scratch_mount >> $seqres.full 2>&1 && mounted=1
109         if [ $mounted -gt 0 ]; then
110                 # Implant a sentinel file to see if repair nukes the directory
111                 # later.  Scrub, unmount, and check for errors.
112                 echo moo > $SCRATCH_MNT/a
113                 grep "$SCRATCH_MNT" /proc/mounts >> $seqres.full
114                 test $run_scrub -gt 0 && \
115                         _scratch_scrub -n >> $seqres.full
116                 _scratch_unmount
117                 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
118                         echo "Repair found problems."
119         else
120                 echo "mount failed" >> $seqres.full
121         fi
122
123         # Update the superblock like the kernel used to do.
124         _scratch_xfs_get_sb_field unit >> $seqres.full
125         _scratch_xfs_get_sb_field width >> $seqres.full
126         _scratch_xfs_set_sb_field unit 256 >> $seqres.full
127         _scratch_xfs_set_sb_field width 1024 >> $seqres.full
128         _scratch_xfs_get_sb_field unit >> $seqres.full
129         _scratch_xfs_get_sb_field width >> $seqres.full
130
131         # Run xfs_repair in repair mode to see if it can be baited into nuking
132         # the root filesystem on account of the sunit update.
133         _scratch_xfs_repair >> $seqres.full 2>&1
134
135         # If the previous mount succeeded, mount the fs and look for the file
136         # we implanted.
137         if [ $mounted -gt 0 ]; then
138                 _scratch_mount
139                 test -f $SCRATCH_MNT/a || echo "Root directory got nuked."
140                 _scratch_unmount
141         fi
142
143         echo >> $seqres.full
144 }
145
146 # Format with a 256k stripe unit and 4x stripe width, and try various mount
147 # options that want to change that and see if they blow up.  Normally you
148 # would never change the stripe *unit*, so it's no wonder this is not well
149 # tested.
150
151 log "Test: no raid parameters"
152 test_su_opts
153
154 log "Test: 256k stripe unit; 4x stripe width"
155 test_su_opts -o sunit=512,swidth=2048
156
157 log "Test: 256k stripe unit; 5x stripe width"
158 test_su_opts -o sunit=512,swidth=2560
159
160 # Note: Larger stripe units probably won't mount
161 log "Test: 512k stripe unit; 4x stripe width"
162 test_su_opts -o sunit=1024,swidth=4096
163
164 log "Test: 512k stripe unit; 3x stripe width"
165 test_su_opts -o sunit=1024,swidth=3072
166
167 # Note: Should succeed with kernel warnings, and should not create repair
168 # failures or nuke the root directory.
169 log "Test: 128k stripe unit; 8x stripe width"
170 test_su_opts -o sunit=256,swidth=2048
171
172 # Note: Should succeed without nuking the root dir
173 log "Test: Repair of 128k stripe unit; 8x stripe width"
174 test_repair_detection
175
176 # Brian Foster noticed a bug in an earlier version of the patch that avoids
177 # updating the ondisk sunit/swidth values if they would cause later repair
178 # failures.  The bug was that we wouldn't convert the kernel mount option sunit
179 # value to the correct incore units until after computing the inode geometry.
180 # This caused it to behave incorrectly when the filesystem was formatted with
181 # sunit=1fsb and the mount options try to increase swidth.
182 log "Test: Formatting with sunit=1fsb,swidth=1fsb and mounting with larger swidth"
183 test_sunit_opts -o sunit=8,swidth=64
184
185 # success, all done
186 status=0
187 exit