summaryrefslogtreecommitdiff
path: root/tests/btrfs/131
blob: ef8f4918816ec1c345157c700ea1dfbc6cd04114 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2016 Facebook.  All Rights Reserved.
#
# FS QA Test 131
#
# Test free space tree mount options.
#
. ./common/preamble
_begin_fstest auto quick

. ./common/filter

_supported_fs btrfs
_require_scratch
_require_btrfs_command inspect-internal dump-super
_require_btrfs_fs_feature free_space_tree
# Zoned btrfs does not support space_cache(v1)
_require_non_zoned_device "${SCRATCH_DEV}"
# Block group tree does not support space_cache(v1)
_require_btrfs_no_block_group_tree

_scratch_mkfs >/dev/null 2>&1
[ "$(_get_page_size)" -gt "$(_scratch_btrfs_sectorsize)" ] && \
	_notrun "cannot run with subpage sectorsize"

mkfs_v1()
{
	_scratch_mkfs >/dev/null 2>&1
	# Future proof against btrfs-progs making space_cache=v2 filesystems by
	# default.
	_scratch_mount -o clear_cache,space_cache=v1
	_scratch_unmount
}

mkfs_v2()
{
	_scratch_mkfs >/dev/null 2>&1
	_scratch_mount -o space_cache=v2
	_scratch_unmount
}

check_fst_compat()
{
	compat_ro="$($BTRFS_UTIL_PROG inspect-internal dump-super "$SCRATCH_DEV" | \
		     sed -rn 's/^compat_ro_flags\s+(.*)$/\1/p')"
	if ((compat_ro & 0x1)); then
		echo "free space tree is enabled"
	else
		echo "free space tree is disabled"
	fi
}

# Mount options might interfere.
export MOUNT_OPTIONS=""

# When the free space tree is not enabled:
# -o space_cache=v1: keep using the old free space cache
# -o space_cache=v2: enable the free space tree
# -o clear_cache,space_cache=v2: clear the free space cache and enable the free space tree
# We don't check the no options case or plain space_cache as that will change
# in the future to turn on space_cache=v2.

mkfs_v1
echo "Using free space cache"
_scratch_mount -o space_cache=v1
check_fst_compat
_scratch_unmount

mkfs_v1
echo "Enabling free space tree"
_scratch_mount -o space_cache=v2
check_fst_compat
_scratch_unmount

mkfs_v1
echo "Disabling free space cache and enabling free space tree"
_scratch_mount -o clear_cache,space_cache=v2
check_fst_compat
_scratch_unmount

# When the free space tree is enabled:
# -o nospace_cache, -o space_cache=v1: error
# no options, -o space_cache=v2: keep using the free space tree
# -o clear_cache, -o clear_cache,space_cache=v2: clear and recreate the free space tree
# -o clear_cache,nospace_cache: clear the free space tree
# -o clear_cache,space_cache=v1: clear the free space tree, enable the free space cache

mkfs_v2
echo "Trying to mount without free space tree"
_try_scratch_mount -o nospace_cache >/dev/null 2>&1 || echo "mount failed"
_try_scratch_mount -o space_cache=v1 >/dev/null 2>&1 || echo "mount failed"

mkfs_v2
echo "Mounting existing free space tree"
_scratch_mount
check_fst_compat
_scratch_unmount
_scratch_mount -o space_cache=v2
check_fst_compat
_scratch_unmount

mkfs_v2
echo "Recreating free space tree"
_scratch_mount -o clear_cache,space_cache=v2
check_fst_compat
_scratch_unmount
mkfs_v2
_scratch_mount -o clear_cache
check_fst_compat
_scratch_unmount

mkfs_v2
echo "Disabling free space tree"
_scratch_mount -o clear_cache,nospace_cache
check_fst_compat
_scratch_unmount

mkfs_v2
echo "Reverting to free space cache"
_scratch_mount -o clear_cache,space_cache=v1
check_fst_compat
_scratch_unmount

# success, all done
status=0
exit