On 2024/10/25 11:58, Zorro Lang wrote:
On Wed, Oct 23, 2024 at 04:16:02PM +0800, Chao Yu wrote:
metadata of compressed inode should always be consistent after file
compression, reservation, releasement and decompression, let's add
a testcase to check it.
Cc: Jaegeuk Kim <jaegeuk@xxxxxxxxxx>
Cc: Qi Han <hanqi@xxxxxxxx>
Signed-off-by: Chao Yu <chao@xxxxxxxxxx>
---
v2:
- add _fixed_by_kernel_commit()
- code cleanup
- add error handling for _scratch_mkfs()
tests/f2fs/007 | 116 +++++++++++++++++++++++++++++++++++++++++++++
tests/f2fs/007.out | 4 ++
2 files changed, 120 insertions(+)
create mode 100755 tests/f2fs/007
create mode 100644 tests/f2fs/007.out
diff --git a/tests/f2fs/007 b/tests/f2fs/007
new file mode 100755
index 00000000..8979c21c
--- /dev/null
+++ b/tests/f2fs/007
@@ -0,0 +1,116 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2024 Oppo. All Rights Reserved.
+#
+# FS QA Test No. f2fs/007
+#
+# This is a regression test to check whether compressed metadata
+# can become inconsistent after file compression, reservation
+# releasement, and decompression.
+#
+. ./common/preamble
+_begin_fstest auto quick rw compress
+
+_fixed_by_kernel_commit xxxxxxxxxxxx \
+ "f2fs: compress: fix inconsistent update of i_blocks in release_compress_blocks and reserve_compress_blocks"
+
+testfile_prefix=$SCRATCH_MNT/testfile
+fio_config=$tmp.fio
+
+cat >$fio_config <<EOF
+[write_compressed_data_30]
+name=mytest
+ioengine=psync
+rw=write
+direct=0
+bs=1M
+filesize=1M
+numjobs=1
+filename=${testfile_prefix}30
+buffer_compress_percentage=30
+
+[write_compressed_data_60]
+name=mytest
+ioengine=psync
+rw=write
+direct=0
+bs=1M
+filesize=1M
+numjobs=1
+filename=${testfile_prefix}60
+buffer_compress_percentage=60
+
+[write_compressed_data_90]
+name=mytest
+ioengine=psync
+rw=write
+direct=0
+bs=1M
+filesize=1M
+numjobs=1
+filename=${testfile_prefix}90
+buffer_compress_percentage=90
+EOF
+
+_require_scratch
Better to move _require_scratch before "testfile_prefix=$SCRATCH_MNT/testfile".
Due to we'd better to make sure there's $SCRATCH_MNT, before using it.
+_require_fio $fio_config
+_scratch_mkfs "-f -O extra_attr,compression" >> $seqres.full || _fail "mkfs failed"
+_scratch_mount "-o compress_mode=user,compress_extension=*" >> $seqres.full
+
+echo -e "Run fio to initialize file w/ specified compress ratio" >> $seqres.full
+cat $fio_config >> $seqres.full
+$FIO_PROG $fio_config >> $seqres.full
+_scratch_unmount
+
+# force to repaire if filesystem is corrupted
+export FSCK_OPTIONS="-f $FSCK_OPTIONS"
+
+for i in 30 60 90; do
+ testfile=$testfile_prefix$i
+
+ _scratch_mount "-o compress_mode=user" >> $seqres.full
+ $F2FS_IO_PROG compress $testfile >> $seqres.full
+ cblocks=`$F2FS_IO_PROG get_cblocks $testfile`
+ echo "compression ratio is: "$cblocks" / 256"
+
+ _scratch_unmount
+
+ # 1. check after compression
+ _check_scratch_fs
+ if [ $? -ne 0 ]; then
+ _fail "filesystem becomes corrupted after compress"
+ fi
+
+ _scratch_mount >> $seqres.full
+ $F2FS_IO_PROG release_cblocks $testfile >> $seqres.full
+ _scratch_unmount
+
+ # 2. check after releasement
+ _check_scratch_fs
+ if [ $? -ne 0 ]; then
+ _fail "filesystem becomes corrupted after release_cblocks"
The _fail is not necessary, due to _check_scratch_fs will do "exit 1"
if it find a corruption. If you need some message, maybe echo it before
calling _check_scratch_fs?
+ fi
+
+ _scratch_mount >> $seqres.full
+ $F2FS_IO_PROG reserve_cblocks $testfile >> $seqres.full
+ _scratch_unmount
+
+ # 3. check after rservation
+ _check_scratch_fs
+ if [ $? -ne 0 ]; then
+ _fail "filesystem becomes corrupted after reserve_cblocks"
+ fi
Same as above
+
+ _scratch_mount "-o compress_mode=user" >> $seqres.full
+ $F2FS_IO_PROG decompress $testfile >> $seqres.full
+ _scratch_unmount
+
+ # 4. check after decompression
+ _check_scratch_fs
+ if [ $? -ne 0 ]; then
+ _fail "filesystem becomes corrupted after decompress"
+ fi
Same as above.
Okay, let me update the patch.
Thanks,
Thanks,
Zorro
+done
+
+status=0
+exit
diff --git a/tests/f2fs/007.out b/tests/f2fs/007.out
new file mode 100644
index 00000000..2ea71c18
--- /dev/null
+++ b/tests/f2fs/007.out
@@ -0,0 +1,4 @@
+QA output created by 007
+compression ratio is: 64 / 256
+compression ratio is: 128 / 256
+compression ratio is: 192 / 256
--
2.40.1