misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 356
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 356
6 #
7 # Check that we can't reflink a 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 7 15
17
18 _cleanup()
19 {
20         cd /
21         rm -rf $tmp.*
22         wait
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/reflink
29
30 # real QA test starts here
31 _require_scratch_swapfile
32 _require_scratch_reflink
33 _require_cp_reflink
34
35 echo "Format and mount"
36 _scratch_mkfs > $seqres.full 2>&1
37 _scratch_mount >> $seqres.full 2>&1
38
39 testdir=$SCRATCH_MNT/test-$seq
40 mkdir $testdir
41
42 blocks=160
43 blksz=65536
44
45 echo "Initialize file"
46 _format_swapfile "$testdir/file1" $((blocks * blksz))
47 swapon $testdir/file1
48
49 touch "$testdir/file2"
50 $CHATTR_PROG +C "$testdir/file2" >/dev/null 2>&1
51
52 echo "Try to reflink"
53 _cp_reflink $testdir/file1 $testdir/file2 2>&1 | _filter_scratch
54
55 echo "Tear it down"
56 swapoff $testdir/file1
57
58 # success, all done
59 status=0
60 exit