summaryrefslogtreecommitdiff
path: root/tests/btrfs/285
blob: 56cdad51334a757bd31f93a20db5a98d836d2c6c (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2023 Meta Platforms, Inc.  All Rights Reserved.
#
# FS QA Test No. 285
#
# Test that mounting a btrfs filesystem properly loads block group size classes.
#
. ./common/preamble
_begin_fstest auto quick

sysfs_size_classes() {
	local uuid="$(findmnt -n -o UUID "$SCRATCH_MNT")"
	cat "/sys/fs/btrfs/$uuid/allocation/data/size_classes"
}

_supported_fs btrfs
_require_scratch
_require_btrfs_fs_sysfs
_require_fs_sysfs allocation/data/size_classes

f="$SCRATCH_MNT/f"
small=$((16 * 1024))
medium=$((1024 * 1024))
large=$((16 * 1024 * 1024))

_scratch_mkfs >/dev/null
_scratch_mount
# Write files with extents in each size class
$XFS_IO_PROG -fc "pwrite -q 0 $small" $f.small
$XFS_IO_PROG -fc "pwrite -q 0 $medium" $f.medium
$XFS_IO_PROG -fc "pwrite -q 0 $large" $f.large
# Sync to force the extent allocation
sync
pre=$(sysfs_size_classes)

# cycle mount to drop the block group cache
_scratch_cycle_mount

# Another write causes us to actually load the block groups
$XFS_IO_PROG -fc "pwrite -q 0 $large" $f.large.2
sync

post=$(sysfs_size_classes)
diff <(echo $pre) <(echo $post)

echo "Silence is golden"
# success, all done
status=0
exit