38ed7ad51a577896661b5ecc9e264011ae725b20
[xfstests-dev.git] / tests / btrfs / 049
1 #! /bin/bash
2 # FS QA Test No. btrfs/049
3 #
4 # Regression test for btrfs inode caching vs tree log which was
5 # addressed by the following kernel patch.
6 #
7 # Btrfs: fix inode caching vs tree log
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2014 Fujitsu.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33
34 status=1        # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39         _cleanup_flakey
40         rm -rf $tmp
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46 . ./common/dmflakey
47
48 # real QA test starts here
49 _supported_fs btrfs
50 _supported_os Linux
51 _need_to_be_root
52 _require_scratch
53 _require_dm_target flakey
54
55 rm -f $seqres.full
56
57 _scratch_mkfs >> $seqres.full 2>&1
58
59 SAVE_MOUNT_OPTIONS="$MOUNT_OPTIONS"
60 MOUNT_OPTIONS="$MOUNT_OPTIONS -o inode_cache,commit=100"
61
62 # create a basic flakey device that will never error out
63 _init_flakey
64 _mount_flakey
65
66 _get_inode_id()
67 {
68         local inode_id
69         inode_id=`stat $1 | grep Inode: | $AWK_PROG '{print $4}'`
70         echo $inode_id
71 }
72
73 $XFS_IO_PROG -f -c "pwrite 0 10M" -c "fsync" \
74         $SCRATCH_MNT/data >& /dev/null
75
76 inode_id=`_get_inode_id "$SCRATCH_MNT/data"`
77 rm -f $SCRATCH_MNT/data
78
79 for i in `seq 1 5`;
80 do
81         mkdir $SCRATCH_MNT/dir_$i
82         new_inode_id=`_get_inode_id $SCRATCH_MNT/dir_$i`
83         if [ $new_inode_id -eq $inode_id ]
84         then
85                 $XFS_IO_PROG -f -c "pwrite 0 1M" -c "fsync" \
86                         $SCRATCH_MNT/dir_$i/data1 >& /dev/null
87                 _load_flakey_table 1
88                 _unmount_flakey
89                 need_umount=1
90                 break
91         fi
92         sleep 1
93 done
94
95 # restore previous mount options
96 export MOUNT_OPTIONS="$SAVE_MOUNT_OPTIONS"
97
98 # ok mount so that any recovery that needs to happen is done
99 if [ $new_inode_id -eq $inode_id ];then
100         _load_flakey_table $FLAKEY_ALLOW_WRITES
101         _mount_flakey
102         _unmount_flakey
103 fi
104
105 # make sure we got a valid fs after replay
106 _check_scratch_fs $FLAKEY_DEV
107
108 status=0
109 exit