diff options
author | Darrick J. Wong <djwong@kernel.org> | 2023-02-28 18:59:15 -0800 |
---|---|---|
committer | Zorro Lang <zlang@kernel.org> | 2023-03-02 16:18:23 +0800 |
commit | 5d2aea2b1f6dc3ac84909bbd3c155edccc131aae (patch) | |
tree | 4bd66768877a82e94934d3bd2e386960310dc00d | |
parent | e19c99400cfe67bd5f11d3cfe5587446ed3026ef (diff) |
generic: test old xfs extent swapping ioctl
Add some tests to check the operation of the old xfs swapext ioctl.
There aren't any xfs-specific pieces in here, so they're in generic/
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
-rw-r--r-- | common/rc | 11 | ||||
-rw-r--r-- | doc/group-names.txt | 2 | ||||
-rwxr-xr-x | tests/generic/709 | 55 | ||||
-rw-r--r-- | tests/generic/709.out | 3 | ||||
-rwxr-xr-x | tests/generic/710 | 53 | ||||
-rw-r--r-- | tests/generic/710.out | 4 | ||||
-rwxr-xr-x | tests/generic/711 | 47 | ||||
-rw-r--r-- | tests/generic/711.out | 2 | ||||
-rwxr-xr-x | tests/xfs/537 | 2 | ||||
-rwxr-xr-x | tests/xfs/789 | 59 | ||||
-rw-r--r-- | tests/xfs/789.out | 12 |
11 files changed, 249 insertions, 1 deletions
@@ -2581,6 +2581,17 @@ _require_xfs_io_command() echo $testio | grep -q "Inappropriate ioctl" && \ _notrun "xfs_io $command support is missing" ;; + "swapext") + $XFS_IO_PROG -f -c 'pwrite -S 0x58 0 128k -b 128k' $testfile > /dev/null + $XFS_IO_PROG -f -c 'truncate 128k' $testfile.1 > /dev/null + testio=`$XFS_IO_PROG -c "$command $param $testfile.1" $testfile 2>&1` + echo $testio | grep -q "bad argument count" && \ + _notrun "xfs_io $command $param support is missing" + echo $testio | grep -q "Inappropriate ioctl" && \ + _notrun "xfs_io $command $param ioctl support is missing" + rm -f $testfile.1 + param_checked="$param" + ;; "utimes" ) testio=`$XFS_IO_PROG -f -c "utimes 0 0 0 0" $testfile 2>&1` ;; diff --git a/doc/group-names.txt b/doc/group-names.txt index ace59e05..a0ae6965 100644 --- a/doc/group-names.txt +++ b/doc/group-names.txt @@ -52,6 +52,7 @@ enospc ENOSPC error reporting exportfs file handles fiemap fiemap ioctl filestreams XFS filestreams allocator +fiexchange FIEXCHANGE_RANGE ioctl freeze filesystem freeze tests fsck general fsck tests fsmap FS_IOC_GETFSMAP ioctl @@ -123,6 +124,7 @@ splice splice system call stress fsstress filesystem exerciser subvol btrfs subvolumes swap swap files +swapext XFS_IOC_SWAPEXT ioctl symlink symbolic links tape dump and restore with a tape thin thin provisioning diff --git a/tests/generic/709 b/tests/generic/709 new file mode 100755 index 00000000..3dbce2c2 --- /dev/null +++ b/tests/generic/709 @@ -0,0 +1,55 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 709 +# +# Can we use swapext to make the quota accounting incorrect? + +. ./common/preamble +_begin_fstest auto quick fiexchange swapext quota + +# Import common functions. +. ./common/filter +. ./common/quota + +# real QA test starts here +_require_xfs_io_command swapext '-v vfs' +_require_user +_require_nobody +_require_quota +_require_xfs_quota +_require_scratch + +# Format filesystem and set up quota limits +_scratch_mkfs > $seqres.full +_qmount_option "usrquota,grpquota" +_qmount >> $seqres.full + +# Set up initial files +$XFS_IO_PROG -f -c 'pwrite -S 0x58 0 256k -b 1m' $SCRATCH_MNT/a >> $seqres.full +chown $qa_user $SCRATCH_MNT/a +$XFS_IO_PROG -f -c 'pwrite -S 0x59 0 64k -b 64k' -c 'truncate 256k' $SCRATCH_MNT/b >> $seqres.full +chown nobody $SCRATCH_MNT/b + +echo before swapext >> $seqres.full +$XFS_QUOTA_PROG -x -c 'report -a' $SCRATCH_MNT >> $seqres.full +stat $SCRATCH_MNT/* >> $seqres.full + +# Now try to swap the extents of the two files. The command is allowed to +# fail with -EINVAL (since that's what the first kernel fix does) or succeed +# (because subsequent rewrites can handle quota). Whatever the outcome, the +# quota usage check at the end should never show a discrepancy. +$XFS_IO_PROG -c "swapext $SCRATCH_MNT/b" $SCRATCH_MNT/a &> $tmp.swap +cat $tmp.swap >> $seqres.full +grep -v 'Invalid argument' $tmp.swap + +echo after swapext >> $seqres.full +$XFS_QUOTA_PROG -x -c 'report -a' $SCRATCH_MNT >> $seqres.full +stat $SCRATCH_MNT/* >> $seqres.full + +_check_quota_usage + +# success, all done +status=0 +exit diff --git a/tests/generic/709.out b/tests/generic/709.out new file mode 100644 index 00000000..e2d83cf0 --- /dev/null +++ b/tests/generic/709.out @@ -0,0 +1,3 @@ +QA output created by 709 +Comparing user usage +Comparing group usage diff --git a/tests/generic/710 b/tests/generic/710 new file mode 100755 index 00000000..dc4a999a --- /dev/null +++ b/tests/generic/710 @@ -0,0 +1,53 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 710 +# +# Can we use swapext to exceed the quota enforcement? + +. ./common/preamble +_begin_fstest auto quick fiexchange swapext quota + +# Import common functions. +. ./common/filter +. ./common/quota + +# real QA test starts here +_require_xfs_io_command swapext '-v vfs' +_require_user +_require_nobody +_require_quota +_require_xfs_quota +_require_scratch + +# Format filesystem and set up quota limits +_scratch_mkfs > $seqres.full +_qmount_option "usrquota,grpquota" +_qmount >> $seqres.full + +# Set up initial files +$XFS_IO_PROG -f -c 'pwrite -S 0x58 0 256k -b 1m' $SCRATCH_MNT/a >> $seqres.full +chown $qa_user $SCRATCH_MNT/a +$XFS_IO_PROG -f -c 'pwrite -S 0x59 0 64k -b 64k' -c 'truncate 256k' $SCRATCH_MNT/b >> $seqres.full +chown nobody $SCRATCH_MNT/b + +# Set up a quota limit +$XFS_QUOTA_PROG -x -c "limit -u bhard=70k nobody" $SCRATCH_MNT + +echo before swapext >> $seqres.full +$XFS_QUOTA_PROG -x -c 'report -a' $SCRATCH_MNT >> $seqres.full +stat $SCRATCH_MNT/* >> $seqres.full + +# Now try to swapext +$XFS_IO_PROG -c "swapext $SCRATCH_MNT/b" $SCRATCH_MNT/a + +echo after swapext >> $seqres.full +$XFS_QUOTA_PROG -x -c 'report -a' $SCRATCH_MNT >> $seqres.full +stat $SCRATCH_MNT/* >> $seqres.full + +_check_quota_usage + +# success, all done +status=0 +exit diff --git a/tests/generic/710.out b/tests/generic/710.out new file mode 100644 index 00000000..a2aa9819 --- /dev/null +++ b/tests/generic/710.out @@ -0,0 +1,4 @@ +QA output created by 710 +swapext: Disk quota exceeded +Comparing user usage +Comparing group usage diff --git a/tests/generic/711 b/tests/generic/711 new file mode 100755 index 00000000..a24fe226 --- /dev/null +++ b/tests/generic/711 @@ -0,0 +1,47 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 711 +# +# Make sure that swapext won't touch a swap file. + +. ./common/preamble +_begin_fstest auto quick fiexchange swapext + +# Override the default cleanup function. +_cleanup() +{ + cd / + test -e "$dir/a" && swapoff $dir/a + rm -r -f $tmp.* $dir +} + +# Import common functions. +. ./common/filter + +# real QA test starts here +_require_xfs_io_command swapext '-v vfs' +_require_test + +dir=$TEST_DIR/test-$seq +mkdir -p $dir + +# Set up a fragmented swapfile and a dummy donor file. +$XFS_IO_PROG -f -c 'pwrite -S 0x58 0 32m -b 1m' -c fsync $dir/a >> $seqres.full +$here/src/punch-alternating $dir/a +$XFS_IO_PROG -f -c 'pwrite -S 0x58 0 32m -b 1m' -c fsync $dir/a >> $seqres.full +$MKSWAP_PROG $dir/a >> $seqres.full + +$XFS_IO_PROG -f -c 'pwrite -S 0x59 0 32m -b 1m' $dir/b >> $seqres.full + +swapon $dir/a || _notrun 'failed to swapon' + +# Now try to swapext. The old code would return EINVAL for swapfiles +# even though everything else in the VFS returns ETXTBSY. +$XFS_IO_PROG -c "swapext $dir/b" $dir/a 2>&1 | \ + sed -e 's/swapext: Invalid argument/swapext: Text file busy/g' + +# success, all done +status=0 +exit diff --git a/tests/generic/711.out b/tests/generic/711.out new file mode 100644 index 00000000..6c590f7e --- /dev/null +++ b/tests/generic/711.out @@ -0,0 +1,2 @@ +QA output created by 711 +swapext: Text file busy diff --git a/tests/xfs/537 b/tests/xfs/537 index 7e114887..6364db9b 100755 --- a/tests/xfs/537 +++ b/tests/xfs/537 @@ -7,7 +7,7 @@ # Verify that XFS does not cause inode fork's extent count to overflow when # swapping forks between files . ./common/preamble -_begin_fstest auto quick collapse +_begin_fstest auto quick collapse swapext # Import common functions. . ./common/filter diff --git a/tests/xfs/789 b/tests/xfs/789 new file mode 100755 index 00000000..9df91ac3 --- /dev/null +++ b/tests/xfs/789 @@ -0,0 +1,59 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 789 +# +# Simple tests of the old xfs swapext ioctl + +. ./common/preamble +_begin_fstest auto quick fiexchange swapext + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $dir +} + +# Import common functions. +. ./common/filter + +# real QA test starts here +_supported_fs xfs +_require_xfs_io_command swapext '-v vfs' +_require_test + +# We can't do any reasonable swapping if the files we're going to create are +# realtime files, the rt extent size is greater than 1 block, and we can't use +# atomic extent swapping to make sure that partially written extents are fully +# swapped. +file_blksz=$(_get_file_block_size $TEST_DIR) +fs_blksz=$(_get_block_size $TEST_DIR) +if (( $file_blksz != $fs_blksz )); then + _xfs_has_feature $TEST_DIR reflink || \ + _notrun "test requires atomic extent swapping for rextsize=$((file_blksz / fs_blksz))" +fi + +dir=$TEST_DIR/test-$seq +mkdir -p $dir + +$XFS_IO_PROG -f -c 'pwrite -S 0x58 0 256k -b 1m' $dir/a >> $seqres.full +$XFS_IO_PROG -f -c 'pwrite -S 0x59 0 256k -b 1m' $dir/b >> $seqres.full +$XFS_IO_PROG -f -c 'pwrite -S 0x60 0 256k -b 1m' $dir/c >> $seqres.full +$XFS_IO_PROG -f -c 'pwrite -S 0x61 0 128k -b 1m' $dir/d >> $seqres.full +md5sum $dir/a $dir/b $dir/c $dir/d | _filter_test_dir + +# Swap two files that are the same length +echo swap +$XFS_IO_PROG -c "swapext $dir/b" $dir/a +md5sum $dir/a $dir/b | _filter_test_dir + +# Try to swap two files that are not the same length +echo fail swap +$XFS_IO_PROG -c "swapext $dir/c" $dir/d +md5sum $dir/c $dir/d | _filter_test_dir + +# success, all done +status=0 +exit diff --git a/tests/xfs/789.out b/tests/xfs/789.out new file mode 100644 index 00000000..1ed23fca --- /dev/null +++ b/tests/xfs/789.out @@ -0,0 +1,12 @@ +QA output created by 789 +af5c6e2d6c297f3139a4e99df396c072 TEST_DIR/test-789/a +fba5c83875b2ab054e06a0284346ebdf TEST_DIR/test-789/b +40c08c6f2aca19bb0d2cf1dbd8bc1b1c TEST_DIR/test-789/c +81615449a98aaaad8dc179b3bec87f38 TEST_DIR/test-789/d +swap +fba5c83875b2ab054e06a0284346ebdf TEST_DIR/test-789/a +af5c6e2d6c297f3139a4e99df396c072 TEST_DIR/test-789/b +fail swap +swapext: Bad address +40c08c6f2aca19bb0d2cf1dbd8bc1b1c TEST_DIR/test-789/c +81615449a98aaaad8dc179b3bec87f38 TEST_DIR/test-789/d |