xfs: test what happens when we reset the root dir and it has xattrs
[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 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 _supported_fs xfs
29
30 # real QA test starts here
31 rm -f $seqres.full
32 _require_scratch
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
35 _scratch_mount
36
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
40
41 # Step 1: Cause badly fragmented free space
42
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
48 done
49 sync
50
51 for I in `seq 0 2 26200`; do
52         rm -f $SCRATCH_MNT/fragdir/f$I >> $seqres.full 2>&1
53 done
54 sync
55
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
58
59 # Take a look at freespace for any post-mortem on the test
60 _scratch_unmount
61 _scratch_xfs_db -r -c freesp  >> $seqres.full 2>&1
62 _scratch_mount
63
64 # Step 2: Make a bunch of (hopefully fragmented) multiblock
65 # dir2 directories
66
67 # - FMT_LOCAL
68 mkdir $SCRATCH_MNT/S_IFDIR.FMT_LOCAL
69 touch $SCRATCH_MNT/S_IFDIR.FMT_LOCAL/localdirfile
70
71 # - FMT_EXTENTS
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
75 done
76 # With a few missing
77 for I in `seq 10 2 20` 100; do
78         rm -f $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
79 done
80
81 # - FMT_BTREE
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
85 done
86 # With a few missing
87 for I in `seq 10 2 20` 1000; do
88         rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
89 done
90
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
95 done
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
99 done
100
101 _scratch_unmount
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"
105
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"
116
117 # Yes it can; success, all done
118 status=0
119 exit
120