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 _begin_fstest auto quick
13 # Override the default cleanup function.
20 # Import common functions.
23 # real QA test starts here
25 _require_scratch_nocheck
27 # Assume that if we can run scrub on the test dev we can run it on the scratch
30 _supports_xfs_scrub $TEST_DIR $TEST_DEV && run_scrub=1
34 echo "$@" | tee -a $seqres.full /dev/ttyprintk
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
51 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
52 echo "Repair found problems."
54 echo "mount failed" >> $seqres.full
56 _scratch_xfs_get_sb_field unit >> $seqres.full
57 _scratch_xfs_get_sb_field width >> $seqres.full
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
63 # If the previous mount succeeded, mount the fs and look for the file
65 if [ $mounted -gt 0 ]; then
67 test -f $SCRATCH_MNT/a || echo "Root directory got nuked."
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
79 __test_mount_opts "$@"
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
89 __test_mount_opts "$@"
92 test_repair_detection()
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
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
109 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
110 echo "Repair found problems."
112 echo "mount failed" >> $seqres.full
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
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
127 # If the previous mount succeeded, mount the fs and look for the file
129 if [ $mounted -gt 0 ]; then
131 test -f $SCRATCH_MNT/a || echo "Root directory got nuked."
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
143 log "Test: no raid parameters"
146 log "Test: 256k stripe unit; 4x stripe width"
147 test_su_opts -o sunit=512,swidth=2048
149 log "Test: 256k stripe unit; 5x stripe width"
150 test_su_opts -o sunit=512,swidth=2560
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
156 log "Test: 512k stripe unit; 3x stripe width"
157 test_su_opts -o sunit=1024,swidth=3072
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
164 # Note: Should succeed without nuking the root dir
165 log "Test: Repair of 128k stripe unit; 8x stripe width"
166 test_repair_detection
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