fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / ext4 / 021
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test 021
6 #
7 # Regression test for commit:
8 # 688f869 ext4: Initialize fsync transaction ids in ext4_new_inode()
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27
28 # remove previous $seqres.full before test
29 rm -f $seqres.full
30
31 # real QA test starts here
32 _supported_fs ext4
33 _require_scratch
34 _require_dumpe2fs
35
36 _scratch_mkfs >> $seqres.full 2>&1
37 _scratch_mount
38 blocksize=$(_get_block_size $SCRATCH_MNT)
39 _scratch_unmount
40
41 # With 4k block size, this amounts to 10M FS instance.
42 fssize=$((2560 * $blocksize))
43 _scratch_mkfs_sized $fssize >> $seqres.full 2>&1
44 _require_metadata_journaling $SCRATCH_DEV
45
46 offset=0
47 found=0
48 # this is the jbd2 journal superblock magic number on disk, in big endian
49 magic="c0 3b 39 98"
50
51 while [ $offset -lt $fssize ]; do
52         if od -j $offset -N 4 -t x1 $SCRATCH_DEV | \
53            grep -i "$magic" >/dev/null; then
54                 echo "Found journal: $offset" >> $seqres.full
55                 found=1
56                 break
57         fi
58         offset=$((offset + blocksize))
59 done
60 if [ $found -ne 1 ]; then
61         echo "Found no journal"
62         exit
63 fi
64
65 # Overwrite journal.s_squence to 0x 81d1a480
66 # 0x81d1a480 is hex form of 2178000000, and jbd2 journal is big endian on
67 # disk, the s_squence offset to the beginning of journal superblock is 24
68 # we do this to let jbd2 start to run with a initial big transaction id,
69 # which will reduce the time taken to trigger this bug.
70 $XFS_IO_PROG -c "pwrite -S 0x81 $((offset+24)) 1" \
71         -c "pwrite -S 0xd1 $((offset+25)) 1" \
72         -c "pwrite -S 0xa4 $((offset+26)) 1" \
73         -c "pwrite -S 0x80 $((offset+27)) 1" $SCRATCH_DEV >> $seqres.full 2>&1
74
75 trans_id=`$DUMPE2FS_PROG $SCRATCH_DEV 2>/dev/null | grep "Journal sequence" | \
76         awk '{print $NF}'`
77 echo "Initial transaction id is $trans_id"
78 _scratch_mount
79
80 do_fdatasync_work()
81 {
82         # Wait for running subcommand before exitting so that
83         # mountpoint is not busy when we try to unmount it
84         trap "wait; exit" SIGTERM
85
86         while [ 1 ]; do
87                 $XFS_IO_PROG -f -c "fdatasync" $SCRATCH_MNT/testfile
88         done
89 }
90
91 do_fdatasync_work &
92 datasync_work_pid=$!
93 sleep 10
94 kill $datasync_work_pid >/dev/null 2>&1
95 wait
96
97 # success, all done
98 status=0
99 exit