fstests: move test group info to test files
[xfstests-dev.git] / tests / ext4 / 050
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Google, Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 050
6 #
7 # Test checkpoint and zeroout of journal via ioctl EXT4_IOC_CHECKPOINT
8 #
9
10 . ./common/preamble
11 _begin_fstest auto ioctl quick
12
13 # Import common functions.
14 . ./common/filter
15
16 # real QA test starts here
17 _supported_fs ext4
18
19 _require_scratch
20 _require_command "$DEBUGFS_PROG" debugfs
21
22 checkpoint_journal=$here/src/checkpoint_journal
23 _require_test_program "checkpoint_journal"
24
25 # convert output from stat<journal_inode> to list of block numbers
26 get_journal_extents() {
27         inode_info=$($DEBUGFS_PROG $SCRATCH_DEV -R "stat <8>" 2>> $seqres.full)
28         echo -e "\nJournal info:" >> $seqres.full
29         echo "$inode_info" >> $seqres.full
30
31         extents_line=$(echo "$inode_info" | awk '/EXTENTS:/{ print NR; exit }')
32         get_extents=$(echo "$inode_info" | sed -n "$(($extents_line + 1))"p)
33
34         # get just the physical block numbers
35         get_extents=$(echo "$get_extents" |  perl -pe 's|\(.*?\):||g' | sed -e 's/, /\n/g' | perl -pe 's|(\d+)-(\d+)|\1 \2|g')
36
37         echo "$get_extents"
38 }
39
40 # checks all extents are zero'd out except for the superblock
41 # arg 1: extents (output of get_journal_extents())
42 check_extents() {
43         echo -e "\nChecking extents:" >> $seqres.full
44         echo "$1" >> $seqres.full
45
46         super_block="true"
47         echo "$1" | while IFS= read line; do
48                 start_block=$(echo $line | cut -f1 -d' ')
49                 end_block=$(echo $line | cut -f2 -d' ' -s)
50
51                 # if first block of journal, shouldn't be wiped
52                 if [ "$super_block" == "true" ]; then
53                         super_block="false"
54
55                         #if super block only block in this extent, skip extent
56                         if [ -z "$end_block" ]; then
57                                 continue;
58                         fi
59                         start_block=$(($start_block + 1))
60                 fi
61
62                 if [ ! -z "$end_block" ]; then
63                         blocks=$(($end_block - $start_block + 1))
64                 else
65                         blocks=1
66                 fi
67
68                 check=$(od $SCRATCH_DEV --skip-bytes=$(($start_block * $blocksize)) --read-bytes=$(($blocks * $blocksize)) -An -v | sed -e 's/[0 \t\n\r]//g')
69
70                 [ ! -z "$check" ] && echo "error" && break
71         done
72 }
73
74 testdir="${SCRATCH_MNT}/testdir"
75
76 _scratch_mkfs_sized $((64 * 1024 * 1024)) >> $seqres.full 2>&1
77 _require_metadata_journaling $SCRATCH_DEV
78 _scratch_mount >> $seqres.full 2>&1
79 blocksize=$(_get_block_size $SCRATCH_MNT)
80 mkdir $testdir
81
82 # check if ioctl present, skip test if not present
83 $checkpoint_journal $SCRATCH_MNT --dry-run || _notrun "journal checkpoint ioctl not present on device"
84
85 # create some files to add some entries to journal
86 for i in {1..100}; do
87         echo > $testdir/$i
88 done
89
90 # make sure these files get to the journal
91 sync --file-system $testdir/1
92
93 # call ioctl to checkpoint and zero-fill journal blocks
94 $checkpoint_journal $SCRATCH_MNT --erase=zeroout || _fail "ioctl returned error"
95
96 extents=$(get_journal_extents)
97
98 # check journal blocks zeroed out
99 ret=$(check_extents "$extents")
100 [ "$ret" = "error" ] && _fail "Journal was not zero-filled"
101
102 _scratch_unmount >> $seqres.full 2>&1
103
104 echo "Silence is golden"
105
106 status=0
107 exit