blob: 4433d577e2132167c1852a93241e0de64dec210f (
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
#
# FS QA Test No. 042
#
# xfs_fsr QA tests
# create a large fragmented file and check that xfs_fsr doesn't corrupt
# it or the other contents of the filesystem
#
set +x
. ./common/preamble
_begin_fstest fsr ioctl auto prealloc
# Override the default cleanup function.
_cleanup()
{
_scratch_unmount
rm -f $tmp.*
}
# Import common functions.
. ./common/filter
# real QA test starts here
_supported_fs xfs
_require_xfs_io_command "falloc"
_require_scratch
[ "$XFS_FSR_PROG" = "" ] && _notrun "xfs_fsr not found"
# Test performs several operations to produce a badly fragmented file, then
# create enough contiguous free space for xfs_fsr to defragment the fragmented
# file:
#
# - create fs with 3 minimum sized (16Mb) allocation groups
# - create 16x1MB contiguous files which will become large free space extents
# when deleted
# - put a small "space" between each of the 16 contiuguous files to ensure we
# have separated free space extents
# - fill the remaining free space with a "fill file"
# - mount/unmount/fill remaining free space with a pad file
# - punch alternate single block holes in the the "fill file" to create
# fragmented free space.
# - use fill2 to generate a very large fragmented file
# - delete the 16 large contiguous files created initially
# - run xfs_fsr on the filesystem
# - check checksums for remaining files
_do_die_on_error=message_only
echo -n "Make a 96 megabyte filesystem on SCRATCH_DEV and mount... "
_scratch_mkfs_xfs -dsize=96m,agcount=3 2>&1 >/dev/null || _fail "mkfs failed"
_scratch_mount
echo "done"
echo -n "Reserve 32 1Mb unfragmented regions... "
for i in `seq 1 32`
do
_do "$XFS_IO_PROG -f -c \"resvsp 0 1m\" $SCRATCH_MNT/hole$i"
_do "$XFS_IO_PROG -f -c \"resvsp 0 4k\" $SCRATCH_MNT/space$i"
_do "xfs_bmap -vp $SCRATCH_MNT/hole$i"
done
echo "done"
# set up filesystem
echo -n "Fill filesystem with fill file... "
for i in `seq 0 1 63`; do
_do "$XFS_IO_PROG -f -c \"falloc ${i}m 1m\" $SCRATCH_MNT/fill"
done
_do "xfs_bmap -vp $SCRATCH_MNT/fill"
echo "done"
# flush the filesystem - make sure there is no space "lost" to pre-allocation
_do "_scratch_unmount"
_do "_try_scratch_mount"
echo -n "Use up any further available space... "
_do "$XFS_IO_PROG -f -c \"falloc 0 1m\" $SCRATCH_MNT/pad"
echo "done"
# create fragmented file
#_do "Delete every second file" "_cull_files"
echo -n "Punch every second 4k block... "
for i in `seq 0 8 65536`; do
# This generates excessive output that significantly slows down the
# test. It's not necessary for debug, so just bin it.
$XFS_IO_PROG -f -c "unresvsp ${i}k 4k" $SCRATCH_MNT/fill \
> /dev/null 2>&1
done
_do "xfs_bmap -vp $SCRATCH_MNT/fill"
_do "sum $SCRATCH_MNT/fill >$tmp.fillsum1"
echo "done"
echo -n "Create one very large file... "
_do "$here/src/fill2 -d nbytes=32000000,file=$SCRATCH_MNT/fragmented"
echo "done"
_do "xfs_bmap -v $SCRATCH_MNT/fragmented"
_do "sum $SCRATCH_MNT/fragmented >$tmp.sum1"
_do "Remove other files" "rm -rf $SCRATCH_MNT/{pad,hole*}"
# defragment
_do "Run xfs_fsr on filesystem" "$XFS_FSR_PROG -v $SCRATCH_MNT/fragmented"
_do "xfs_bmap -v $SCRATCH_MNT/fragmented"
echo -n "Check fill file... "
_do "sum $SCRATCH_MNT/fill >$tmp.fillsum2"
if ! _do "diff $tmp.fillsum1 $tmp.fillsum2"; then
echo "fail"
echo "Fill file is corrupt/missing after fsr. Test failed see $seqres.full"
status=1; exit
fi
echo "done"
# check
echo -n "Check large file... "
_do "sum $SCRATCH_MNT/fragmented >$tmp.sum2"
if ! _do "diff $tmp.sum1 $tmp.sum2"; then
echo "fail"
echo "File is corrupt/missing after fsr. Test failed see $seqres.full"
status=1; exit
fi
echo "done"
# success, all done
echo "xfs_fsr tests passed."
status=0 ; exit
|