blob: 5541aee0c3d575bb10aa3e4e1ae4fec4b95596ab [file] [log] [blame]
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2022 Oracle. All Rights Reserved.
#
# FS QA Test No. 713
#
# Test exchangerange between ranges of two different files.
. ./common/preamble
_begin_fstest auto quick fiexchange
# Override the default cleanup function.
_cleanup()
{
cd /
rm -r -f $tmp.* $dir
}
# Import common functions.
. ./common/filter
. ./common/reflink
_require_xfs_io_command exchangerange ' -s 64k -l 64k'
_require_xfs_io_command "falloc"
_require_test
filesnap() {
echo "$1"
if [ "$2" != "$3" ]; then
md5sum $2 $3 | _filter_test_dir
else
md5sum $2 | _filter_test_dir
fi
}
test_exchangerange_once() {
filesnap "$1: before exchangerange" $dir/$3 $dir/$4
$XFS_IO_PROG -c "exchangerange $2 $dir/$3" $dir/$4
filesnap "$1: after exchangerange" $dir/$3 $dir/$4
_test_cycle_mount
filesnap "$1: after cycling mount" $dir/$3 $dir/$4
echo
}
test_exchangerange_two() {
# exchangerange the same range of two files
test_exchangerange_once "$*: samerange" \
"-s $((blksz * 3)) -d $((blksz * 3)) -l $((blksz * 5))" b a
# exchangerange different ranges of two files
test_exchangerange_once "$*: diffrange" \
"-s $((blksz * 37)) -d $((blksz * 47)) -l $((blksz * 7))" b a
# exchangerange overlapping ranges of two files
test_exchangerange_once "$*: overlap" \
"-s $((blksz * 17)) -d $((blksz * 23)) -l $((blksz * 7))" b a
}
dir=$TEST_DIR/test-$seq
mkdir -p $dir
blksz=65536
nrblks=57
_require_congruent_file_oplen $TEST_DIR $blksz
# Set up some simple files for a first test.
rm -rf $dir/a $dir/b
_pwrite_byte 0x58 0 $((blksz * nrblks)) $dir/a >> $seqres.full
_pwrite_byte 0x59 0 $((blksz * nrblks)) $dir/b >> $seqres.full
test_exchangerange_two "simple"
# Make some files that don't end an aligned offset.
rm -rf $dir/a $dir/b
_pwrite_byte 0x58 0 $(( (blksz * nrblks) + 37)) $dir/a >> $seqres.full
_pwrite_byte 0x59 0 $(( (blksz * nrblks) + 37)) $dir/b >> $seqres.full
test_exchangerange_once "unalignedeof" "" a b
# Set up some crazy rainbow files
rm -rf $dir/a $dir/b
_weave_file_rainbow $blksz $nrblks $dir/a >> $seqres.full
_weave_file_rainbow $blksz $nrblks $dir/b >> $seqres.full
test_exchangerange_two "rainbow"
# Now set up a simple file for testing within the same file
rm -rf $dir/c
$XFS_IO_PROG -f -c "pwrite -S 0x58 0 $((blksz * nrblks))" \
-c "pwrite -S 0x59 $((blksz * nrblks)) $((blksz * nrblks))" \
$dir/c >> $seqres.full
# exchangerange the same offset into the 'X' and 'Y' regions of the file
test_exchangerange_once "single: sameXandY" \
"-s $((blksz * 3)) -d $((blksz * (nrblks + 3))) -l $((blksz * 5))" c c
# exchangerange the same offset into the 'X' and 'Y' regions of the file
test_exchangerange_once "single: overlap" \
"-s $((blksz * 13)) -d $((blksz * 17)) -l $((blksz * 5))" c c
# success, all done
status=0
exit