blob: 7b4c043f11950956ce5164bad949867265082d5d (
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
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test 257
#
# Make sure btrfs doesn't defrag preallocated extents, nor lone extents
# before preallocated extents.
#
. ./common/preamble
_begin_fstest auto quick defrag prealloc fiemap
# Override the default cleanup function.
# _cleanup()
# {
# cd /
# rm -r -f $tmp.*
# }
. ./common/filter
_supported_fs btrfs
_require_scratch
# We rely on specific extent layout, don't run on compress
_require_btrfs_no_compress
# Needs 4K sectorsize
_require_btrfs_support_sectorsize 4096
_require_xfs_io_command "falloc"
_require_xfs_io_command "fiemap"
_scratch_mkfs -s 4k >> $seqres.full 2>&1
# Need datacow to make the defragged extents to have different bytenr
_scratch_mount -o datacow
# Create a file with the following layout:
# 0 4K 8K 16K
# |<- R ->|<-- Preallocated ->|
# R is regular extents.
#
# In this case it makes no sense to defrag any extent.
$XFS_IO_PROG -f -c "pwrite 0 4k" -c sync -c "falloc 4k 12k" \
"$SCRATCH_MNT/foobar" >> $seqres.full
echo "=== Initial file extent layout ===" >> $seqres.full
$XFS_IO_PROG -c "fiemap -v" "$SCRATCH_MNT/foobar" >> $seqres.full
# Save the bytenr of both extents
old_regular=$(_get_file_extent_sector "$SCRATCH_MNT/foobar" 0)
old_prealloc=$(_get_file_extent_sector "$SCRATCH_MNT/foobar" 4096)
# Now defrag and write the defragged range back to disk
$BTRFS_UTIL_PROG filesystem defrag "$SCRATCH_MNT/foobar" >> $seqres.full
sync
echo "=== File extent layout after defrag ===" >> $seqres.full
$XFS_IO_PROG -c "fiemap -v" "$SCRATCH_MNT/foobar" >> $seqres.full
new_regular=$(_get_file_extent_sector "$SCRATCH_MNT/foobar" 0)
new_prealloc=$(_get_file_extent_sector "$SCRATCH_MNT/foobar" 4096)
if [ "$old_regular" -ne "$new_regular" ]; then
echo "the single lone sector got defragged"
fi
if [ "$old_prealloc" -ne "$new_prealloc" ]; then
echo "the preallocated extent got defragged"
fi
echo "Silence is golden"
# success, all done
status=0
exit
|