#! /bin/bash
-# SPDX-License-Identifier: GPL-2.0
-# Copyright (c) 2006 Silicon Graphics, Inc. All Rights Reserved.
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 Oracle. All Rights Reserved.
#
-# FSQA Test No. 147
-#
-# Dmapi get/set_region
+# FS QA Test No. 147
#
+# Make sure we validate realtime extent size alignment for fallocate modes.
+# This is a regression test for fe341eb151ec ("xfs: ensure that fpunch,
+# fcollapse, and finsert operations are aligned to rt extent size")
+
seq=`basename $0`
seqres=$RESULT_DIR/$seq
echo "QA output created by $seq"
here=`pwd`
tmp=/tmp/$$
status=1 # failure is the default!
-trap "exit \$status" 0 1 2 3 15
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -f $tmp.*
+}
# get standard environment, filters and checks
. ./common/rc
. ./common/filter
-. ./common/dmapi
# real QA test starts here
_supported_fs xfs
-_supported_os Linux
-
_require_scratch
-_scratch_mkfs_xfs >/dev/null 2>&1
-_dmapi_scratch_mount
+_require_realtime
+_require_xfs_io_command "fcollapse"
+_require_xfs_io_command "finsert"
+_require_xfs_io_command "funshare"
+_require_xfs_io_command "fzero"
+_require_xfs_io_command "falloc"
+
+rm -f $seqres.full
+
+# Format filesystem with a 256k realtime extent size
+_scratch_mkfs -r extsize=256k > $seqres.full
+_scratch_mount >> $seqres.full
+
+blksz=$(_get_block_size $SCRATCH_MNT)
+rextsize=$($XFS_INFO_PROG $SCRATCH_MNT | grep realtime.*extsz | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g')
+rextblks=$((rextsize / blksz))
+
+echo "blksz $blksz rextsize $rextsize rextblks $rextblks" >> $seqres.full
+
+# Make sure the root directory has rtinherit set so our test file will too
+_xfs_force_bdev realtime $SCRATCH_MNT
-mkdir -p $SCRATCH_MNT/dmapi
+sz=$((rextsize * 100))
+range="$((blksz * 3)) $blksz"
-# run DMAPI test using verbose output
-${DMAPI_QASUITE2_DIR}src/test_region -v $DMAPI_LS_TO_COPY_PATH $SCRATCH_MNT
+for verb in fpunch finsert fcollapse fzero funshare falloc; do
+ echo "test $verb"
+ $XFS_IO_PROG -f -c "falloc 0 $sz" "$SCRATCH_MNT/b"
+ $XFS_IO_PROG -f -c "$verb $range" "$SCRATCH_MNT/b"
+ rm -f "$SCRATCH_MNT/b"
+ _scratch_cycle_mount
+done
+# success, all done
status=0
-exit
+exit