2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Google, Inc. All Rights Reserved.
7 # Test checkpoint and zeroout of journal via ioctl EXT4_IOC_CHECKPOINT
11 _begin_fstest auto ioctl quick
13 # Import common functions.
16 # real QA test starts here
20 _require_command "$DEBUGFS_PROG" debugfs
22 checkpoint_journal=$here/src/checkpoint_journal
23 _require_test_program "checkpoint_journal"
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
31 extents_line=$(echo "$inode_info" | awk '/EXTENTS:/{ print NR; exit }')
32 get_extents=$(echo "$inode_info" | sed -n "$(($extents_line + 1))"p)
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')
40 # checks all extents are zero'd out except for the superblock
41 # arg 1: extents (output of get_journal_extents())
43 echo -e "\nChecking extents:" >> $seqres.full
44 echo "$1" >> $seqres.full
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)
51 # if first block of journal, shouldn't be wiped
52 if [ "$super_block" == "true" ]; then
55 #if super block only block in this extent, skip extent
56 if [ -z "$end_block" ]; then
59 start_block=$(($start_block + 1))
62 if [ ! -z "$end_block" ]; then
63 blocks=$(($end_block - $start_block + 1))
68 check=$(od $SCRATCH_DEV --skip-bytes=$(($start_block * $blocksize)) --read-bytes=$(($blocks * $blocksize)) -An -v | sed -e 's/[0 \t\n\r]//g')
70 [ ! -z "$check" ] && echo "error" && break
74 testdir="${SCRATCH_MNT}/testdir"
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)
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"
85 # create some files to add some entries to journal
90 # make sure these files get to the journal
91 sync --file-system $testdir/1
93 # call ioctl to checkpoint and zero-fill journal blocks
94 $checkpoint_journal $SCRATCH_MNT --erase=zeroout || _fail "ioctl returned error"
96 extents=$(get_journal_extents)
98 # check journal blocks zeroed out
99 ret=$(check_extents "$extents")
100 [ "$ret" = "error" ] && _fail "Journal was not zero-filled"
102 _scratch_unmount >> $seqres.full 2>&1
104 echo "Silence is golden"