2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2020, Oracle and/or its affiliates. All Rights Reserved.
7 # Update sunit and width and make sure that the filesystem still passes
8 # xfs_repair afterwards.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
27 # get standard environment, filters and checks
31 # real QA test starts here
34 _require_scratch_nocheck
36 # Assume that if we can run scrub on the test dev we can run it on the scratch
39 _supports_xfs_scrub $TEST_DIR $TEST_DEV && run_scrub=1
43 echo "$@" | tee -a $seqres.full /dev/ttyprintk
50 # Try to mount the fs with our test options.
51 _try_scratch_mount "$@" >> $seqres.full 2>&1 && mounted=1
52 if [ $mounted -gt 0 ]; then
53 # Implant a sentinel file to see if repair nukes the directory
54 # later. Scrub, unmount, and check for errors.
55 echo moo > $SCRATCH_MNT/a
56 grep "$SCRATCH_MNT" /proc/mounts >> $seqres.full
57 test $run_scrub -gt 0 && \
58 _scratch_scrub -n >> $seqres.full
60 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
61 echo "Repair found problems."
63 echo "mount failed" >> $seqres.full
65 _scratch_xfs_get_sb_field unit >> $seqres.full
66 _scratch_xfs_get_sb_field width >> $seqres.full
68 # Run xfs_repair in repair mode to see if it can be baited into nuking
69 # the root filesystem on account of the sunit update.
70 _scratch_xfs_repair >> $seqres.full 2>&1
72 # If the previous mount succeeded, mount the fs and look for the file
74 if [ $mounted -gt 0 ]; then
76 test -f $SCRATCH_MNT/a || echo "Root directory got nuked."
85 echo "Format with 4k stripe unit; 1x stripe width" >> $seqres.full
86 _scratch_mkfs -b size=4k -d sunit=8,swidth=8 >> $seqres.full 2>&1
88 __test_mount_opts "$@"
95 echo "Format with 256k stripe unit; 4x stripe width" >> $seqres.full
96 _scratch_mkfs -b size=1k -d su=256k,sw=4 >> $seqres.full 2>&1
98 __test_mount_opts "$@"
101 test_repair_detection()
105 echo "Format with 256k stripe unit; 4x stripe width" >> $seqres.full
106 _scratch_mkfs -b size=1k -d su=256k,sw=4 >> $seqres.full 2>&1
108 # Try to mount the fs with our test options.
109 _try_scratch_mount >> $seqres.full 2>&1 && mounted=1
110 if [ $mounted -gt 0 ]; then
111 # Implant a sentinel file to see if repair nukes the directory
112 # later. Scrub, unmount, and check for errors.
113 echo moo > $SCRATCH_MNT/a
114 grep "$SCRATCH_MNT" /proc/mounts >> $seqres.full
115 test $run_scrub -gt 0 && \
116 _scratch_scrub -n >> $seqres.full
118 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
119 echo "Repair found problems."
121 echo "mount failed" >> $seqres.full
124 # Update the superblock like the kernel used to do.
125 _scratch_xfs_get_sb_field unit >> $seqres.full
126 _scratch_xfs_get_sb_field width >> $seqres.full
127 _scratch_xfs_set_sb_field unit 256 >> $seqres.full
128 _scratch_xfs_set_sb_field width 1024 >> $seqres.full
129 _scratch_xfs_get_sb_field unit >> $seqres.full
130 _scratch_xfs_get_sb_field width >> $seqres.full
132 # Run xfs_repair in repair mode to see if it can be baited into nuking
133 # the root filesystem on account of the sunit update.
134 _scratch_xfs_repair >> $seqres.full 2>&1
136 # If the previous mount succeeded, mount the fs and look for the file
138 if [ $mounted -gt 0 ]; then
140 test -f $SCRATCH_MNT/a || echo "Root directory got nuked."
147 # Format with a 256k stripe unit and 4x stripe width, and try various mount
148 # options that want to change that and see if they blow up. Normally you
149 # would never change the stripe *unit*, so it's no wonder this is not well
152 log "Test: no raid parameters"
155 log "Test: 256k stripe unit; 4x stripe width"
156 test_su_opts -o sunit=512,swidth=2048
158 log "Test: 256k stripe unit; 5x stripe width"
159 test_su_opts -o sunit=512,swidth=2560
161 # Note: Larger stripe units probably won't mount
162 log "Test: 512k stripe unit; 4x stripe width"
163 test_su_opts -o sunit=1024,swidth=4096
165 log "Test: 512k stripe unit; 3x stripe width"
166 test_su_opts -o sunit=1024,swidth=3072
168 # Note: Should succeed with kernel warnings, and should not create repair
169 # failures or nuke the root directory.
170 log "Test: 128k stripe unit; 8x stripe width"
171 test_su_opts -o sunit=256,swidth=2048
173 # Note: Should succeed without nuking the root dir
174 log "Test: Repair of 128k stripe unit; 8x stripe width"
175 test_repair_detection
177 # Brian Foster noticed a bug in an earlier version of the patch that avoids
178 # updating the ondisk sunit/swidth values if they would cause later repair
179 # failures. The bug was that we wouldn't convert the kernel mount option sunit
180 # value to the correct incore units until after computing the inode geometry.
181 # This caused it to behave incorrectly when the filesystem was formatted with
182 # sunit=1fsb and the mount options try to increase swidth.
183 log "Test: Formatting with sunit=1fsb,swidth=1fsb and mounting with larger swidth"
184 test_sunit_opts -o sunit=8,swidth=64