misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 086
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat, Inc., Lukas Czerner <lczerner@redhat.com>
4 #
5 # FS QA Test 086
6 #
7 # This test excercises the problem with unwritten and delayed extents
8 # in ext4 extent status tree where we might in some cases lose a block
9 # worth of data. Even though this was a ext4 specific problem the
10 # reproducer can be easily tun on any file system so let's do that just
11 # in case.
12 #
13 # This tests excercises the problem fixed in kernel with commit
14 # "ext4: Fix data corruption caused by unwritten and delayed extents"
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27         cd /
28         rm -f $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34
35 # real QA test starts here
36
37 # Modify as appropriate.
38 _supported_fs generic
39 _require_test
40 _require_xfs_io_command "falloc"
41
42 test_file=${TEST_DIR}/testfile-$seq
43
44 rm -f $test_file
45
46 # The first write creates a delayed extent, fallocate creates
47 # unwritten extent which will be marked as delayed in ext4
48 # extent status tree. Second write will convert unwritten/delayed
49 # block into written/delayed.
50 $XFS_IO_PROG -f -c "pwrite -S 0xaa 4096 2048" \
51                 -c "falloc 0 131072" \
52                 -c "pwrite -S 0xbb 65536 2048" \
53                 -c "fsync"  $test_file > $seqres.full 2>&1
54
55 # Drop the caches to evict dirty buffers from memory
56 echo 3 > /proc/sys/vm/drop_caches
57
58 # Write into the second part of the block with 0xbb write from before
59 # will create new empty! buffer because the block is still marked as
60 # delayed even though it's already written - resulting in
61 # overwriting previous data.
62 $XFS_IO_PROG -c "pwrite -S 0xdd 67584 2048" $test_file >> $seqres.full 2>&1
63
64 # On a faulty ext4 oxbb data will be missing, overwritten by zeroes.
65 hexdump -C $test_file
66
67 # success, all done
68 status=0
69 exit