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