xfs/007: fix regressions on V4 filesystems
[xfstests-dev.git] / tests / xfs / 291
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 291
6 #
7 # Test xfs_repair on fragmented multi-block dir2 fs
8 #
9 . ./common/preamble
10 _begin_fstest auto repair
11
12 # Import common functions.
13 . ./common/filter
14
15 _supported_fs xfs
16
17 # real QA test starts here
18 _require_scratch
19 logblks=$(_scratch_find_xfs_min_logblocks -n size=16k -d size=133m)
20 _scratch_mkfs_xfs -n size=16k -l size=${logblks}b -d size=133m >> $seqres.full 2>&1
21 _scratch_mount
22
23 # First we cause very badly fragmented freespace, then
24 # make some multiblock directories in the filesystem, which
25 # should come out very fragmented as a result
26
27 # Step 1: Cause badly fragmented free space
28
29 # XXX: this needs to be factored to match what generic/204 does to support
30 # different inode sizes without ENOSPC
31 mkdir $SCRATCH_MNT/fragdir
32 for I in `seq 0 26200`; do
33         (echo data > $SCRATCH_MNT/fragdir/f$I) >> $seqres.full 2>&1
34 done
35 sync
36
37 for I in `seq 0 2 26200`; do
38         rm -f $SCRATCH_MNT/fragdir/f$I >> $seqres.full 2>&1
39 done
40 sync
41
42 # Soak up any remaining freespace
43 $XFS_IO_PROG -f -c "pwrite 0 16m" -c "fsync" $SCRATCH_MNT/space_file.large >> $seqres.full 2>&1
44
45 # Take a look at freespace for any post-mortem on the test
46 _scratch_unmount
47 _scratch_xfs_db -r -c freesp  >> $seqres.full 2>&1
48 _scratch_mount
49
50 # Step 2: Make a bunch of (hopefully fragmented) multiblock
51 # dir2 directories
52
53 # - FMT_LOCAL
54 mkdir $SCRATCH_MNT/S_IFDIR.FMT_LOCAL
55 touch $SCRATCH_MNT/S_IFDIR.FMT_LOCAL/localdirfile
56
57 # - FMT_EXTENTS
58 mkdir $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS
59 for I in `seq 1 100`; do
60         touch $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
61 done
62 # With a few missing
63 for I in `seq 10 2 20` 100; do
64         rm -f $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
65 done
66
67 # - FMT_BTREE
68 mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE
69 for I in `seq 1 1000`; do
70         touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
71 done
72 # With a few missing
73 for I in `seq 10 2 20` 1000; do
74         rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
75 done
76
77 # Dave's special hack - grow freespace tree
78 mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE2
79 for I in `seq 1 5000`; do
80         touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
81 done
82 # Remove every other (odds)
83 for I in `seq 1 2 5000`; do
84         rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
85 done
86
87 _scratch_unmount
88 # Can xfs_repair and xfs_check cope with this monster?
89 _scratch_xfs_repair >> $seqres.full 2>&1 || _fail "xfs_repair failed"
90 _scratch_xfs_check >> $seqres.full 2>&1 || _fail "xfs_check failed"
91
92 # Yes they can!  Now...
93 # Can xfs_metadump cope with this monster?
94 _scratch_xfs_metadump $tmp.metadump || _fail "xfs_metadump failed"
95 xfs_mdrestore $tmp.metadump $tmp.img || _fail "xfs_mdrestore failed"
96 [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ] && \
97         rt_repair_opts="-r $SCRATCH_RTDEV"
98 [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_LOGDEV" ] && \
99         log_repair_opts="-l $SCRATCH_LOGDEV"
100 $XFS_REPAIR_PROG $rt_repair_opts $log_repair_opts -f $tmp.img >> $seqres.full 2>&1 || \
101         _fail "xfs_repair of metadump failed"
102
103 # Yes it can; success, all done
104 status=0
105 exit
106