generic: test MADV_POPULATE_READ with IO errors
[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 # Zoned btrfs does not support space_cache(v1)
22 _require_non_zoned_device "${SCRATCH_DEV}"
23
24 mkfs_v1()
25 {
26         _scratch_mkfs >/dev/null 2>&1
27         # Future proof against btrfs-progs making space_cache=v2 filesystems by
28         # default.
29         _scratch_mount -o clear_cache,space_cache=v1
30         _scratch_unmount
31 }
32
33 mkfs_v2()
34 {
35         _scratch_mkfs >/dev/null 2>&1
36         _scratch_mount -o space_cache=v2
37         _scratch_unmount
38 }
39
40 check_fst_compat()
41 {
42         compat_ro="$($BTRFS_UTIL_PROG inspect-internal dump-super "$SCRATCH_DEV" | \
43                      sed -rn 's/^compat_ro_flags\s+(.*)$/\1/p')"
44         if ((compat_ro & 0x1)); then
45                 echo "free space tree is enabled"
46         else
47                 echo "free space tree is disabled"
48         fi
49 }
50
51 # Mount options might interfere.
52 export MOUNT_OPTIONS=""
53
54 # When the free space tree is not enabled:
55 # -o space_cache=v1: keep using the old free space cache
56 # -o space_cache=v2: enable the free space tree
57 # -o clear_cache,space_cache=v2: clear the free space cache and enable the free space tree
58 # We don't check the no options case or plain space_cache as that will change
59 # in the future to turn on space_cache=v2.
60
61 mkfs_v1
62 echo "Using free space cache"
63 _scratch_mount -o space_cache=v1
64 check_fst_compat
65 _scratch_unmount
66
67 mkfs_v1
68 echo "Enabling free space tree"
69 _scratch_mount -o space_cache=v2
70 check_fst_compat
71 _scratch_unmount
72
73 mkfs_v1
74 echo "Disabling free space cache and enabling free space tree"
75 _scratch_mount -o clear_cache,space_cache=v2
76 check_fst_compat
77 _scratch_unmount
78
79 # When the free space tree is enabled:
80 # -o nospace_cache, -o space_cache=v1: error
81 # no options, -o space_cache=v2: keep using the free space tree
82 # -o clear_cache, -o clear_cache,space_cache=v2: clear and recreate the free space tree
83 # -o clear_cache,nospace_cache: clear the free space tree
84 # -o clear_cache,space_cache=v1: clear the free space tree, enable the free space cache
85
86 mkfs_v2
87 echo "Trying to mount without free space tree"
88 _try_scratch_mount -o nospace_cache >/dev/null 2>&1 || echo "mount failed"
89 _try_scratch_mount -o space_cache=v1 >/dev/null 2>&1 || echo "mount failed"
90
91 mkfs_v2
92 echo "Mounting existing free space tree"
93 _scratch_mount
94 check_fst_compat
95 _scratch_unmount
96 _scratch_mount -o space_cache=v2
97 check_fst_compat
98 _scratch_unmount
99
100 mkfs_v2
101 echo "Recreating free space tree"
102 _scratch_mount -o clear_cache,space_cache=v2
103 check_fst_compat
104 _scratch_unmount
105 mkfs_v2
106 _scratch_mount -o clear_cache
107 check_fst_compat
108 _scratch_unmount
109
110 mkfs_v2
111 echo "Disabling free space tree"
112 _scratch_mount -o clear_cache,nospace_cache
113 check_fst_compat
114 _scratch_unmount
115
116 mkfs_v2
117 echo "Reverting to free space cache"
118 _scratch_mount -o clear_cache,space_cache=v1
119 check_fst_compat
120 _scratch_unmount
121
122 # success, all done
123 status=0
124 exit