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
25 # get standard environment, filters and checks
29 # real QA test starts here
32 _require_scratch_nocheck
34 # Assume that if we can run scrub on the test dev we can run it on the scratch
37 _supports_xfs_scrub $TEST_DIR $TEST_DEV && run_scrub=1
41 echo "$@" | tee -a $seqres.full /dev/ttyprintk
48 # Try to mount the fs with our test options.
49 _try_scratch_mount "$@" >> $seqres.full 2>&1 && mounted=1
50 if [ $mounted -gt 0 ]; then
51 # Implant a sentinel file to see if repair nukes the directory
52 # later. Scrub, unmount, and check for errors.
53 echo moo > $SCRATCH_MNT/a
54 grep "$SCRATCH_MNT" /proc/mounts >> $seqres.full
55 test $run_scrub -gt 0 && \
56 _scratch_scrub -n >> $seqres.full
58 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
59 echo "Repair found problems."
61 echo "mount failed" >> $seqres.full
63 _scratch_xfs_db -c 'sb 0' -c 'p unit width' >> $seqres.full
65 # Run xfs_repair in repair mode to see if it can be baited into nuking
66 # the root filesystem on account of the sunit update.
67 _scratch_xfs_repair >> $seqres.full 2>&1
69 # If the previous mount succeeded, mount the fs and look for the file
71 if [ $mounted -gt 0 ]; then
73 test -f $SCRATCH_MNT/a || echo "Root directory got nuked."
82 echo "Format with 4k stripe unit; 1x stripe width" >> $seqres.full
83 _scratch_mkfs -b size=4k -d sunit=8,swidth=8 >> $seqres.full 2>&1
85 __test_mount_opts "$@"
92 echo "Format with 256k stripe unit; 4x stripe width" >> $seqres.full
93 _scratch_mkfs -b size=1k -d su=256k,sw=4 >> $seqres.full 2>&1
95 __test_mount_opts "$@"
98 test_repair_detection()
102 echo "Format with 256k stripe unit; 4x stripe width" >> $seqres.full
103 _scratch_mkfs -b size=1k -d su=256k,sw=4 >> $seqres.full 2>&1
105 # Try to mount the fs with our test options.
106 _try_scratch_mount >> $seqres.full 2>&1 && mounted=1
107 if [ $mounted -gt 0 ]; then
108 # Implant a sentinel file to see if repair nukes the directory
109 # later. Scrub, unmount, and check for errors.
110 echo moo > $SCRATCH_MNT/a
111 grep "$SCRATCH_MNT" /proc/mounts >> $seqres.full
112 test $run_scrub -gt 0 && \
113 _scratch_scrub -n >> $seqres.full
115 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
116 echo "Repair found problems."
118 echo "mount failed" >> $seqres.full
121 # Update the superblock like the kernel used to do.
122 _scratch_xfs_db -c 'sb 0' -c 'p unit width' >> $seqres.full
123 _scratch_xfs_db -x -c 'sb 0' -c 'write -d unit 256' -c 'write -d width 1024' >> $seqres.full
124 _scratch_xfs_db -c 'sb 0' -c 'p unit width' >> $seqres.full
126 # Run xfs_repair in repair mode to see if it can be baited into nuking
127 # the root filesystem on account of the sunit update.
128 _scratch_xfs_repair >> $seqres.full 2>&1
130 # If the previous mount succeeded, mount the fs and look for the file
132 if [ $mounted -gt 0 ]; then
134 test -f $SCRATCH_MNT/a || echo "Root directory got nuked."
141 # Format with a 256k stripe unit and 4x stripe width, and try various mount
142 # options that want to change that and see if they blow up. Normally you
143 # would never change the stripe *unit*, so it's no wonder this is not well
146 log "Test: no raid parameters"
149 log "Test: 256k stripe unit; 4x stripe width"
150 test_su_opts -o sunit=512,swidth=2048
152 log "Test: 256k stripe unit; 5x stripe width"
153 test_su_opts -o sunit=512,swidth=2560
155 # Note: Larger stripe units probably won't mount
156 log "Test: 512k stripe unit; 4x stripe width"
157 test_su_opts -o sunit=1024,swidth=4096
159 log "Test: 512k stripe unit; 3x stripe width"
160 test_su_opts -o sunit=1024,swidth=3072
162 # Note: Should succeed with kernel warnings, and should not create repair
163 # failures or nuke the root directory.
164 log "Test: 128k stripe unit; 8x stripe width"
165 test_su_opts -o sunit=256,swidth=2048
167 # Note: Should succeed without nuking the root dir
168 log "Test: Repair of 128k stripe unit; 8x stripe width"
169 test_repair_detection
171 # Brian Foster noticed a bug in an earlier version of the patch that avoids
172 # updating the ondisk sunit/swidth values if they would cause later repair
173 # failures. The bug was that we wouldn't convert the kernel mount option sunit
174 # value to the correct incore units until after computing the inode geometry.
175 # This caused it to behave incorrectly when the filesystem was formatted with
176 # sunit=1fsb and the mount options try to increase swidth.
177 log "Test: Formatting with sunit=1fsb,swidth=1fsb and mounting with larger swidth"
178 test_sunit_opts -o sunit=8,swidth=64