2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat, inc. All Rights Reserved.
7 # Test xfs_fsr's handling of 2-extent files with preallocation
9 # An error in xfs_swap_extent_forks() incorrectly set up the
10 # temporary inode's if_extents pointer to inline, leading to
11 # in-memory corruption when the temporary inode was released
12 # and torn down; i_itemp and d_ops got overwritten with zeros,
13 # which led to an oops in xfs_trans_log_inode down the fput path.
15 # Fixed upstream by proper nextents counting using
16 # ip->i_df.if_bytes not ip->i_d.di_nextents in xfs_swap_extent_forks
19 _begin_fstest auto quick fsr
21 # Import common functions.
27 _require_command "$XFS_FSR_PROG" "xfs_fsr"
28 _require_xfs_io_command "falloc"
31 _scratch_mkfs_sized $((50 * 1024 * 1024)) >> $seqres.full 2>&1
34 echo "Silence is golden"
37 # The aim is to create a fragmented two-extent file *with* prealloc
38 # so make the free holes big enough that a 2-extent file will have
39 # preallocation added. Let's say... 64k free chunks.
41 $XFS_IO_PROG -fs -c "falloc 0 40000k" $SCRATCH_MNT/fill >> $seqres.full 2>&1
44 dd if=/dev/zero of=$SCRATCH_MNT/remainder oflag=direct > /dev/null 2>&1
46 # Free up a bunch of 64k chunks
47 for i in `seq 0 68 40000`; do
48 $XFS_IO_PROG -fs -c "unresvsp ${i}k 64k" $SCRATCH_MNT/fill
51 # Create 2-extent files w/ preallocation (via extending writes)
52 for I in `seq 1 64`; do
53 $XFS_IO_PROG -f -c "pwrite 0 64k" $SCRATCH_MNT/newfile-$I \
55 $XFS_IO_PROG -f -c "pwrite 64k 64k" $SCRATCH_MNT/newfile-$I \
58 # sync to get extents on disk so fsr sees them
61 # Free up some space for defragmentation temp file
62 rm -f $SCRATCH_MNT/fill
64 $XFS_FSR_PROG -vd $SCRATCH_MNT/newfile* >> $seqres.full 2>&1