fstests: move test group info to test files
[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 . ./common/preamble
11 _begin_fstest auto quick
12
13 # Import common functions.
14
15 # real QA test starts here
16 _supported_fs ext4
17 _require_scratch
18 _require_dumpe2fs
19
20 _scratch_mkfs >> $seqres.full 2>&1
21 _scratch_mount
22 blocksize=$(_get_block_size $SCRATCH_MNT)
23 _scratch_unmount
24
25 # With 4k block size, this amounts to 10M FS instance.
26 fssize=$((2560 * $blocksize))
27 _scratch_mkfs_sized $fssize >> $seqres.full 2>&1
28 _require_metadata_journaling $SCRATCH_DEV
29
30 offset=0
31 found=0
32 # this is the jbd2 journal superblock magic number on disk, in big endian
33 magic="c0 3b 39 98"
34
35 while [ $offset -lt $fssize ]; do
36         if od -j $offset -N 4 -t x1 $SCRATCH_DEV | \
37            grep -i "$magic" >/dev/null; then
38                 echo "Found journal: $offset" >> $seqres.full
39                 found=1
40                 break
41         fi
42         offset=$((offset + blocksize))
43 done
44 if [ $found -ne 1 ]; then
45         echo "Found no journal"
46         exit
47 fi
48
49 # Overwrite journal.s_squence to 0x 81d1a480
50 # 0x81d1a480 is hex form of 2178000000, and jbd2 journal is big endian on
51 # disk, the s_squence offset to the beginning of journal superblock is 24
52 # we do this to let jbd2 start to run with a initial big transaction id,
53 # which will reduce the time taken to trigger this bug.
54 $XFS_IO_PROG -c "pwrite -S 0x81 $((offset+24)) 1" \
55         -c "pwrite -S 0xd1 $((offset+25)) 1" \
56         -c "pwrite -S 0xa4 $((offset+26)) 1" \
57         -c "pwrite -S 0x80 $((offset+27)) 1" $SCRATCH_DEV >> $seqres.full 2>&1
58
59 trans_id=`$DUMPE2FS_PROG $SCRATCH_DEV 2>/dev/null | grep "Journal sequence" | \
60         awk '{print $NF}'`
61 echo "Initial transaction id is $trans_id"
62 _scratch_mount
63
64 do_fdatasync_work()
65 {
66         # Wait for running subcommand before exitting so that
67         # mountpoint is not busy when we try to unmount it
68         trap "wait; exit" SIGTERM
69
70         while [ 1 ]; do
71                 $XFS_IO_PROG -f -c "fdatasync" $SCRATCH_MNT/testfile
72         done
73 }
74
75 do_fdatasync_work &
76 datasync_work_pid=$!
77 sleep 10
78 kill $datasync_work_pid >/dev/null 2>&1
79 wait
80
81 # success, all done
82 status=0
83 exit