generic: _require_dm_target() helper
[xfstests-dev.git] / tests / generic / 321
1 #! /bin/bash
2 # FS QA Test No. 321
3 #
4 # Runs various dir fsync tests to cover fsync'ing directory 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 directory survived fsync
60 _directory_test()
61 {
62         echo "fsync new directory"
63         _mount_flakey
64         mkdir $SCRATCH_MNT/bar
65         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
66         _load_flakey_table $FLAKEY_DROP_WRITES
67         _unmount_flakey
68
69         _load_flakey_table $FLAKEY_ALLOW_WRITES
70         _mount_flakey
71         _ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
72         _unmount_flakey
73         _check_scratch_fs $FLAKEY_DEV
74         [ $? -ne 0 ] && _fatal "fsck failed"
75 }
76
77 # Btrfs was losing a rename into a new directory
78 _rename_test()
79 {
80         echo "rename fsync test"
81         _mount_flakey
82         touch $SCRATCH_MNT/foo
83         mkdir $SCRATCH_MNT/bar
84         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
85         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
86         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
87         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
88         _load_flakey_table $FLAKEY_DROP_WRITES
89         _unmount_flakey
90
91         _load_flakey_table $FLAKEY_ALLOW_WRITES
92         _mount_flakey
93         _ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
94         _ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
95         _unmount_flakey
96         _check_scratch_fs $FLAKEY_DEV
97         [ $? -ne 0 ] && _fatal "fsck failed"
98 }
99
100 # Btrfs was failing to replay a log when we had a inode with a smaller inode
101 # number that is renamed into a directory with a higher inode number
102 _replay_rename_test()
103 {
104         echo "replay rename fsync test"
105         _mount_flakey
106         touch $SCRATCH_MNT/foo
107         mkdir $SCRATCH_MNT/bar
108         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
109         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
110         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
111
112         # This is to force btrfs to relog the entire inode including the ref so
113         # we are sure to try and replay the ref along with the dir_index item
114         setfattr -n user.foo -v blah $SCRATCH_MNT/bar/foo >> $seqres.full 2>&1
115
116         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
117         _load_flakey_table $FLAKEY_DROP_WRITES
118         _unmount_flakey
119
120         _load_flakey_table $FLAKEY_ALLOW_WRITES
121         _mount_flakey
122         _ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
123         _ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
124         _unmount_flakey
125 }
126
127 _scratch_mkfs >> $seqres.full 2>&1
128
129 # Create a basic flakey device that will never error out
130 _init_flakey
131
132 _directory_test
133 _clean_working_dir
134 _rename_test
135 _clean_working_dir
136 _replay_rename_test
137
138 status=0
139 exit