f2fs/013: test to check potential corruption on atomic_write file
PATCH 1/1 f2fs/013: test to check potential corruption on atomic_write file
This is a regression testcase to check whether we will handle database inode dirty status correctly:
1. make sure disk quota is enabled
2. create a regular file, and write data into the file
3. start transaction on the file (via F2FS_IOC_START_ATOMIC_WRITE)
4. write transaction data to the file
5. commit and end the transaction (via F2FS_IOC_COMMIT_ATOMIC_WRITE)
6. meanwhile loop call fsync in parallel
Before f098aeba04c9 ("f2fs: fix to avoid atomicity corruption of atomic file"), database file may become corrupted after atomic write while there is concurrent dirty inode flush in background.
--- tests/f2fs/013 | 73 ++++++++++++++++++++++++++++++++++++++++++++++ tests/f2fs/013.out | 2 ++ 2 files changed, 75 insertions(+) create mode 100755 tests/f2fs/013 create mode 100644 tests/f2fs/013.out
tests/f2fs/013 new file +73 -0
@@ -0,0 +1,73 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2025 Chao Yu. All Rights Reserved. +# +# FS QA Test No. f2fs/013 +# +# This is a regression testcase to check whether we will handle database +# inode dirty status correctly: +# 1. make sure disk quota is enabled +# 2. create a regular file, and write data into the file +# 3. start transaction on the file (via F2FS_IOC_START_ATOMIC_WRITE) +# 4. write transaction data to the file +# 5. commit and end the transaction (via F2FS_IOC_COMMIT_ATOMIC_WRITE) +# 6. meanwhile loop call fsync in parallel +# Before f098aeba04c9 ("f2fs: fix to avoid atomicity corruption of atomic +# file"), database file may become corrupted after atomic write while +# there is concurrent dirty inode flush in background. +# +. ./common/preamble +_begin_fstest auto quick + +_cleanup() +{ + [ -n "$atomic_write_pid" ] && kill -9 $atomic_write_pid + wait + cd / + rm -r -f $tmp.* +} + +_fixed_by_kernel_commit f098aeba04c9 \ + "f2fs: fix to avoid atomicity corruption of atomic file" + +_require_scratch + +_scratch_mkfs >> $seqres.full +# note that it relis on FAULT_TIMEOUT fault injection support in f2fs +_scratch_mount "-o fault_injection=1,fault_type=4194304" >> $seqres.full + +dbfile=$SCRATCH_MNT/file.db + +# initialize database file +$XFS_IO_PROG -c "pwrite 0 4k" -c "fsync" -f $dbfile >> $seqres.full + +# sync filesystem to clear dirty inode +sync + +# start atomic_write on src.db database file and commit transaction +$F2FS_IO_PROG write 1 0 2 zero atomic_commit $dbfile >> $seqres.full & +atomic_write_pid=$! + +# call fsync to flush dirty inode of database file in parallel +for ((j=0;j<1000;j++)) do + $F2FS_IO_PROG fsync $dbfile >> $seqres.full +done + +wait $atomic_write_pid +unset atomic_write_pid + +# flush dirty data and drop cache +sync +echo 3 > /proc/sys/vm/drop_caches + +newsize=`stat $dbfile -c %s` +if [ "$newsize" != "8192" ]; then + _fail "filesize is inconsistent:"$newsize +fi +rm $dbfile +sync + +echo "Silence is golden" + +status=0 +exit
tests/f2fs/013.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 013 +Silence is golden
Signature · 1 line
2.49.0
Hi Chao Yu,
Quoted 28 lines · Chao Yu
This is a regression testcase to check whether we will handle database inode dirty status correctly:
1. make sure disk quota is enabled
2. create a regular file, and write data into the file
3. start transaction on the file (viaF2FS_IOC_START_ATOMIC_WRITE)
4. write transaction data to the file
5. commit and end the transaction (viaF2FS_IOC_COMMIT_ATOMIC_WRITE)
6. meanwhile loop call fsync in parallel
Beforef098aeba04c9("f2fs: fix to avoid atomicity corruption of atomic file"), database file may become corrupted after atomic write while there is concurrent dirty inode flush in background.Cc Jaegeuk Kim <[email protected]>Cc Daeho Jeong <[email protected]>Signed-off-by Chao Yu <[email protected]>--- tests/f2fs/013 | 73 ++++++++++++++++++++++++++++++++++++++++++++++ tests/f2fs/013.out | 2 ++ 2 files changed, 75 insertions(+) create mode 100755 tests/f2fs/013 create mode 100644 tests/f2fs/013.outtests/f2fs/013 new file +0
-0
tests/f2fs/013 line 9
Quoted 9 lines
tests/f2fs/013 new file +9
-0@@ -0,0 +1,73 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2025 Chao Yu. All Rights Reserved. +# +# FS QA Test No. f2fs/013 +# +# This is a regression testcase to check whether we will handle database +# inode dirty status correctly: +# 1. make sure disk quota is enabled
Where is the check that disk quota is enabled?
Quoted 18 lines
tests/f2fs/013 new file +18
-0+# 2. create a regular file, and write data into the file +# 3. start transaction on the file (via F2FS_IOC_START_ATOMIC_WRITE) +# 4. write transaction data to the file +# 5. commit and end the transaction (via F2FS_IOC_COMMIT_ATOMIC_WRITE) +# 6. meanwhile loop call fsync in parallel +# Before f098aeba04c9 ("f2fs: fix to avoid atomicity corruption of atomic +# file"), database file may become corrupted after atomic write while +# there is concurrent dirty inode flush in background. +# +. ./common/preamble +_begin_fstest auto quick + +_cleanup() +{ + [ -n "$atomic_write_pid" ] && kill -9 $atomic_write_pid + wait + cd / + rm -r -f $tmp.*
tests/f2fs/013 line 37
Quoted 10 lines
tests/f2fs/013 new file +10
-0+} + +_fixed_by_kernel_commit f098aeba04c9 \ + "f2fs: fix to avoid atomicity corruption of atomic file" + +_require_scratch + +_scratch_mkfs >> $seqres.full +# note that it relis on FAULT_TIMEOUT fault injection support in f2fs +_scratch_mount "-o fault_injection=1,fault_type=4194304" >> $seqres.full
This requires CONFIG_F2FS_FAULT_INJECTION=y, although now I see that parse_options() just ignores them and the test still passes fine with CONFIG_F2FS_FAULT_INJECTION unset. Does it make sense to run without FAULT_TIMEOUT injection? It'd likely make sense to just _notrun if fault injection is unavailable.
Quoted 18 lines
tests/f2fs/013 new file +18
-0+dbfile=$SCRATCH_MNT/file.db + +# initialize database file +$XFS_IO_PROG -c "pwrite 0 4k" -c "fsync" -f $dbfile >> $seqres.full + +# sync filesystem to clear dirty inode +sync + +# start atomic_write on src.db database file and commit transaction +$F2FS_IO_PROG write 1 0 2 zero atomic_commit $dbfile >> $seqres.full & +atomic_write_pid=$! + +# call fsync to flush dirty inode of database file in parallel +for ((j=0;j<1000;j++)) do + $F2FS_IO_PROG fsync $dbfile >> $seqres.full +done + +wait $atomic_write_pid
tests/f2fs/013 line 66
Quoted 10 lines
tests/f2fs/013 new file +10
-0+unset atomic_write_pid + +# flush dirty data and drop cache +sync +echo 3 > /proc/sys/vm/drop_caches + +newsize=`stat $dbfile -c %s` +if [ "$newsize" != "8192" ]; then + _fail "filesize is inconsistent:"$newsize +fi
nit: I think it'd be simpler to do:
stat $dbfile -c %s
...and just put the 8192 in the golden output.
Quoted 15 lines
tests/f2fs/013 new file +7
-0+rm $dbfile +sync + +echo "Silence is golden" + +status=0 +exittests/f2fs/013.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 013 +Silence is golden
Hi David,
Quoted 35 lines · David Disseldorp
Hi Chao Yu,
Quoted 31 lines · Chao Yu
This is a regression testcase to check whether we will handle database inode dirty status correctly:
1. make sure disk quota is enabled
2. create a regular file, and write data into the file
3. start transaction on the file (viaF2FS_IOC_START_ATOMIC_WRITE)
4. write transaction data to the file
5. commit and end the transaction (viaF2FS_IOC_COMMIT_ATOMIC_WRITE)
6. meanwhile loop call fsync in parallel
Beforef098aeba04c9("f2fs: fix to avoid atomicity corruption of atomic file"), database file may become corrupted after atomic write while there is concurrent dirty inode flush in background.Cc Jaegeuk Kim <[email protected]>Cc Daeho Jeong <[email protected]>Signed-off-by Chao Yu <[email protected]>--- tests/f2fs/013 | 73 ++++++++++++++++++++++++++++++++++++++++++++++ tests/f2fs/013.out | 2 ++ 2 files changed, 75 insertions(+)create mode 100755 tests/f2fs/013
create mode 100644 tests/f2fs/013.outtests/f2fs/013 new file +3
-0@@ -0,0 +1,73 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2025 Chao Yu. All Rights Reserved.
Quoted 8 lines
tests/f2fs/013 line 9
Quoted 6 lines
tests/f2fs/013 new file +6
-0+# +# FS QA Test No. f2fs/013 +# +# This is a regression testcase to check whether we will handle database +# inode dirty status correctly: +# 1. make sure disk quota is enabledWhere is the check that disk quota is enabled?
Oh, I tested this testcase, it passed no matter disk quota on or off, let me remove this description.
Quoted 27 lines
Quoted 27 lines
tests/f2fs/013 new file +26
-0+# 2. create a regular file, and write data into the file +# 3. start transaction on the file (via F2FS_IOC_START_ATOMIC_WRITE) +# 4. write transaction data to the file +# 5. commit and end the transaction (via F2FS_IOC_COMMIT_ATOMIC_WRITE) +# 6. meanwhile loop call fsync in parallel +# Before f098aeba04c9 ("f2fs: fix to avoid atomicity corruption of atomic +# file"), database file may become corrupted after atomic write while +# there is concurrent dirty inode flush in background. +# +. ./common/preamble +_begin_fstest auto quick + +_cleanup() +{ + [ -n "$atomic_write_pid" ] && kill -9 $atomic_write_pid + wait + cd / + rm -r -f $tmp.* +} + +_fixed_by_kernel_commit f098aeba04c9 \ + "f2fs: fix to avoid atomicity corruption of atomic file" + +_require_scratch + +_scratch_mkfs >> $seqres.full
Quoted 8 lines
tests/f2fs/013 line 37
Quoted 2 lines
tests/f2fs/013 new file +2
-0+# note that it relis on FAULT_TIMEOUT fault injection support in f2fs +_scratch_mount "-o fault_injection=1,fault_type=4194304" >> $seqres.fullThis requires
CONFIG_F2FS_FAULT_INJECTION=y, although now I see thatparse_options()just ignores them and the test still passes fine withCONFIG_F2FS_FAULT_INJECTIONunset. Does it make sense to run withoutFAULT_TIMEOUTinjection? It'd likely make sense to just_notrunif fault injection is unavailable.
Yes, the testcase relies on CONFIG_F2FS_FAULT_INJECTION, let me add a requirement condition for that.
If FAULT_TIMEOUT injection is not supported, mount() will fail.
Quoted 25 lines
Quoted 25 lines
tests/f2fs/013 new file +24
-0+dbfile=$SCRATCH_MNT/file.db + +# initialize database file +$XFS_IO_PROG -c "pwrite 0 4k" -c "fsync" -f $dbfile >> $seqres.full + +# sync filesystem to clear dirty inode +sync + +# start atomic_write on src.db database file and commit transaction +$F2FS_IO_PROG write 1 0 2 zero atomic_commit $dbfile >> $seqres.full & +atomic_write_pid=$! + +# call fsync to flush dirty inode of database file in parallel +for ((j=0;j<1000;j++)) do + $F2FS_IO_PROG fsync $dbfile >> $seqres.full +done + +wait $atomic_write_pid +unset atomic_write_pid + +# flush dirty data and drop cache +sync +echo 3 > /proc/sys/vm/drop_caches +
Quoted 8 lines
tests/f2fs/013 line 66
Quoted 4 lines
tests/f2fs/013 new file +4
-0+newsize=`stat $dbfile -c %s` +if [ "$newsize" != "8192" ]; then + _fail "filesize is inconsistent:"$newsize +finit: I think it'd be simpler to do:
stat $dbfile -c %s
...and just put the 8192 in the golden output.
Looks fine to me.
Thanks for the review, let me revise all in v2.
Thanks,
Quoted 17 lines
Quoted 16 lines
tests/f2fs/013 new file +7
-0+rm $dbfile +sync + +echo "Silence is golden" + +status=0 +exittests/f2fs/013.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 013 +Silence is golden