2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) Red Hat, Inc. All Rights Reserved.
7 # Test xfs_repair on fragmented multi-block dir2 fs
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
30 # real QA test starts here
33 logblks=$(_scratch_find_xfs_min_logblocks -n size=16k -d size=133m)
34 _scratch_mkfs_xfs -n size=16k -l size=${logblks}b -d size=133m >> $seqres.full 2>&1
37 # First we cause very badly fragmented freespace, then
38 # make some multiblock directories in the filesystem, which
39 # should come out very fragmented as a result
41 # Step 1: Cause badly fragmented free space
43 # XXX: this needs to be factored to match what generic/204 does to support
44 # different inode sizes without ENOSPC
45 mkdir $SCRATCH_MNT/fragdir
46 for I in `seq 0 26200`; do
47 (echo data > $SCRATCH_MNT/fragdir/f$I) >> $seqres.full 2>&1
51 for I in `seq 0 2 26200`; do
52 rm -f $SCRATCH_MNT/fragdir/f$I >> $seqres.full 2>&1
56 # Soak up any remaining freespace
57 $XFS_IO_PROG -f -c "pwrite 0 16m" -c "fsync" $SCRATCH_MNT/space_file.large >> $seqres.full 2>&1
59 # Take a look at freespace for any post-mortem on the test
61 _scratch_xfs_db -r -c freesp >> $seqres.full 2>&1
64 # Step 2: Make a bunch of (hopefully fragmented) multiblock
68 mkdir $SCRATCH_MNT/S_IFDIR.FMT_LOCAL
69 touch $SCRATCH_MNT/S_IFDIR.FMT_LOCAL/localdirfile
72 mkdir $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS
73 for I in `seq 1 100`; do
74 touch $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
77 for I in `seq 10 2 20` 100; do
78 rm -f $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
82 mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE
83 for I in `seq 1 1000`; do
84 touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
87 for I in `seq 10 2 20` 1000; do
88 rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
91 # Dave's special hack - grow freespace tree
92 mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE2
93 for I in `seq 1 5000`; do
94 touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
96 # Remove every other (odds)
97 for I in `seq 1 2 5000`; do
98 rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
102 # Can xfs_repair and xfs_check cope with this monster?
103 _scratch_xfs_repair >> $seqres.full 2>&1 || _fail "xfs_repair failed"
104 _scratch_xfs_check >> $seqres.full 2>&1 || _fail "xfs_check failed"
106 # Yes they can! Now...
107 # Can xfs_metadump cope with this monster?
108 _scratch_xfs_metadump $tmp.metadump || _fail "xfs_metadump failed"
109 xfs_mdrestore $tmp.metadump $tmp.img || _fail "xfs_mdrestore failed"
110 [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ] && \
111 rt_repair_opts="-r $SCRATCH_RTDEV"
112 [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_LOGDEV" ] && \
113 log_repair_opts="-l $SCRATCH_LOGDEV"
114 $XFS_REPAIR_PROG $rt_repair_opts $log_repair_opts -f $tmp.img >> $seqres.full 2>&1 || \
115 _fail "xfs_repair of metadump failed"
117 # Yes it can; success, all done