summaryrefslogtreecommitdiff
path: root/tests/xfs/291
blob: 54448497cc29e135c023d3d4f8df6439599b57b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) Red Hat, Inc.  All Rights Reserved.
#
# FS QA Test No. 291
#
# Test xfs_repair on fragmented multi-block dir2 fs
#
. ./common/preamble
_begin_fstest auto repair metadump

# Import common functions.
. ./common/filter

_supported_fs xfs
_require_command "$XFS_MDRESTORE_PROG" "xfs_mdrestore"

# real QA test starts here
_require_scratch
logblks=$(_scratch_find_xfs_min_logblocks -n size=16k -d size=133m)
_scratch_mkfs_xfs -n size=16k -l size=${logblks}b -d size=133m >> $seqres.full 2>&1
_scratch_mount

# First we cause very badly fragmented freespace, then
# make some multiblock directories in the filesystem, which
# should come out very fragmented as a result

# Step 1: Cause badly fragmented free space
# 
# XXX: this needs to be factored to match what generic/204 does to support
# different inode sizes without ENOSPC
mkdir $SCRATCH_MNT/fragdir
for I in `seq 0 26200`; do
        (echo data > $SCRATCH_MNT/fragdir/f$I) >> $seqres.full 2>&1
done
sync

for I in `seq 0 2 26200`; do
        rm -f $SCRATCH_MNT/fragdir/f$I >> $seqres.full 2>&1
done
sync

# Soak up any remaining freespace
$XFS_IO_PROG -f -c "pwrite 0 16m" -c "fsync" $SCRATCH_MNT/space_file.large >> $seqres.full 2>&1

# Take a look at freespace for any post-mortem on the test
_scratch_unmount
_scratch_xfs_db -r -c freesp  >> $seqres.full 2>&1
_scratch_mount

# Step 2: Make a bunch of (hopefully fragmented) multiblock
# dir2 directories

# - FMT_LOCAL
mkdir $SCRATCH_MNT/S_IFDIR.FMT_LOCAL
touch $SCRATCH_MNT/S_IFDIR.FMT_LOCAL/localdirfile

# - FMT_EXTENTS
mkdir $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS
for I in `seq 1 100`; do
	touch $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
done
# With a few missing
for I in `seq 10 2 20` 100; do
	rm -f $SCRATCH_MNT/S_IFDIR.FMT_EXTENTS/extent_dir_file_$I
done

# - FMT_BTREE
mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE
for I in `seq 1 1000`; do
	touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
done
# With a few missing
for I in `seq 10 2 20` 1000; do
	rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE/btree_dir_file_$I
done

# Dave's special hack - grow freespace tree
mkdir $SCRATCH_MNT/S_IFDIR.FMT_BTREE2
for I in `seq 1 5000`; do
	touch $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
done
# Remove every other (odds)
for I in `seq 1 2 5000`; do
	rm -f $SCRATCH_MNT/S_IFDIR.FMT_BTREE2/btree2_dir_file_$I
done

_scratch_unmount
# Can xfs_repair and xfs_check cope with this monster?
_scratch_xfs_repair >> $seqres.full 2>&1 || _fail "xfs_repair failed"
_scratch_xfs_check >> $seqres.full 2>&1 || _fail "xfs_check failed"

# Yes they can!  Now...
# Can xfs_metadump cope with this monster?
_scratch_xfs_metadump $tmp.metadump -a -o || _fail "xfs_metadump failed"
SCRATCH_DEV=$tmp.img _scratch_xfs_mdrestore $tmp.metadump || _fail "xfs_mdrestore failed"
SCRATCH_DEV=$tmp.img _scratch_xfs_repair -f &>> $seqres.full || \
	_fail "xfs_repair of metadump failed"

# Yes it can; success, all done
status=0
exit