misc: move exit status into trap handler
[xfstests-dev.git] / tests / xfs / 118
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat, inc.  All Rights Reserved.
4 #
5 # FS QA Test 118
6 #
7 # Test xfs_fsr's handling of 2-extent files with preallocation
8 #
9 # An error in xfs_swap_extent_forks() incorrectly set up the
10 # temporary inode's if_extents pointer to inline, leading to
11 # in-memory corruption when the temporary inode was released
12 # and torn down; i_itemp and d_ops got overwritten with zeros,
13 # which led to an oops in xfs_trans_log_inode down the fput path.
14 #
15 # Fixed upstream by proper nextents counting using
16 # ip->i_df.if_bytes not ip->i_d.di_nextents in xfs_swap_extent_forks
17 #
18 seq=`basename $0`
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
21
22 here=`pwd`
23 tmp=/tmp/$$
24 status=1        # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
26
27 _cleanup()
28 {
29         cd /
30         rm -f $tmp.*
31 }
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36
37 # remove previous $seqres.full before test
38 rm -f $seqres.full
39
40 _supported_fs xfs
41
42 _require_scratch
43 _require_command "$XFS_FSR_PROG" "xfs_fsr"
44 _require_xfs_io_command "falloc"
45
46 # 50M
47 _scratch_mkfs_sized $((50 * 1024 * 1024)) >> $seqres.full 2>&1
48 _scratch_mount
49
50 echo "Silence is golden"
51
52 # Fragment freespace
53 # The aim is to create a fragmented two-extent file *with* prealloc
54 # so make the free holes big enough that a 2-extent file will have
55 # preallocation added.  Let's say... 64k free chunks.
56
57 $XFS_IO_PROG -fs -c "falloc 0 40000k" $SCRATCH_MNT/fill >> $seqres.full 2>&1
58 sync
59
60 dd if=/dev/zero of=$SCRATCH_MNT/remainder oflag=direct > /dev/null 2>&1
61
62 # Free up a bunch of 64k chunks
63 for i in `seq 0 68 40000`; do
64         $XFS_IO_PROG -fs -c "unresvsp ${i}k 64k" $SCRATCH_MNT/fill
65 done
66
67 # Create 2-extent files w/ preallocation (via extending writes)
68 for I in `seq 1 64`; do
69         $XFS_IO_PROG -f -c "pwrite 0 64k" $SCRATCH_MNT/newfile-$I \
70                                                  >> $seqres.full 2>&1
71         $XFS_IO_PROG -f -c "pwrite 64k 64k" $SCRATCH_MNT/newfile-$I \
72                                                 >> $seqres.full 2>&1
73 done
74 # sync to get extents on disk so fsr sees them
75 sync
76
77 # Free up some space for defragmentation temp file
78 rm -f $SCRATCH_MNT/fill
79
80 $XFS_FSR_PROG -vd $SCRATCH_MNT/newfile* >> $seqres.full 2>&1
81
82 # success, all done
83 status=0
84 exit