8bf856ae9e8d28a0eb00668537dbb93e5e1b1501
[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 . ./common/preamble
11 _begin_fstest auto quick swap
12
13 . ./common/filter
14
15 _supported_fs btrfs
16 _require_scratch_swapfile
17
18 _scratch_mkfs >> $seqres.full 2>&1
19 _scratch_mount
20
21 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/swapvol" >> $seqres.full
22 swapfile="$SCRATCH_MNT/swapvol/swap"
23 _format_swapfile "$swapfile" $(($(get_page_size) * 10))
24 swapon "$swapfile"
25
26 # Turning off nocow doesn't do anything because the file is not empty, not
27 # because the file is a swap file, but make sure this works anyways.
28 echo "Disable nocow"
29 $CHATTR_PROG -C "$swapfile"
30 $LSATTR_PROG -l "$swapfile" | _filter_scratch | _filter_spaces
31
32 # Compression we reject outright.
33 echo "Enable compression"
34 $CHATTR_PROG +c "$swapfile" 2>&1 | grep -o "Invalid argument while setting flags"
35 $LSATTR_PROG -l "$swapfile" | _filter_scratch | _filter_spaces
36
37 echo "Snapshot"
38 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/swapvol" \
39         "$SCRATCH_MNT/swapsnap" 2>&1 | grep -o "Text file busy"
40
41 echo "Defrag"
42 # We pass the -c (compress) flag to force defrag even if the file isn't
43 # fragmented.
44 $BTRFS_UTIL_PROG filesystem defrag -c "$swapfile" 2>&1 | grep -o "Text file busy"
45
46 swapoff "$swapfile"
47 _scratch_unmount
48
49 status=0
50 exit