misc: move exit status into trap handler
[xfstests-dev.git] / tests / xfs / 329
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 329
6 #
7 # Ensure that xfs_fsr handles errors correctly while defragging files.
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 -rf "$tmp".*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28 . ./common/reflink
29 . ./common/inject
30
31 # real QA test starts here
32 _supported_fs xfs
33 _require_scratch_reflink
34 _require_cp_reflink
35 _require_command "$XFS_FSR_PROG" "xfs_fsr"
36 _require_xfs_io_error_injection "bmap_finish_one"
37 _require_xfs_scratch_rmapbt
38
39 rm -f "$seqres.full"
40
41 echo "Format and mount"
42 _scratch_mkfs > "$seqres.full" 2>&1
43 _scratch_mount >> "$seqres.full" 2>&1
44
45 testdir="$SCRATCH_MNT/test-$seq"
46 blksz=65536
47 blks=3
48 mkdir "$testdir"
49
50 echo "Create a many-block file"
51 _pwrite_byte 0x62 0 $((blksz * blks)) $testdir/file1 >> $seqres.full
52 _pwrite_byte 0x63 0 $blksz $testdir/file2 >> $seqres.full
53 _reflink_range $testdir/file2 0 $testdir/file1 $blksz $blksz >> $seqres.full
54 _scratch_cycle_mount
55 $XFS_IO_PROG -c 'bmap -v' $testdir/file1 >> $seqres.full
56
57 echo "Inject error"
58 _scratch_inject_error "bmap_finish_one"
59
60 echo "Defrag the file"
61 old_nextents=$(_count_extents $testdir/file1)
62 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full 2>&1
63
64 echo "FS should be shut down, touch will fail"
65 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
66
67 echo "Remount to replay log" | tee /dev/ttyprintk
68 _scratch_inject_logprint >> $seqres.full
69 new_nextents=$(_count_extents $testdir/file1)
70
71 echo "Check extent count" | tee /dev/ttyprintk
72 $XFS_IO_PROG -c 'stat -v' $testdir/file1 >> $seqres.full
73 $XFS_IO_PROG -c 'stat -v' $testdir/file2 >> $seqres.full
74 echo "extents: $old_nextents -> $new_nextents" >> $seqres.full
75
76 echo "FS should be online, touch should succeed"
77 touch $SCRATCH_MNT/goodfs
78 $XFS_IO_PROG -c 'bmap -v' $testdir/file1 >> $seqres.full
79
80 # success, all done
81 status=0
82 exit