generic/077: fall back to /usr if /lib/modules doesn't exist
[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
47 _require_dm_flakey
48
49 rm -f $seqres.full
50
51 _clean_working_dir()
52 {
53         _mount_flakey
54         rm -rf $SCRATCH_MNT/foo $SCRATCH_MNT/bar
55         _unmount_flakey
56 }
57
58 # Btrfs wasn't making sure the directory survived fsync
59 _directory_test()
60 {
61         echo "fsync new directory"
62         _mount_flakey
63         mkdir $SCRATCH_MNT/bar
64         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
65         _load_flakey_table $FLAKEY_DROP_WRITES
66         _unmount_flakey
67
68         _load_flakey_table $FLAKEY_ALLOW_WRITES
69         _mount_flakey
70         _ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
71         _unmount_flakey
72         _check_scratch_fs $FLAKEY_DEV
73         [ $? -ne 0 ] && _fatal "fsck failed"
74 }
75
76 # Btrfs was losing a rename into a new directory
77 _rename_test()
78 {
79         echo "rename fsync test"
80         _mount_flakey
81         touch $SCRATCH_MNT/foo
82         mkdir $SCRATCH_MNT/bar
83         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
84         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
85         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
86         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
87         _load_flakey_table $FLAKEY_DROP_WRITES
88         _unmount_flakey
89
90         _load_flakey_table $FLAKEY_ALLOW_WRITES
91         _mount_flakey
92         _ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
93         _ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
94         _unmount_flakey
95         _check_scratch_fs $FLAKEY_DEV
96         [ $? -ne 0 ] && _fatal "fsck failed"
97 }
98
99 # Btrfs was failing to replay a log when we had a inode with a smaller inode
100 # number that is renamed into a directory with a higher inode number
101 _replay_rename_test()
102 {
103         echo "replay rename fsync test"
104         _mount_flakey
105         touch $SCRATCH_MNT/foo
106         mkdir $SCRATCH_MNT/bar
107         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
108         mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
109         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
110
111         # This is to force btrfs to relog the entire inode including the ref so
112         # we are sure to try and replay the ref along with the dir_index item
113         setfattr -n user.foo -v blah $SCRATCH_MNT/bar/foo >> $seqres.full 2>&1
114
115         $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
116         _load_flakey_table $FLAKEY_DROP_WRITES
117         _unmount_flakey
118
119         _load_flakey_table $FLAKEY_ALLOW_WRITES
120         _mount_flakey
121         _ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
122         _ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
123         _unmount_flakey
124 }
125
126 _scratch_mkfs >> $seqres.full 2>&1
127
128 # Create a basic flakey device that will never error out
129 _init_flakey
130
131 _directory_test
132 _clean_working_dir
133 _rename_test
134 _clean_working_dir
135 _replay_rename_test
136
137 status=0
138 exit