btrfs/079: fix failure to umount scratch fs due to running filefrag process
[xfstests-dev.git] / tests / btrfs / 173
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 173
6 #
7 # Test swap file activation restrictions specific to Btrfs, swap file can't be
8 # CoW file nor compressed file.
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 echo "COW file"
38 # We can't use _format_swapfile because we don't want chattr +C, and we can't
39 # unset it after the swap file has been created.
40 rm -f "$SCRATCH_MNT/swap"
41 touch "$SCRATCH_MNT/swap"
42 chmod 0600 "$SCRATCH_MNT/swap"
43 _pwrite_byte 0x61 0 $(($(get_page_size) * 10)) "$SCRATCH_MNT/swap" >> $seqres.full
44 $MKSWAP_PROG "$SCRATCH_MNT/swap" >> $seqres.full
45 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
46 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
47
48 echo "Compressed file"
49 rm -f "$SCRATCH_MNT/swap"
50 _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
51 $CHATTR_PROG +c "$SCRATCH_MNT/swap"
52 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
53 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
54
55 status=0
56 exit