generic: _require_dm_target() helper
[xfstests-dev.git] / tests / generic / 322
1 #! /bin/bash
2 # FS QA Test No. 322
3 #
4 # Runs various rename fsync tests to cover some rename fsync corner cases.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2013 Fusion IO. All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 status=1        # failure is the default!
30
31 _cleanup()
32 {
33         _cleanup_flakey
34 }
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40 . ./common/dmflakey
41
42 # real QA test starts here
43 _supported_fs generic
44 _supported_os Linux
45 _need_to_be_root
46 _require_scratch_nocheck
47 _require_dm_target flakey
48 _require_metadata_journaling $SCRATCH_DEV
49
50 rm -f $seqres.full
51
52 _clean_working_dir()
53 {
54         _mount_flakey
55         rm -rf $SCRATCH_MNT/foo $SCRATCH_MNT/bar
56         _unmount_flakey
57 }
58
59 # Btrfs wasn't making sure the new file after rename survived the fsync
60 _rename_test()
61 {
62         echo "fsync rename test"
63         _mount_flakey
64         $XFS_IO_PROG -f -c "pwrite 0 1M" -c "fsync" $SCRATCH_MNT/foo \
65                 > $seqres.full 2>&1 || _fail "xfs_io failed"
66         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
67         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
68         _load_flakey_table $FLAKEY_DROP_WRITES
69         md5sum $SCRATCH_MNT/bar | _filter_scratch
70         _unmount_flakey
71
72         _load_flakey_table $FLAKEY_ALLOW_WRITES
73         _mount_flakey
74         md5sum $SCRATCH_MNT/bar | _filter_scratch
75         _unmount_flakey
76         _check_scratch_fs $FLAKEY_DEV
77         [ $? -ne 0 ] && _fatal "fsck failed"
78 }
79
80 # Btrfs was dropping some of the modified extents in between fsyncs if we
81 # renamed.
82 _write_after_fsync_rename_test()
83 {
84         echo "fsync rename test"
85         _mount_flakey
86         $XFS_IO_PROG -f -c "pwrite 0 1M" -c "fsync" -c "pwrite 2M 1M" \
87                 -c "sync_range -b" $SCRATCH_MNT/foo > $seqres.full 2>&1 || _fail "xfs_io failed"
88         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
89         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
90         _load_flakey_table $FLAKEY_DROP_WRITES
91         md5sum $SCRATCH_MNT/bar | _filter_scratch
92         _unmount_flakey
93
94         _load_flakey_table $FLAKEY_ALLOW_WRITES
95         _mount_flakey
96         md5sum $SCRATCH_MNT/bar | _filter_scratch
97         _unmount_flakey
98 }
99
100 _scratch_mkfs >> $seqres.full 2>&1
101
102 # Create a basic flakey device that will never error out
103 _init_flakey
104
105 _rename_test
106 _clean_working_dir
107 _write_after_fsync_rename_test
108
109 status=0
110 exit