generic: convert tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 494
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 494
6 #
7 # Test truncation/hole punching of an active swapfile.
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 . ./common/rc
25 . ./common/filter
26
27 rm -f $seqres.full
28
29 _supported_fs generic
30 _supported_os Linux
31 _require_scratch_swapfile
32 _require_xfs_io_command "fpunch"
33
34 echo "Format and mount"
35 _scratch_mkfs > $seqres.full 2>&1
36 _scratch_mount >> $seqres.full 2>&1
37
38 testdir="$SCRATCH_MNT/test-$seq"
39 mkdir "$testdir"
40
41 blocks=160
42 blksz=65536
43
44 echo "Initialize file"
45 _format_swapfile "$testdir/file1" $((blocks * blksz))
46 swapon "$testdir/file1"
47
48 echo "Try to truncate"
49 $XFS_IO_PROG -c "truncate $blksz" "$testdir/file1"
50
51 echo "Try to punch hole"
52 $XFS_IO_PROG -c "fpunch $blksz $((2 * blksz))" "$testdir/file1"
53
54 echo "Tear it down"
55 swapoff "$testdir/file1"
56
57 status=0
58 exit