common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / btrfs / 174
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 174
6 #
7 # Test restrictions on operations that can be done on an active swap file
8 # specific to Btrfs.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 . ./common/rc
26 . ./common/filter
27
28 rm -f $seqres.full
29
30 _supported_fs btrfs
31 _supported_os Linux
32 _require_scratch_swapfile
33
34 _scratch_mkfs >> $seqres.full 2>&1
35 _scratch_mount
36
37 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/swapvol" >> $seqres.full
38 swapfile="$SCRATCH_MNT/swapvol/swap"
39 _format_swapfile "$swapfile" $(($(get_page_size) * 10))
40 swapon "$swapfile"
41
42 # Turning off nocow doesn't do anything because the file is not empty, not
43 # because the file is a swap file, but make sure this works anyways.
44 echo "Disable nocow"
45 $CHATTR_PROG -C "$swapfile"
46 $LSATTR_PROG -l "$swapfile" | _filter_scratch | _filter_spaces
47
48 # Compression we reject outright.
49 echo "Enable compression"
50 $CHATTR_PROG +c "$swapfile" 2>&1 | grep -o "Text file busy"
51 $LSATTR_PROG -l "$swapfile" | _filter_scratch | _filter_spaces
52
53 echo "Snapshot"
54 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/swapvol" \
55         "$SCRATCH_MNT/swapsnap" 2>&1 | grep -o "Text file busy"
56
57 echo "Defrag"
58 # We pass the -c (compress) flag to force defrag even if the file isn't
59 # fragmented.
60 $BTRFS_UTIL_PROG filesystem defrag -c "$swapfile" 2>&1 | grep -o "Text file busy"
61
62 swapoff "$swapfile"
63 _scratch_unmount
64
65 status=0
66 exit