e9c177a27f95e78e355865fb86d8b979f6687c24
[xfstests-dev.git] / tests / ext4 / 021
1 #! /bin/bash
2 # FS QA Test 021
3 #
4 # Regression test for commit:
5 # 688f869 ext4: Initialize fsync transaction ids in ext4_new_inode()
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2016 Fujitsu.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42
43 # remove previous $seqres.full before test
44 rm -f $seqres.full
45
46 # real QA test starts here
47 _supported_fs ext4
48 _supported_os Linux
49 _require_scratch
50 _require_dumpe2fs
51
52 # 10M in bytes
53 fssize=$((10 * 1024 * 1024))
54 _scratch_mkfs_sized $fssize >> $seqres.full 2>&1
55 _require_metadata_journaling $SCRATCH_DEV
56
57 blocksize=`$DUMPE2FS_PROG -h $SCRATCH_DEV 2>/dev/null | grep "Block size" | \
58         awk '{print $3}'`
59 offset=0
60 found=0
61 # this is the jbd2 journal superblock magic number on disk, in big endian
62 magic="c0 3b 39 98"
63
64 while [ $offset -lt $fssize ]; do
65         if od -j $offset -N 4 -t x1 $SCRATCH_DEV | \
66            grep -i "$magic" >/dev/null; then
67                 echo "Found journal: $offset" >> $seqres.full
68                 found=1
69                 break
70         fi
71         offset=$((offset + blocksize))
72 done
73 if [ $found -ne 1 ]; then
74         echo "Found no journal"
75         exit
76 fi
77
78 # Overwrite journal.s_squence to 0x 81d1a480
79 # 0x81d1a480 is hex form of 2178000000, and jbd2 journal is big endian on
80 # disk, the s_squence offset to the beginning of journal superblock is 24
81 # we do this to let jbd2 start to run with a initial big transaction id,
82 # which will reduce the time taken to trigger this bug.
83 $XFS_IO_PROG -c "pwrite -S 0x81 $((offset+24)) 1" \
84         -c "pwrite -S 0xd1 $((offset+25)) 1" \
85         -c "pwrite -S 0xa4 $((offset+26)) 1" \
86         -c "pwrite -S 0x80 $((offset+27)) 1" $SCRATCH_DEV >> $seqres.full 2>&1
87
88 trans_id=`$DUMPE2FS_PROG $SCRATCH_DEV 2>/dev/null | grep "Journal sequence" | \
89         awk '{print $NF}'`
90 echo "Initial transaction id is $trans_id"
91 _scratch_mount
92
93 do_fdatasync_work()
94 {
95         while [ 1 ]; do
96                 $XFS_IO_PROG -f -c "fdatasync" $SCRATCH_MNT/testfile
97         done
98 }
99
100 do_fdatasync_work &
101 datasync_work_pid=$!
102 sleep 10
103 kill $datasync_work_pid >/dev/null 2>&1
104
105 # success, all done
106 status=0
107 exit