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