From patchwork Tue Oct 15 02:51:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13835680 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C29A6AB8 for ; Tue, 15 Oct 2024 02:51:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728960690; cv=none; b=aJmP5LaVc9KEynAR1Hrmy5f4pIekUn39r7Q5EHDthiamIjx6UX3WsRr29oj5BNZridpTeiWOArR45PE6jCUdT4pcDqxe0Tu/cLcjWxZEjXQLqNQjbARpvBNcflVyHwBr5Jesd+nhXHBN8z0M0LAGR4YETxaDc97HUxp00AFB5EE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728960690; c=relaxed/simple; bh=Tk/AWN8N3hXZ7c5itZX1115sbx+Ry+VXv7ESB2Mj4wc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=JxLmBPZs/JhX1VBRwJVd2Wk6UTONVzJwxMpU7Jp5cHHXLbQ+gDPjJRxFhB0dRIgbcO65qycIFs/pUOBLWfZ/U1yrYfFc3+rIWBPKr5+CK6St9o16iV+NiQQwacLKCF2UM1crGqT7ZuXalhjAkzI9zngsQcfJaOX5NxlX7J53nu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NuIsZsQi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NuIsZsQi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7875AC4CEC3; Tue, 15 Oct 2024 02:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728960689; bh=Tk/AWN8N3hXZ7c5itZX1115sbx+Ry+VXv7ESB2Mj4wc=; h=From:To:Cc:Subject:Date:From; b=NuIsZsQiZCXwAyDb3AbPU44TCnAKmuX3wW86P4efeHQpjgjV9o6LAKfzNuUjE4F7z /EO9uSYMD2ux0xpQmNv1QmMiMsFJlX9pvtoVRiVXriler7UlH8WYUnW5IPycUnTb+q sgjehBdMNK4qoejxuNi/UvNTraagbbzsPxqviKtp4L+hELS08nEa4HNSEKlYIDnLtp BMrgUgMftgUccpBlWkA8ejjzLxDQJ2UMo1L0uDI5D3ynEsFXpk9408bR/axSPY45R7 n9kZAd/Ff6FbUPlweBBgytjejQRN/rrSk5W+NYgEksLVbcLxgxRZjJUYGvfxmTpmRY tN7HOOqxUqvnQ== From: Chao Yu To: Zorro Lang Cc: fstests@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Chao Yu , Jaegeuk Kim Subject: [PATCH 1/2] f2fs/006: add testcase to check out-of-space case Date: Tue, 15 Oct 2024 10:51:05 +0800 Message-Id: <20241015025106.3203676-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: fstests@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is a regression test to check whether f2fs handles dirty data correctly when checkpoint is disabled, if lfs mode is on, it will trigger OPU for all overwritten data, this will cost free segments, so f2fs must account overwritten data as OPU data when calculating free space, otherwise, it may run out of free segments in f2fs' allocation function, resulting in panic. Cc: Jaegeuk Kim Signed-off-by: Chao Yu --- tests/f2fs/006 | 52 ++++++++++++++++++++++++++++++++++++++++++++++ tests/f2fs/006.out | 6 ++++++ 2 files changed, 58 insertions(+) create mode 100755 tests/f2fs/006 create mode 100644 tests/f2fs/006.out diff --git a/tests/f2fs/006 b/tests/f2fs/006 new file mode 100755 index 00000000..b359ef8f --- /dev/null +++ b/tests/f2fs/006 @@ -0,0 +1,52 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oppo. All Rights Reserved. +# +# FS QA Test No. f2fs/006 +# +# This is a regression test to check whether f2fs handles dirty +# data correctly when checkpoint is disabled, if lfs mode is on, +# it will trigger OPU for all overwritten data, this will cost +# free segments, so f2fs must account overwritten data as OPU +# data when calculating free space, otherwise, it may run out +# of free segments in f2fs' allocation function, resulting in +# panic. +# +. ./common/preamble +_begin_fstest auto quick + +_cleanup() +{ + rm -f $img + _scratch_unmount >> $seqres.full + cd / + rm -r -f $tmp.* +} + +_require_scratch +_scratch_mkfs >> $seqres.full +_scratch_mount >> $seqres.full + +img=$SCRATCH_MNT/f2fs.img +mnt=$SCRATCH_MNT/f2fs.mnt +testfile=$mnt/testfile + +mkdir $mnt +dd if=/dev/zero of=$img bs=1M count=100 2>/dev/null +$MKFS_F2FS_PROG -f $img >/dev/null 2>&1 +sync + +# use mode=lfs to let f2fs always triggers OPU +mount -t $FSTYP -o loop,mode=lfs,checkpoint=disable:10%,noinline_dentry $img $mnt + +dd if=/dev/zero of=$testfile bs=1M count=50 2>/dev/null + +# it may run out of free space of f2fs and hang kernel +dd if=/dev/zero of=$testfile bs=1M count=50 conv=notrunc conv=fsync +dd if=/dev/zero of=$testfile bs=1M count=50 conv=notrunc conv=fsync + +mount -o remount,checkpoint=enable $mnt +umount $mnt + +status=0 +exit diff --git a/tests/f2fs/006.out b/tests/f2fs/006.out new file mode 100644 index 00000000..a2c7ba48 --- /dev/null +++ b/tests/f2fs/006.out @@ -0,0 +1,6 @@ +QA output created by 006 +50+0 records in +50+0 records out +dd: error writing '/mnt/scratch_f2fs/f2fs.mnt/testfile': No space left on device +3+0 records in +2+0 records out From patchwork Tue Oct 15 02:51:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13835681 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 201236AB8 for ; Tue, 15 Oct 2024 02:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728960692; cv=none; b=PJhF9J6+KW5yCiTWmpTugWDFZLOpoAGpnobAo5Omt2ZJaXvg0iKLgS30l0oZEVo34rzOaaY8wa9RgustzcZPbDpE7NUKj7wCKrara8eTFZvxQjl3NggISnnsE8+MFMcnWreVtR0ioAlkCK4A57zBWK8Fd9CnM67jtlbNfxR75CY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728960692; c=relaxed/simple; bh=Y05EfT0ASAjNhTImYRlNb+wZ7uQbgocCROAhY9S4ZAU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YR6SadNA55cEzAk6667dFw1Z0govst9BAyBiwTbHdM5lWW+JWpXFdm3E+uv5Djukn7mnMA6OSIEmbd8XMujWOqE/6n5LLvRHeoungoCfwch7d/8aBDtM4YE+MFrh+UR1e70VR9V4b3TXTHvwsgn3Ua5KFGHmPI09L9iz0wrdFUg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KWKKJK7v; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KWKKJK7v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F8F1C4CED0; Tue, 15 Oct 2024 02:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728960691; bh=Y05EfT0ASAjNhTImYRlNb+wZ7uQbgocCROAhY9S4ZAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KWKKJK7vFQn9sRsbVTHVJFDV0KhaqMyDA65XyYsIdE6xEcXx7KE3wklyotJ7CET06 6bIvhp+iaxew4tV+3FuQnvzI2Cz82mURHKCzMd2su6As/Davr92etlVH8Xe9uLxCjG 6lhQ+Ts+YgrJmNCUhLj/8lgcZJR8p7ShTrnXW0VqRTQRrLlNN0BOPhGzGQV1Dt3km1 aS8BfKruyBeHgn8c0JDh/3YJY7T/QLWs8r3kgice8P/2ImNvHZLDr4IuWgB5V8PTey jhomZNcd/L+UrZWWjPGOxrkDdyRAKrNi+q3HpurZl6wM3p50ASaWu12Ud/75XG+KW5 ++/itwbhoM0Mg== From: Chao Yu To: Zorro Lang Cc: fstests@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Chao Yu , Jaegeuk Kim , Qi Han Subject: [PATCH 2/2] f2fs/007: add testcase to check consistency of compressed inode metadata Date: Tue, 15 Oct 2024 10:51:06 +0800 Message-Id: <20241015025106.3203676-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20241015025106.3203676-1-chao@kernel.org> References: <20241015025106.3203676-1-chao@kernel.org> Precedence: bulk X-Mailing-List: fstests@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Cc: Qi Han Signed-off-by: Chao Yu --- 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..274be806 --- /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 + +_cleanup() +{ + cd / + rm -r -f tmp.* +} + +testfile_prefix=$SCRATCH_MNT/testfile +fio_config=$tmp.fio + +cat >$fio_config <> $seqres.full +_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 + +for i in 30 60 90; do + testfile=$testfile_prefix$i + + _scratch_mount "-o compress_mode=user" >> $seqres.full + f2fs_io compress $testfile >> $seqres.full + cblocks=`f2fs_io get_cblocks $testfile` + echo "compression ratio is: "$cblocks" / 256" + + _scratch_unmount + + # 1. check after compression + fsck -t $FSTYP -f $SCRATCH_DEV >> $seqres.full + if [ $? -ne 0 ]; then + _fail "filesystem becomes corrupted after compress" + fi + + _scratch_mount >> $seqres.full + f2fs_io release_cblocks $testfile >> $seqres.full + _scratch_unmount + + # 2. check after releasement + fsck -t $FSTYP -f $SCRATCH_DEV >> $seqres.full + if [ $? -ne 0 ]; then + _fail "filesystem becomes corrupted after release_cblocks" + fi + + _scratch_mount >> $seqres.full + f2fs_io reserve_cblocks $testfile >> $seqres.full + _scratch_unmount + + # 3. check after rservation + fsck -t $FSTYP -f $SCRATCH_DEV >> $seqres.full + if [ $? -ne 0 ]; then + _fail "filesystem becomes corrupted after reserve_cblocks" + fi + + _scratch_mount "-o compress_mode=user" >> $seqres.full + f2fs_io decompress $testfile >> $seqres.full + _scratch_unmount + + # 4. check after decompression + fsck -t $FSTYP -f $SCRATCH_DEV >> $seqres.full + if [ $? -ne 0 ]; then + _fail "filesystem becomes corrupted after decompress" + fi +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