generic: fallocate two bytes at block boundary
PATCH v2 1/1 generic: fallocate two bytes at block boundary
Allocating two bytes at a block boundary with fallocate should allocate both blocks involved. Test this by writing data to both bytes afterwards and see whether the on-disk size increases (it should not).
---
v2:
- Use _get_file_block_size instead of manual stat -fc '%S'
- Use xfs_io instead of fallocate/dd
(and require falloc support)
- Add the ' B' that was missing as allocated_size_after's unit in the error message
--- tests/generic/568 | 63 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/568.out | 4 +++ tests/generic/group | 1 + 3 files changed, 68 insertions(+) create mode 100755 tests/generic/568 create mode 100644 tests/generic/568.out
tests/generic/568 new file +63 -0
@@ -0,0 +1,63 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2019 Red Hat, Inc. All Rights Reserved. +# +# FS QA Test No. generic/568 +# +# Test that fallocating an unaligned range allocates all blocks +# touched by that range +# +seq=$(basename $0) +seqres="$RESULT_DIR/$seq" +echo "QA output created by $seq" + +here=$PWD +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f "$tmp".* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_scratch +_require_xfs_io_command "falloc" + +testfile="$SCRATCH_MNT/testfile" + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mount + +# Fallocate 2 bytes across a block boundary +block_size=$(_get_file_block_size "$SCRATCH_MNT") +$XFS_IO_PROG -f -c "falloc $((block_size - 1)) 2" "$testfile" + +# Both the first blocks should be allocated now. Check that by +# inquiring whether the file grows when we write to the two bytes we +# have just fallocated. + +allocated_size_before=$(($(stat -c '%b * %B' "$testfile"))) + +$XFS_IO_PROG -c "pwrite $((block_size - 1)) 2" "$testfile" \ + | _filter_xfs_io | sed -e "s/$((block_size - 1))/block_size - 1/" + +allocated_size_after=$(($(stat -c '%b * %B' "$testfile"))) + +if [ $allocated_size_after -gt $allocated_size_before ]; then + echo "ERROR: File grew from ${allocated_size_before} B to" \ + "${allocated_size_after} B when writing to the fallocated range." +else + echo "OK: File did not grow." +fi + +status=0 +exit
tests/generic/568.out new file +4 -0
@@ -0,0 +1,4 @@ +QA output created by 568 +wrote 2/2 bytes at offset block_size - 1 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +OK: File did not grow.
tests/generic/group +1 -0
@@ -570,3 +570,4 @@ 565 auto quick copy_range 566 auto quick quota metadata 567 auto quick rw punch +568 auto quick rw
Signature · 1 line
2.21.0
Quoted 5 lines · Max Reitz
Allocating two bytes at a block boundary with fallocate should allocate both blocks involved. Test this by writing data to both bytes afterwards and see whether the on-disk size increases (it should not).
Signed-off-by Max Reitz <[email protected]>
I notice that XFS fails this test with v5.3 kernel, so I guess this is a targeted regression test? Do you have a (pending) patch/commit that could be referenced in the commit log and/or test description? So we could know which patch/commit fixed this particular failure.
Quoted 49 lines
---
v2:
- Use_get_file_block_sizeinstead of manual stat -fc '%S'
- Usexfs_ioinstead of fallocate/dd
(and require falloc support)
- Add the ' B' that was missing as allocated_size_after's unit in the error message--- tests/generic/568 | 63 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/568.out | 4 +++ tests/generic/group | 1 + 3 files changed, 68 insertions(+) create mode 100755 tests/generic/568 create mode 100644 tests/generic/568.outtests/generic/568 new file +28
-0@@ -0,0 +1,63 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2019 Red Hat, Inc. All Rights Reserved. +# +# FS QA Test No. generic/568 +# +# Test that fallocating an unaligned range allocates all blocks +# touched by that range +# +seq=$(basename $0) +seqres="$RESULT_DIR/$seq" +echo "QA output created by $seq" + +here=$PWD +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f "$tmp".* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +
tests/generic/568 line 38
Quoted 10 lines
tests/generic/568 new file +10
-0+# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_scratch +_require_xfs_io_command "falloc" + +testfile="$SCRATCH_MNT/testfile" + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mount
Seems you don't need $SCRATCH_DEV at all. Just create the test file on $TEST_DEV in $TEST_DIR, e.g.
testfile="$TEST_DIR"/falloctest-$seq
rm -f $testfile
Quoted 40 lines
tests/generic/568 new file +25
-0+ +# Fallocate 2 bytes across a block boundary +block_size=$(_get_file_block_size "$SCRATCH_MNT") +$XFS_IO_PROG -f -c "falloc $((block_size - 1)) 2" "$testfile" + +# Both the first blocks should be allocated now. Check that by +# inquiring whether the file grows when we write to the two bytes we +# have just fallocated. + +allocated_size_before=$(($(stat -c '%b * %B' "$testfile"))) + +$XFS_IO_PROG -c "pwrite $((block_size - 1)) 2" "$testfile" \ + | _filter_xfs_io | sed -e "s/$((block_size - 1))/block_size - 1/" + +allocated_size_after=$(($(stat -c '%b * %B' "$testfile"))) + +if [ $allocated_size_after -gt $allocated_size_before ]; then + echo "ERROR: File grew from ${allocated_size_before} B to" \ + "${allocated_size_after} B when writing to the fallocated range." +else + echo "OK: File did not grow." +fi + +status=0 +exittests/generic/568.out new file +4
-0@@ -0,0 +1,4 @@ +QA output created by 568 +wrote 2/2 bytes at offset block_size - 1 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +OK: File did not grow.tests/generic/group +0
-0
tests/generic/group line 573
Quoted 4 lines
tests/generic/group +1
-0@@ -570,3 +570,4 @@ 565 auto quick copy_range 566 auto quick quota metadata 567 auto quick rw punch +568 auto quick rw
Add 'prealloc' group as well.
Thanks for the test!
Eryu
Quoted 3 lines
Signature · 1 line
2.21.0
Quoted 11 lines · Eryu Guan
Quoted 5 lines · Max Reitz
Allocating two bytes at a block boundary with fallocate should allocate both blocks involved. Test this by writing data to both bytes afterwards and see whether the on-disk size increases (it should not).
Signed-off-by Max Reitz <[email protected]>I notice that XFS fails this test with v5.3 kernel, so I guess this is a targeted regression test? Do you have a (pending) patch/commit that could be referenced in the commit log and/or test description? So we could know which patch/commit fixed this particular failure.
Yes, exactly. It’s "xfs: Fix tail rounding in xfs_alloc_file_space()”
(https://www.spinics.net/lists/linux-xfs/msg32174.html). I’ll add it to the commit message in v3.
Quoted 63 lines
Quoted 49 lines
---
v2:
- Use_get_file_block_sizeinstead of manual stat -fc '%S'
- Usexfs_ioinstead of fallocate/dd
(and require falloc support)
- Add the ' B' that was missing as allocated_size_after's unit in the error message--- tests/generic/568 | 63 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/568.out | 4 +++ tests/generic/group | 1 + 3 files changed, 68 insertions(+) create mode 100755 tests/generic/568 create mode 100644 tests/generic/568.outtests/generic/568 new file +28
-0@@ -0,0 +1,63 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2019 Red Hat, Inc. All Rights Reserved. +# +# FS QA Test No. generic/568 +# +# Test that fallocating an unaligned range allocates all blocks +# touched by that range +# +seq=$(basename $0) +seqres="$RESULT_DIR/$seq" +echo "QA output created by $seq" + +here=$PWD +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f "$tmp".* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +tests/generic/568 line 38
Quoted 10 lines
tests/generic/568 new file +10
-0+# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_scratch +_require_xfs_io_command "falloc" + +testfile="$SCRATCH_MNT/testfile" + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mountSeems you don't need $SCRATCH_DEV at all. Just create the test file on $TEST_DEV in $TEST_DIR, e.g.
Quoted 2 lines
testfile="$TEST_DIR"/falloctest-$seq
rm -f $testfile
OK, sure.
Quoted 38 lines
Quoted 38 lines
tests/generic/568 new file +25
-0+ +# Fallocate 2 bytes across a block boundary +block_size=$(_get_file_block_size "$SCRATCH_MNT") +$XFS_IO_PROG -f -c "falloc $((block_size - 1)) 2" "$testfile" + +# Both the first blocks should be allocated now. Check that by +# inquiring whether the file grows when we write to the two bytes we +# have just fallocated. + +allocated_size_before=$(($(stat -c '%b * %B' "$testfile"))) + +$XFS_IO_PROG -c "pwrite $((block_size - 1)) 2" "$testfile" \ + | _filter_xfs_io | sed -e "s/$((block_size - 1))/block_size - 1/" + +allocated_size_after=$(($(stat -c '%b * %B' "$testfile"))) + +if [ $allocated_size_after -gt $allocated_size_before ]; then + echo "ERROR: File grew from ${allocated_size_before} B to" \ + "${allocated_size_after} B when writing to the fallocated range." +else + echo "OK: File did not grow." +fi + +status=0 +exittests/generic/568.out new file +4
-0@@ -0,0 +1,4 @@ +QA output created by 568 +wrote 2/2 bytes at offset block_size - 1 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +OK: File did not grow.tests/generic/group +0
-1--- a/tests/generic/group
Quoted 8 lines
tests/generic/group line 573
Quoted 6 lines
+++ b/tests/generic/group
tests/generic/group +1
-0@@ -570,3 +570,4 @@ 565 auto quick copy_range 566 auto quick quota metadata 567 auto quick rw punch +568 auto quick rwAdd 'prealloc' group as well.
Will do.
Quoted 1 line
Thanks for the test!
Thanks for reviewing,
Max