4 # Test free space tree mount options.
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2016 Facebook. All Rights Reserved.
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #-----------------------------------------------------------------------
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
30 status=1 # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
43 # remove previous $seqres.full before test
46 # real QA test starts here
51 _require_btrfs_command inspect-internal dump-super
55 _scratch_mkfs >/dev/null 2>&1
56 # Future proof against btrfs-progs making space_cache=v2 filesystems by
58 _scratch_mount -o clear_cache,space_cache=v1
64 _scratch_mkfs >/dev/null 2>&1
65 _scratch_mount -o space_cache=v2
71 compat_ro="$($BTRFS_UTIL_PROG inspect-internal dump-super "$SCRATCH_DEV" | \
72 sed -rn 's/^compat_ro_flags\s+(.*)$/\1/p')"
73 if ((compat_ro & 0x1)); then
74 echo "free space tree is enabled"
76 echo "free space tree is disabled"
80 # Mount options might interfere.
81 export MOUNT_OPTIONS=""
83 # When the free space tree is not enabled:
84 # -o space_cache=v1: keep using the old free space cache
85 # -o space_cache=v2: enable the free space tree
86 # -o clear_cache,space_cache=v2: clear the free space cache and enable the free space tree
87 # We don't check the no options case or plain space_cache as that will change
88 # in the future to turn on space_cache=v2.
91 echo "Using free space cache"
92 _scratch_mount -o space_cache=v1
97 echo "Enabling free space tree"
98 _scratch_mount -o space_cache=v2
103 echo "Disabling free space cache and enabling free space tree"
104 _scratch_mount -o clear_cache,space_cache=v2
108 # When the free space tree is enabled:
109 # -o nospace_cache, -o space_cache=v1: error
110 # no options, -o space_cache=v2: keep using the free space tree
111 # -o clear_cache, -o clear_cache,space_cache=v2: clear and recreate the free space tree
112 # -o clear_cache,nospace_cache: clear the free space tree
113 # -o clear_cache,space_cache=v1: clear the free space tree, enable the free space cache
116 echo "Trying to mount without free space tree"
117 _try_scratch_mount -o nospace_cache >/dev/null 2>&1 || echo "mount failed"
118 _try_scratch_mount -o space_cache=v1 >/dev/null 2>&1 || echo "mount failed"
121 echo "Mounting existing free space tree"
125 _scratch_mount -o space_cache=v2
130 echo "Recreating free space tree"
131 _scratch_mount -o clear_cache,space_cache=v2
135 _scratch_mount -o clear_cache
140 echo "Disabling free space tree"
141 _scratch_mount -o clear_cache,nospace_cache
146 echo "Reverting to free space cache"
147 _scratch_mount -o clear_cache,space_cache=v1