fstests: move test group info to test files
[xfstests-dev.git] / tests / btrfs / 131
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 131
6 #
7 # Test free space tree mount options.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick
11
12 # Import common functions.
13 . ./common/filter
14
15 # real QA test starts here
16
17 _supported_fs btrfs
18 _require_scratch
19 _require_btrfs_command inspect-internal dump-super
20 _require_btrfs_fs_feature free_space_tree
21
22 mkfs_v1()
23 {
24         _scratch_mkfs >/dev/null 2>&1
25         # Future proof against btrfs-progs making space_cache=v2 filesystems by
26         # default.
27         _scratch_mount -o clear_cache,space_cache=v1
28         _scratch_unmount
29 }
30
31 mkfs_v2()
32 {
33         _scratch_mkfs >/dev/null 2>&1
34         _scratch_mount -o space_cache=v2
35         _scratch_unmount
36 }
37
38 check_fst_compat()
39 {
40         compat_ro="$($BTRFS_UTIL_PROG inspect-internal dump-super "$SCRATCH_DEV" | \
41                      sed -rn 's/^compat_ro_flags\s+(.*)$/\1/p')"
42         if ((compat_ro & 0x1)); then
43                 echo "free space tree is enabled"
44         else
45                 echo "free space tree is disabled"
46         fi
47 }
48
49 # Mount options might interfere.
50 export MOUNT_OPTIONS=""
51
52 # When the free space tree is not enabled:
53 # -o space_cache=v1: keep using the old free space cache
54 # -o space_cache=v2: enable the free space tree
55 # -o clear_cache,space_cache=v2: clear the free space cache and enable the free space tree
56 # We don't check the no options case or plain space_cache as that will change
57 # in the future to turn on space_cache=v2.
58
59 mkfs_v1
60 echo "Using free space cache"
61 _scratch_mount -o space_cache=v1
62 check_fst_compat
63 _scratch_unmount
64
65 mkfs_v1
66 echo "Enabling free space tree"
67 _scratch_mount -o space_cache=v2
68 check_fst_compat
69 _scratch_unmount
70
71 mkfs_v1
72 echo "Disabling free space cache and enabling free space tree"
73 _scratch_mount -o clear_cache,space_cache=v2
74 check_fst_compat
75 _scratch_unmount
76
77 # When the free space tree is enabled:
78 # -o nospace_cache, -o space_cache=v1: error
79 # no options, -o space_cache=v2: keep using the free space tree
80 # -o clear_cache, -o clear_cache,space_cache=v2: clear and recreate the free space tree
81 # -o clear_cache,nospace_cache: clear the free space tree
82 # -o clear_cache,space_cache=v1: clear the free space tree, enable the free space cache
83
84 mkfs_v2
85 echo "Trying to mount without free space tree"
86 _try_scratch_mount -o nospace_cache >/dev/null 2>&1 || echo "mount failed"
87 _try_scratch_mount -o space_cache=v1 >/dev/null 2>&1 || echo "mount failed"
88
89 mkfs_v2
90 echo "Mounting existing free space tree"
91 _scratch_mount
92 check_fst_compat
93 _scratch_unmount
94 _scratch_mount -o space_cache=v2
95 check_fst_compat
96 _scratch_unmount
97
98 mkfs_v2
99 echo "Recreating free space tree"
100 _scratch_mount -o clear_cache,space_cache=v2
101 check_fst_compat
102 _scratch_unmount
103 mkfs_v2
104 _scratch_mount -o clear_cache
105 check_fst_compat
106 _scratch_unmount
107
108 mkfs_v2
109 echo "Disabling free space tree"
110 _scratch_mount -o clear_cache,nospace_cache
111 check_fst_compat
112 _scratch_unmount
113
114 mkfs_v2
115 echo "Reverting to free space cache"
116 _scratch_mount -o clear_cache,space_cache=v1
117 check_fst_compat
118 _scratch_unmount
119
120 # success, all done
121 status=0
122 exit