On 3/20/24 20:06, Josef Bacik wrote:
Btrfs had a deadlock that you could trigger by mmap'ing a large file and using that as the buffer for fiemap. This test adds a c program to do this, and the fstest creates a large enough file and then runs the reproducer on the file. Without the fix btrfs deadlocks, with the fix we pass fine. Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx> --- v2->v3: - Add fiemap-fault to .gitignore - Added a _cleanup() helper - Just let the output of fiemap-fault go instead of using || _fail - Added the munmap - Moved $dst to $TEST_DIR/$seq
looks good. Reviewed-by: Anand Jain <anand.jain@xxxxxxxxxx> A minor whitespace error below, maybe Zorro can handle it when applied. <snap>
diff --git a/tests/generic/808 b/tests/generic/808 new file mode 100755 index 00000000..36015f35 --- /dev/null +++ b/tests/generic/808 @@ -0,0 +1,48 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Meta Platforms, Inc. All Rights Reserved. +# +# FS QA Test 808 +# +# Test fiemap into an mmaped buffer of the same file +# +# Create a reasonably large file, then run a program which mmaps it and uses +# that as a buffer for an fiemap call. This is a regression test for btrfs +# where we used to hold a lock for the duration of the fiemap call which would +# result in a deadlock if we page faulted. +# +. ./common/preamble +_begin_fstest quick auto fiemap +[ $FSTYP == "btrfs" ] && \ + _fixed_by_kernel_commit b0ad381fa769 \ + "btrfs: fix deadlock with fiemap and extent locking" + +_cleanup() +{ + rm -f $dst + cd / + rm -r -f $tmp.* +} + +# real QA test starts here +_supported_fs generic +_require_test +_require_odirect +_require_test_program fiemap-fault +dst=$TEST_DIR/$seq/fiemap-fault + +mkdir -p $TEST_DIR/$seq + +echo "Silence is golden" + +for i in $(seq 0 2 1000) +do + $XFS_IO_PROG -d -f -c "pwrite -q $((i * 4096)) 4096" $dst +done + +$here/src/fiemap-fault $dst + +# success, all done +status=$? +exit
+
Applying: generic/808: add a regression test for fiemap into an mmap range .git/rebase-apply/patch:177: new blank line at EOF. + warning: 1 line adds whitespace errors. Thanks.