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
33 _require_scratch_nocheck
35 # Assume that if we can run scrub on the test dev we can run it on the scratch
38 _supports_xfs_scrub $TEST_DIR $TEST_DEV && run_scrub=1
42 echo "$@" | tee -a $seqres.full /dev/ttyprintk
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
59 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
60 echo "Repair found problems."
62 echo "mount failed" >> $seqres.full
64 _scratch_xfs_get_sb_field unit >> $seqres.full
65 _scratch_xfs_get_sb_field width >> $seqres.full
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
71 # If the previous mount succeeded, mount the fs and look for the file
73 if [ $mounted -gt 0 ]; then
75 test -f $SCRATCH_MNT/a || echo "Root directory got nuked."
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
87 __test_mount_opts "$@"
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
97 __test_mount_opts "$@"
100 test_repair_detection()
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
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
117 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
118 echo "Repair found problems."
120 echo "mount failed" >> $seqres.full
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
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
135 # If the previous mount succeeded, mount the fs and look for the file
137 if [ $mounted -gt 0 ]; then
139 test -f $SCRATCH_MNT/a || echo "Root directory got nuked."
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
151 log "Test: no raid parameters"
154 log "Test: 256k stripe unit; 4x stripe width"
155 test_su_opts -o sunit=512,swidth=2048
157 log "Test: 256k stripe unit; 5x stripe width"
158 test_su_opts -o sunit=512,swidth=2560
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
164 log "Test: 512k stripe unit; 3x stripe width"
165 test_su_opts -o sunit=1024,swidth=3072
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
172 # Note: Should succeed without nuking the root dir
173 log "Test: Repair of 128k stripe unit; 8x stripe width"
174 test_repair_detection
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