misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 322
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Fusion IO. All Rights Reserved.
4 #
5 # FS QA Test No. 322
6 #
7 # Runs various rename fsync tests to cover some rename fsync corner cases.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 status=1        # failure is the default!
15
16 _cleanup()
17 {
18         _cleanup_flakey
19 }
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 # get standard environment, filters and checks
23 . ./common/rc
24 . ./common/filter
25 . ./common/dmflakey
26
27 # real QA test starts here
28 _supported_fs generic
29 _require_scratch_nocheck
30 _require_dm_target flakey
31
32 rm -f $seqres.full
33
34 _clean_working_dir()
35 {
36         _mount_flakey
37         rm -rf $SCRATCH_MNT/foo $SCRATCH_MNT/bar
38         _unmount_flakey
39 }
40
41 # Btrfs wasn't making sure the new file after rename survived the fsync
42 _rename_test()
43 {
44         echo "fsync rename test"
45         _mount_flakey
46         $XFS_IO_PROG -f -c "pwrite 0 1M" -c "fsync" $SCRATCH_MNT/foo \
47                 >> $seqres.full 2>&1
48         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
49         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
50         md5sum $SCRATCH_MNT/bar | _filter_scratch
51
52         _flakey_drop_and_remount
53
54         md5sum $SCRATCH_MNT/bar | _filter_scratch
55         _unmount_flakey
56         _check_scratch_fs $FLAKEY_DEV
57         [ $? -ne 0 ] && _fatal "fsck failed"
58 }
59
60 # Btrfs was dropping some of the modified extents in between fsyncs if we
61 # renamed.
62 _write_after_fsync_rename_test()
63 {
64         echo "fsync rename test"
65         _mount_flakey
66         $XFS_IO_PROG -f -c "pwrite 0 1M" -c "fsync" -c "pwrite 2M 1M" \
67                 -c "sync_range -b 2M 1M" $SCRATCH_MNT/foo >> $seqres.full 2>&1
68         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
69         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
70         md5sum $SCRATCH_MNT/bar | _filter_scratch
71
72         _flakey_drop_and_remount
73
74         md5sum $SCRATCH_MNT/bar | _filter_scratch
75         _unmount_flakey
76 }
77
78 _scratch_mkfs >> $seqres.full 2>&1
79 _require_metadata_journaling $SCRATCH_DEV
80
81 # Create a basic flakey device that will never error out
82 _init_flakey
83
84 _rename_test
85 _clean_working_dir
86 _write_after_fsync_rename_test
87
88 status=0
89 exit