misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 512
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 512
6 #
7 # Test that if we have a very small file, with a size smaller than the block
8 # size, then fallocate a very small range within the block size but past the
9 # file's current size, fsync the file and then power fail, after mounting the
10 # filesystem all the file data is there and the file size is correct.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
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         _cleanup_flakey
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/dmflakey
30
31 # real QA test starts here
32 _supported_fs generic
33 _require_scratch
34 _require_xfs_io_command "falloc"
35 _require_dm_target flakey
36
37 rm -f $seqres.full
38
39 _scratch_mkfs >>$seqres.full 2>&1
40 _require_metadata_journaling $SCRATCH_DEV
41 _init_flakey
42 _mount_flakey
43
44 $XFS_IO_PROG -f \
45              -c "pwrite -S 0xb6 0 21" \
46              -c "falloc 40 40" \
47              -c "fsync" \
48              $SCRATCH_MNT/foobar | _filter_xfs_io
49
50 # Simulate a power failure and mount the filesystem. We expect no data loss
51 # and a correct file size.
52 _flakey_drop_and_remount
53
54 echo "File content after power failure:"
55 od -t x1 -A d $SCRATCH_MNT/foobar
56
57 _unmount_flakey
58
59 status=0
60 exit