btrfs/079: fix failure to umount scratch fs due to running filefrag process
[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 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # remove previous $seqres.full before test
29 rm -f $seqres.full
30
31 # real QA test starts here
32
33 _supported_fs btrfs
34 _supported_os Linux
35 _require_scratch
36 _require_btrfs_command inspect-internal dump-super
37 _require_btrfs_fs_feature free_space_tree
38
39 mkfs_v1()
40 {
41         _scratch_mkfs >/dev/null 2>&1
42         # Future proof against btrfs-progs making space_cache=v2 filesystems by
43         # default.
44         _scratch_mount -o clear_cache,space_cache=v1
45         _scratch_unmount
46 }
47
48 mkfs_v2()
49 {
50         _scratch_mkfs >/dev/null 2>&1
51         _scratch_mount -o space_cache=v2
52         _scratch_unmount
53 }
54
55 check_fst_compat()
56 {
57         compat_ro="$($BTRFS_UTIL_PROG inspect-internal dump-super "$SCRATCH_DEV" | \
58                      sed -rn 's/^compat_ro_flags\s+(.*)$/\1/p')"
59         if ((compat_ro & 0x1)); then
60                 echo "free space tree is enabled"
61         else
62                 echo "free space tree is disabled"
63         fi
64 }
65
66 # Mount options might interfere.
67 export MOUNT_OPTIONS=""
68
69 # When the free space tree is not enabled:
70 # -o space_cache=v1: keep using the old free space cache
71 # -o space_cache=v2: enable the free space tree
72 # -o clear_cache,space_cache=v2: clear the free space cache and enable the free space tree
73 # We don't check the no options case or plain space_cache as that will change
74 # in the future to turn on space_cache=v2.
75
76 mkfs_v1
77 echo "Using free space cache"
78 _scratch_mount -o space_cache=v1
79 check_fst_compat
80 _scratch_unmount
81
82 mkfs_v1
83 echo "Enabling free space tree"
84 _scratch_mount -o space_cache=v2
85 check_fst_compat
86 _scratch_unmount
87
88 mkfs_v1
89 echo "Disabling free space cache and enabling free space tree"
90 _scratch_mount -o clear_cache,space_cache=v2
91 check_fst_compat
92 _scratch_unmount
93
94 # When the free space tree is enabled:
95 # -o nospace_cache, -o space_cache=v1: error
96 # no options, -o space_cache=v2: keep using the free space tree
97 # -o clear_cache, -o clear_cache,space_cache=v2: clear and recreate the free space tree
98 # -o clear_cache,nospace_cache: clear the free space tree
99 # -o clear_cache,space_cache=v1: clear the free space tree, enable the free space cache
100
101 mkfs_v2
102 echo "Trying to mount without free space tree"
103 _try_scratch_mount -o nospace_cache >/dev/null 2>&1 || echo "mount failed"
104 _try_scratch_mount -o space_cache=v1 >/dev/null 2>&1 || echo "mount failed"
105
106 mkfs_v2
107 echo "Mounting existing free space tree"
108 _scratch_mount
109 check_fst_compat
110 _scratch_unmount
111 _scratch_mount -o space_cache=v2
112 check_fst_compat
113 _scratch_unmount
114
115 mkfs_v2
116 echo "Recreating free space tree"
117 _scratch_mount -o clear_cache,space_cache=v2
118 check_fst_compat
119 _scratch_unmount
120 mkfs_v2
121 _scratch_mount -o clear_cache
122 check_fst_compat
123 _scratch_unmount
124
125 mkfs_v2
126 echo "Disabling free space tree"
127 _scratch_mount -o clear_cache,nospace_cache
128 check_fst_compat
129 _scratch_unmount
130
131 mkfs_v2
132 echo "Reverting to free space cache"
133 _scratch_mount -o clear_cache,space_cache=v1
134 check_fst_compat
135 _scratch_unmount
136
137 # success, all done
138 status=0
139 exit