From patchwork Wed Dec 20 13:59:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13500144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7A90C46CD3 for ; Wed, 20 Dec 2023 14:00:00 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rFx7B-0008VJ-6c; Wed, 20 Dec 2023 14:00:00 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rFx78-0008VC-Eo for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 13:59:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xscjI8hRCqb0TVF/ZPOmL17Fu99hTNWTrn2y8jLUfpo=; b=KBVl7CSN/EE+Wi5GmKOCePYZR0 zUBRKxiNoius2Inumq/35ElhR3lEXqKMJRVOaOUmvv/SMvQu7fOVyqSkt6FswNfqLJ/PAX3Kbfm6U YG97NjzYnYPDb63+pGpXjR1gNMlDKkHmo2UUj7lafqYg7co/uFqpkxjniseHfft+jX30=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=xscjI8hRCqb0TVF/ZPOmL17Fu99hTNWTrn2y8jLUfpo=; b=f wAxpMUO4mr/+mfGirDpmYtykoLAHZuYm+H7pLilqoyiCJB3U/HtSQFlEzCqtegwlaTeio+Htkt3Mf GBjMUB8fPP+50szzBQCJjMXvhcwUWCwjcn+Iq7FzrwgLNhSovzZ+7V0NtFm+/73GVwA0pXpz7jY0O etErDV2LQtTuupx0=; Received: from ams.source.kernel.org ([145.40.68.75]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rFx73-0001Jm-QT for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 13:59:57 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 88FF9B81D6F for ; Wed, 20 Dec 2023 13:59:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C1FAC433C9; Wed, 20 Dec 2023 13:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080781; bh=1NoN4vHX+F5B0WJZK8QqQakY9pc1N432/Yr899L6umA=; h=From:To:Cc:Subject:Date:From; b=LsflaQn/Rpi1r63bTcKQzLAw6EfRwK9cBsHYh2in+KK6g6cuNWDLwdAppjiihuRPE DUh1q6tb8kH/p+aNjHZGtKNGSH47k8IPkYzKP1KYu9+0v6RJW9cTl6gIw36PkVv7lw VcsmWYBHfZG++2ANDm7PwM6g65zOvG4hJTdrQnghgTb9b4WYEfLk3Qu0OhvwA43clV Av9IjNnnAYkKuVB9Mrhv/RPZ1MisWBUU3Mqe2X18y/hrGur6vgPHhJLLSAqG4yf/fk mAlr/bWMlcn5tyW61vmyqOfPqRrpT4HS2QuDhkI1ZzpaIhtg/qFQ/3qogGw6ItMCVg QFUKONcK8dPLA== From: Chao Yu To: jaegeuk@kernel.org Date: Wed, 20 Dec 2023 21:59:29 +0800 Message-Id: <20231220135934.3471407-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Headers-End: 1rFx73-0001Jm-QT Subject: [f2fs-dev] [PATCH 1/6] f2fs: compress: fix to guarantee persisting compressed blocks by CP X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net If data block in compressed cluster is not persisted with metadata during checkpoint, after SPOR, the data may be corrupted, let's guarantee to write compressed page by checkpoint. Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Chao Yu --- fs/f2fs/compress.c | 3 ++- fs/f2fs/data.c | 12 +++++++++--- fs/f2fs/f2fs.h | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 5b076329e9bf..1122db8cc0b0 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1442,6 +1442,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) struct f2fs_sb_info *sbi = bio->bi_private; struct compress_io_ctx *cic = (struct compress_io_ctx *)page_private(page); + enum count_type type = WB_DATA_TYPE(page); int i; if (unlikely(bio->bi_status)) @@ -1449,7 +1450,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) f2fs_compress_free_page(page); - dec_page_count(sbi, F2FS_WB_DATA); + dec_page_count(sbi, type); if (atomic_dec_return(&cic->pending_pages)) return; diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index d28c97282e68..6c72a6e86ba8 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -48,7 +48,7 @@ void f2fs_destroy_bioset(void) bioset_exit(&f2fs_bioset); } -static bool __is_cp_guaranteed(struct page *page) +bool f2fs_is_cp_guaranteed(struct page *page) { struct address_space *mapping = page->mapping; struct inode *inode; @@ -66,7 +66,7 @@ static bool __is_cp_guaranteed(struct page *page) return true; if (f2fs_is_compressed_page(page)) - return false; + return true; if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || page_private_gcing(page)) return true; @@ -1007,6 +1007,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp; struct page *bio_page; + enum count_type type; f2fs_bug_on(sbi, is_read_io(fio->op)); @@ -1046,7 +1047,12 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) /* set submitted = true as a return value */ fio->submitted = 1; - inc_page_count(sbi, WB_DATA_TYPE(bio_page)); + type = WB_DATA_TYPE(bio_page); + /* override count type if page is compressed one */ + if (fio->compressed_page) + type = WB_DATA_TYPE(fio->compressed_page); + + inc_page_count(sbi, type); if (io->bio && (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 76e9a8682e38..bcb3940ab5ba 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1092,7 +1092,7 @@ struct f2fs_sm_info { * f2fs monitors the number of several block types such as on-writeback, * dirty dentry blocks, dirty node blocks, and dirty meta blocks. */ -#define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) +#define WB_DATA_TYPE(p) (f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) enum count_type { F2FS_DIRTY_DENTS, F2FS_DIRTY_DATA, @@ -3824,6 +3824,7 @@ void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi); */ int __init f2fs_init_bioset(void); void f2fs_destroy_bioset(void); +bool f2fs_is_cp_guaranteed(struct page *page); int f2fs_init_bio_entry_cache(void); void f2fs_destroy_bio_entry_cache(void); void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio, From patchwork Wed Dec 20 13:59:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13500142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE7D1C3DA6E for ; Wed, 20 Dec 2023 13:59:59 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rFx78-0001Mu-2u; Wed, 20 Dec 2023 13:59:58 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rFx76-0001Mo-0M for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 13:59:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=c4fyeCY1wp5FzjpWoC3wK9/lThvHooCDuVfznyQFUsA=; b=PoCyvRTZoX2KVnmP7gzc7m9wNw hYh8swFgEB8lv9EFtnLoB7JWqxQQhJWtrtYkn3EizUmKWpdP5HXWVSqNEL+Sa8ZzRsWQrWG+y+Fjh FTYorxKER/ho4XgFx0ur7Xc810SvLqlTQLDWHB0l6xP0gE2SF2QIx5enHQqHsBOMa2z4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=c4fyeCY1wp5FzjpWoC3wK9/lThvHooCDuVfznyQFUsA=; b=QtBRg8xPw2wjERi0GUpO5bXbS0 oNVCehSILaQKpm9/437ckJ30OTh0v8rKwVGwZQX96yVcZc2WQWbtLQlw7upYif9+dqRxMmhKIKNlV dyvuXTx2nizA7gpHQO5uC7Eq7xR/nkOb3nRigNM8HjSyEPSadyRmry7PZkybB1kJ8yus=; Received: from ams.source.kernel.org ([145.40.68.75]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rFx70-0001Je-II for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 13:59:56 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 45328B81D70 for ; Wed, 20 Dec 2023 13:59:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A60EC433CC; Wed, 20 Dec 2023 13:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080783; bh=HlIylD6IwGlkcvAcDhSn7XsD9KaF9Cn4cGLKY52iKZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VAx8QlLM9/SAVXDNxAz7Vm0DbGUGFuklAUi9oWrXB2siqcfYl9r8e7XOChcN4D/Qt xYOXSp7QxrttGDBWDLva4C/KR4QUc1uVnnB3taBjsdab4tRRz9aoM6eOn8KHhUSRik yoI1q/DaZ6Rv6lxN854d+RSSfV6XwtjZuKMsK5veySxq7mflzYcUwhBxKHMi4jqYmX yJHnbh4DQqEp3u57DtS2hcfwgTmo8WaZFLQPO2C1UE7qlbZBgy8xQKwrtfvailz4xi u6VpYHaTbn/olibbEvjwuTOfzOEJU+wehVd/hMyg+dYY6ZF/GPdoNGGiiF7L37IXvs kKXTwkHTljw3A== From: Chao Yu To: jaegeuk@kernel.org Date: Wed, 20 Dec 2023 21:59:30 +0800 Message-Id: <20231220135934.3471407-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231220135934.3471407-1-chao@kernel.org> References: <20231220135934.3471407-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1rFx70-0001Je-II Subject: [f2fs-dev] [PATCH 2/6] f2fs: compress: fix to cover normal cluster write with cp_rwsem X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net When we overwrite compressed cluster w/ normal cluster, we should not unlock cp_rwsem during f2fs_write_raw_pages(), otherwise data will be corrupted if partial blocks were persisted before CP & SPOR, due to cluster metadata wasn't updated atomically. Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Chao Yu --- fs/f2fs/compress.c | 20 ++++++++++++++------ fs/f2fs/data.c | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 1122db8cc0b0..a1426c3eadcc 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1471,7 +1471,8 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, enum iostat_type io_type) { struct address_space *mapping = cc->inode->i_mapping; - int _submitted, compr_blocks, ret, i; + struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); + int _submitted, compr_blocks, ret = 0, i; compr_blocks = f2fs_compressed_blocks(cc); @@ -1486,6 +1487,10 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, if (compr_blocks < 0) return compr_blocks; + /* overwrite compressed cluster w/ normal cluster */ + if (compr_blocks > 0) + f2fs_lock_op(sbi); + for (i = 0; i < cc->cluster_size; i++) { if (!cc->rpages[i]) continue; @@ -1518,26 +1523,29 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, unlock_page(cc->rpages[i]); ret = 0; } else if (ret == -EAGAIN) { + ret = 0; /* * for quota file, just redirty left pages to * avoid deadlock caused by cluster update race * from foreground operation. */ if (IS_NOQUOTA(cc->inode)) - return 0; - ret = 0; + goto out; f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT); goto retry_write; } - return ret; + goto out; } *submitted += _submitted; } - f2fs_balance_fs(F2FS_M_SB(mapping), true); +out: + if (compr_blocks > 0) + f2fs_unlock_op(sbi); - return 0; + f2fs_balance_fs(sbi, true); + return ret; } int f2fs_write_multi_pages(struct compress_ctx *cc, diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 6c72a6e86ba8..ceed5ac6c66b 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2848,7 +2848,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, .encrypted_page = NULL, .submitted = 0, .compr_blocks = compr_blocks, - .need_lock = LOCK_RETRY, + .need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY, .post_read = f2fs_post_read_required(inode) ? 1 : 0, .io_type = io_type, .io_wbc = wbc, @@ -2929,6 +2929,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, if (err == -EAGAIN) { err = f2fs_do_write_data_page(&fio); if (err == -EAGAIN) { + f2fs_bug_on(sbi, compr_blocks); fio.need_lock = LOCK_REQ; err = f2fs_do_write_data_page(&fio); } From patchwork Wed Dec 20 13:59:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13500143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C2EAC46CD2 for ; Wed, 20 Dec 2023 14:00:00 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rFx78-0000tH-GW; Wed, 20 Dec 2023 13:59:59 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rFx76-0000t8-HW for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 13:59:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=PG5vzWF2/Zst7Rv4M9EAEkwmGP1h2Y/muDmldfhvo/c=; b=BC/tvC/Klc3yWWFVd0TUHyDkhF cJR3bbgAybL0ejTk7t1oZKOxtw5y71iw4tTdSNdzlRW5AvJuLTy3+TdWYrhZx9VZ6kTnlFs4PFLz1 J4+W577r+FVU986pTOVQ9xrtZfuxQkkbF1FlIiB6nX3FvE7/HNUCOgUTnJczKglAXCH4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=PG5vzWF2/Zst7Rv4M9EAEkwmGP1h2Y/muDmldfhvo/c=; b=kLQBSnZNMIKKjW7ZaK12+yHpWq DPG8UH3vDvl8QYInjirF6xh2Sc2s+c45Wg4GQ1pb2D3X0o6qbz8BDZlbpTaJ5ETk7pVSJANsud7WD jfDqdHATgUmOI7rV+lHqg4mv24+/JIErq4KCvFGf5PPHlF+9aqfifYybA7PiEgJ8+70g=; Received: from ams.source.kernel.org ([145.40.68.75]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rFx72-0001Jj-Pm for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 13:59:57 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 80107B81D6D; Wed, 20 Dec 2023 13:59:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8229AC433C9; Wed, 20 Dec 2023 13:59:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080786; bh=v4LG7qKqe/M+w+R9MpQa9X4bJKEDltOmx7SXeOQu0+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OL7AZ7SRexIAReodySDXML3iH2ENLvevRKCZBxFla/XCSj4J9zJLC1wtYmtdpbRlk gw89uKyBFqkPsyV4hoNrqupk4BsEgh5LsguNh4j3c2o21x/mEzvpCvKSmmqQdwl0B1 xvVuzC23KncXqWNCUTWuY1Qa9RzkARpusQnqsCPKN1dYS4LT/8CzWncLobPQYMEfMJ 54ptx4MbXrSvaUFIXL6OZoAkmy/1YRQYAYX5vKtZxl87pWshX/cXjQsdNxZhlQblsB BuKQ+8HAbPp+PHB/iQ9snsIiVZLFvg45E3XPIGxrhOlpVOS6tjB7aqL9aMNHS9phbn 50aZGm6QlwLDA== From: Chao Yu To: jaegeuk@kernel.org Date: Wed, 20 Dec 2023 21:59:31 +0800 Message-Id: <20231220135934.3471407-3-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231220135934.3471407-1-chao@kernel.org> References: <20231220135934.3471407-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1rFx72-0001Jj-Pm Subject: [f2fs-dev] [PATCH 3/6] f2fs: compress: fix to check unreleased compressed cluster X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Sheng Yong Compressed cluster may not be released due to we can fail in release_compress_blocks(), fix to handle reserved compressed cluster correctly in reserve_compress_blocks(). Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Sheng Yong Signed-off-by: Chao Yu --- fs/f2fs/file.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index c5e681fc1d58..c200b4c81baf 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3643,6 +3643,15 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) goto next; } + /* + * compressed cluster was not released due to + * it fails in release_compress_blocks(). + */ + if (blkaddr == NEW_ADDR) { + compr_blocks++; + continue; + } + if (__is_valid_data_blkaddr(blkaddr)) { compr_blocks++; continue; @@ -3652,6 +3661,9 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) } reserved = cluster_size - compr_blocks; + if (!reserved) + goto next; + ret = inc_valid_block_count(sbi, dn->inode, &reserved); if (ret) return ret; From patchwork Wed Dec 20 13:59:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13500145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 69258C3DA6E for ; Wed, 20 Dec 2023 14:00:03 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rFx7B-0006su-Nb; Wed, 20 Dec 2023 14:00:01 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rFx79-0006sT-Ks for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 13:59:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=32GlP9vHEqARMVaEpjyRz2ivgY/q1Q1PAMgFqPrgVs8=; b=kVDnh92bkk3NPl3dGkasfNf60K 8xivbXrvs7RPcn8VGzWrru8yod99/H+E1+yPpTeS4hkp3KWqVPymi3i1xkutuK3Xq/11gk/cVTJBg 5x/tASxjloaMmrz+O5zEq4Gf57+288cMo4Zk5hFYOD9DHQ9hd3XJacj58WBZvx+jO9nQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=32GlP9vHEqARMVaEpjyRz2ivgY/q1Q1PAMgFqPrgVs8=; b=CEr5Zm+l6W0vPiBP5YnhY3IAhw 3flwniSaUqUtWLSJbVc1WFOcH8r4rOUwtJeDzKVHio4eN/VQVBv3f74EWEIazSpJlHzsKRSXr/nG3 Zy5QomXD51RnsnUelaBXzxs7gaMdngT+/DMlfYusALD5xwF8T1xvewlej4URJuMyufzQ=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rFx78-0001K9-Pf for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 13:59:59 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5FB796165F for ; Wed, 20 Dec 2023 13:59:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBDFAC433C7; Wed, 20 Dec 2023 13:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080788; bh=syTLTyQL0h6bm/dVO7pwCM9/CV4AN46/r4l6pfWHOsk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f+Xem3SDh/g99pjEVufXEyyYTplXClv9zD6wXfHQwb+grX1vfInCbK0xd+jGB3NWr sN92ub7zMqSpU6mGrNFx3TeQIYR3xngeYKtLy8zt6xGgWDU4RwAGi5j5Yyv63Kv6rO k7oX8GeZFKZF0dwOt0BxtO3EFM6aAvk3hxGX3iqHcmTI7vHmtTVePS8HEGQjxKLpDP Ihg1Wf/yOH3qLzMeu0NTd9/aECTj2+HT5FtVD8MW2wAadyp/IgN9BAAsh4hdSv5bA4 Zb/YkGlt+TTHnO54zERz6Sk1nHQaLxXFVVtzGlktNXYFwNOj4UH0W4wRDMxP5aNDut NH+gV9zHyPH5Q== From: Chao Yu To: jaegeuk@kernel.org Date: Wed, 20 Dec 2023 21:59:32 +0800 Message-Id: <20231220135934.3471407-4-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231220135934.3471407-1-chao@kernel.org> References: <20231220135934.3471407-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1rFx78-0001K9-Pf Subject: [f2fs-dev] [PATCH 4/6] f2fs: compress: fix to avoid inconsistent bewteen i_blocks and dnode X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net In reserve_compress_blocks(), we update blkaddrs of dnode in prior to inc_valid_block_count(), it may cause inconsistent status bewteen i_blocks and blkaddrs once inc_valid_block_count() fails. To fix this issue, it needs to reverse their invoking order. Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS") Signed-off-by: Chao Yu --- fs/f2fs/data.c | 5 +++-- fs/f2fs/f2fs.h | 7 ++++++- fs/f2fs/file.c | 26 ++++++++++++++------------ fs/f2fs/segment.c | 2 +- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index ceed5ac6c66b..cc4cb9099db6 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1224,7 +1224,8 @@ int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count) if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC))) return -EPERM; - if (unlikely((err = inc_valid_block_count(sbi, dn->inode, &count)))) + err = inc_valid_block_count(sbi, dn->inode, &count, true); + if (unlikely(err)) return err; trace_f2fs_reserve_new_blocks(dn->inode, dn->nid, @@ -1481,7 +1482,7 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type) dn->data_blkaddr = f2fs_data_blkaddr(dn); if (dn->data_blkaddr == NULL_ADDR) { - err = inc_valid_block_count(sbi, dn->inode, &count); + err = inc_valid_block_count(sbi, dn->inode, &count, true); if (unlikely(err)) return err; } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index bcb3940ab5ba..541c52fe2872 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2294,7 +2294,7 @@ static inline unsigned int get_available_block_count(struct f2fs_sb_info *sbi, static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, - struct inode *inode, blkcnt_t *count) + struct inode *inode, blkcnt_t *count, bool partial) { blkcnt_t diff = 0, release = 0; block_t avail_user_block_count; @@ -2320,6 +2320,11 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, avail_user_block_count = get_available_block_count(sbi, inode, true); if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { + if (!partial) { + spin_unlock(&sbi->stat_lock); + goto enospc; + } + diff = sbi->total_valid_block_count - avail_user_block_count; if (diff > *count) diff = *count; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index c200b4c81baf..4f3ed627f6a1 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3633,14 +3633,16 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) blkcnt_t reserved; int ret; - for (i = 0; i < cluster_size; i++, dn->ofs_in_node++) { - blkaddr = f2fs_data_blkaddr(dn); + for (i = 0; i < cluster_size; i++) { + blkaddr = data_blkaddr(dn->inode, dn->node_page, + dn->ofs_in_node + i); if (i == 0) { - if (blkaddr == COMPRESS_ADDR) - continue; - dn->ofs_in_node += cluster_size; - goto next; + if (blkaddr != COMPRESS_ADDR) { + dn->ofs_in_node += cluster_size; + goto next; + } + continue; } /* @@ -3656,20 +3658,20 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) compr_blocks++; continue; } - - f2fs_set_data_blkaddr(dn, NEW_ADDR); } reserved = cluster_size - compr_blocks; if (!reserved) goto next; - ret = inc_valid_block_count(sbi, dn->inode, &reserved); - if (ret) + ret = inc_valid_block_count(sbi, dn->inode, &reserved, false); + if (unlikely(ret)) return ret; - if (reserved != cluster_size - compr_blocks) - return -ENOSPC; + for (i = 0; i < cluster_size; i++, dn->ofs_in_node++) { + if (f2fs_data_blkaddr(dn) == NULL_ADDR) + f2fs_set_data_blkaddr(dn, NEW_ADDR); + } f2fs_i_compr_blocks_update(dn->inode, compr_blocks, true); diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index bafdd2295957..f95a2e914baf 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -248,7 +248,7 @@ static int __replace_atomic_write_block(struct inode *inode, pgoff_t index, } else { blkcnt_t count = 1; - err = inc_valid_block_count(sbi, inode, &count); + err = inc_valid_block_count(sbi, inode, &count, true); if (err) { f2fs_put_dnode(&dn); return err; From patchwork Wed Dec 20 13:59:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13500147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8BEE1C46CD2 for ; Wed, 20 Dec 2023 14:00:11 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rFx7K-0001O4-Ev; Wed, 20 Dec 2023 14:00:10 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rFx7B-0001Ne-Dc for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 14:00:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=jG1xYjeQFCncjaAKEpZbGnvc9Orum4R/wVy+dZd+s5k=; b=WS9HJp8a38IiL+VIPRULxqT+/S FBwG7loLDDna1sZLZVOEBg7J/a3+2lxtugWhtsIkbc8AV0PaAbHOA7dZyG8QC2ZAu3CYgg8YthiyM G9g2joPJj6RezMVF123mbkW15OhqTPJoECUlS4QBVzXAt93X/thUq0FuKLXS7laP7zbM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=jG1xYjeQFCncjaAKEpZbGnvc9Orum4R/wVy+dZd+s5k=; b=DciSQmMgKat1vlGbONNYzxMM6P W+5tReQ2DoCvfM8eY1nkEMvpZrboXl3ie41Jkl3N6a/sa85lKigtz/jBngvQvVqIQTK240Cg0gyyu n0Q+dTBMqodvVSFm0TpotrKa9kXwAqmEwA3TZaik2PDhwn0SOGZiD3b5CC/+IbVEb6Q4=; Received: from ams.source.kernel.org ([145.40.68.75]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rFx77-0001K0-56 for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 14:00:01 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id D79A3B81D72 for ; Wed, 20 Dec 2023 13:59:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF137C433C7; Wed, 20 Dec 2023 13:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080790; bh=a+Zr5UnD9JUAPNdpT3P1rGDjRu5/Oz4DN3bx1yho9co=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p7AP1VMH72ySxKDNYPwmOKGF7q51vqQMEB1+DXpAwpCyC6g85zy8oN8ik0NtuGECt fw5/oI6jiG4jODCmtW47jZNlF0pSs44rma9TnkTgz4+Rn9VKUA0XdZCAbjTTqWg01s 1Qe/SnxCpB7xpntmDxOOGwId82y/UnScwUQW/JoHkbw/UZ9V0qRiIdGRM0eexxPq+2 YwSJkO5n7pQeyvWeF7tgDH+FLyXYB7cbJ3Xdx7yRW9PwI8Ss8zqIZLy96dglx3O8+0 c/34qbSGUVjWs7wAi2hgltZ7HqAb6Ok3MFqvnR6HgZolU06+U4Vu5Pxk3uEynOOqL8 M10J8RnmP5IDg== From: Chao Yu To: jaegeuk@kernel.org Date: Wed, 20 Dec 2023 21:59:33 +0800 Message-Id: <20231220135934.3471407-5-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231220135934.3471407-1-chao@kernel.org> References: <20231220135934.3471407-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1rFx77-0001K0-56 Subject: [f2fs-dev] [PATCH 5/6] f2fs: fix to remove unnecessary f2fs_bug_on() to avoid panic X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net verify_blkaddr() will trigger panic once we inject fault into f2fs_is_valid_blkaddr(), fix to remove this unnecessary f2fs_bug_on(). Fixes: 18792e64c86d ("f2fs: support fault injection for f2fs_is_valid_blkaddr()") Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 541c52fe2872..9487581db08a 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3489,11 +3489,9 @@ bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, static inline void verify_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type) { - if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) { + if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.", blkaddr, type); - f2fs_bug_on(sbi, 1); - } } static inline bool __is_valid_data_blkaddr(block_t blkaddr) From patchwork Wed Dec 20 13:59:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13500146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C8D22C3DA6E for ; Wed, 20 Dec 2023 14:00:09 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rFx7J-0006tO-EX; Wed, 20 Dec 2023 14:00:09 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rFx7H-0006tD-U1 for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 14:00:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ADmk9SW4UgZx1Gt8dfBrDImUmmYFyOX+V1ThXwqp8CA=; b=FriS97tcILDXZZZEkcoD2u4tJE ob+b7vtnBfdlf/LXOIh2gHvbN64U61VPXDcuz+05dR2rDMjXHvY17ilW30pn6iMMAnygJWsMW/kT8 5/OK2L5cRh8rs1mR2yCMkcMRyn94vqqzlywQVVigv0JF6ovDPhYsoLCvO+tfBZt4A3o8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ADmk9SW4UgZx1Gt8dfBrDImUmmYFyOX+V1ThXwqp8CA=; b=mU8gVH4wKUqLY/nGci7spcgI2Q ev2NoX1IkMs7ou6HelSv9PBrcIUQGXxka74glFL4oVfCkmyueJbvp+7LRjDreDpH/bv/naFNTAH9U bx/WzmUb1Nr1B7r99J5tw5TMO3UXpjGahRUjf8IuOWld9E+8+svaIbH9l59L7Ca8n+80=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rFx7C-0001KX-Sn for linux-f2fs-devel@lists.sourceforge.net; Wed, 20 Dec 2023 14:00:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 76EEE61652 for ; Wed, 20 Dec 2023 13:59:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCAC2C433CB; Wed, 20 Dec 2023 13:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080792; bh=W2roxFRnwD7OFBUoZGhnWeFociodl3+VYdCaqAo2V0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rA/+TbY9/3iHsCkeDwv3DGjklnUjcgF96veKb4IYxEeTOefB7KB+7XvuI8qB5jT/h 3cbxpx5O7v+qc0fzfLQ9FTnTSkx3IJ+851v7UHN0SFcKkFmExcWdFrohLiLEZKDEgH rZckz4T6zWbNAU6HrsBZbaotesOY1v3lPOBrgwI/LRdbF4CPv83r9fI3V2YwIR781f K4CWRsiy61oSa8uIwRQkStY2nm3F5aKG6WN4tZxnXute+XP3dpkLxbDMkWjS+CxkzV ZAtr44wtznR3668+oZvk3VCHLSfI8mEMznTB4ZgFl/X3fsaqN+Cx7JF14MA/V/Ex+1 HWtB6HauAfwHg== From: Chao Yu To: jaegeuk@kernel.org Date: Wed, 20 Dec 2023 21:59:34 +0800 Message-Id: <20231220135934.3471407-6-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231220135934.3471407-1-chao@kernel.org> References: <20231220135934.3471407-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1rFx7C-0001KX-Sn Subject: [f2fs-dev] [PATCH 6/6] f2fs: introduce FAULT_INCONSISTENCE X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net We will encounter below inconsistent status when FAULT_BLKADDR type fault injection is on. Info: checkpoint state = d6 : nat_bits crc fsck compacted_summary orphan_inodes sudden-power-off [ASSERT] (fsck_chk_inode_blk:1254) --> ino: 0x1c100 has i_blocks: 000000c0, but has 191 blocks [FIX] (fsck_chk_inode_blk:1260) --> [0x1c100] i_blocks=0x000000c0 -> 0xbf [FIX] (fsck_chk_inode_blk:1269) --> [0x1c100] i_compr_blocks=0x00000026 -> 0x27 [ASSERT] (fsck_chk_inode_blk:1254) --> ino: 0x1cadb has i_blocks: 0000002f, but has 46 blocks [FIX] (fsck_chk_inode_blk:1260) --> [0x1cadb] i_blocks=0x0000002f -> 0x2e [FIX] (fsck_chk_inode_blk:1269) --> [0x1cadb] i_compr_blocks=0x00000011 -> 0x12 [ASSERT] (fsck_chk_inode_blk:1254) --> ino: 0x1c62c has i_blocks: 00000002, but has 1 blocks [FIX] (fsck_chk_inode_blk:1260) --> [0x1c62c] i_blocks=0x00000002 -> 0x1 After we inject fault into f2fs_is_valid_blkaddr() during truncation, a) it missed to increase @nr_free or @valid_blocks b) it can cause in blkaddr leak in truncated dnode Which may cause inconsistent status. This patch separates FAULT_INCONSISTENCE from FAULT_BLKADDR, so that we can: a) use FAULT_INCONSISTENCE in f2fs_truncate_data_blocks_range() to simulate inconsistent issue independently, b) FAULT_BLKADDR fault will not cause any inconsistent status, we can just use it to check error path handling in kernel side. Signed-off-by: Chao Yu --- Documentation/ABI/testing/sysfs-fs-f2fs | 1 + Documentation/filesystems/f2fs.rst | 1 + fs/f2fs/checkpoint.c | 19 +++++++++++++++---- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/file.c | 8 ++++++-- fs/f2fs/super.c | 1 + 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 4f1d4e636d67..649aabac16c2 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -708,6 +708,7 @@ Description: Support configuring fault injection type, should be FAULT_DQUOT_INIT 0x000010000 FAULT_LOCK_OP 0x000020000 FAULT_BLKADDR 0x000040000 + FAULT_INCONSISTENCE 0x000080000 =================== =========== What: /sys/fs/f2fs//discard_io_aware_gran diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst index 5a1686cdd6b4..dfc1e73b17d9 100644 --- a/Documentation/filesystems/f2fs.rst +++ b/Documentation/filesystems/f2fs.rst @@ -209,6 +209,7 @@ fault_type=%d Support configuring fault injection type, should be FAULT_DQUOT_INIT 0x000010000 FAULT_LOCK_OP 0x000020000 FAULT_BLKADDR 0x000040000 + FAULT_INCONSISTENCE 0x000080000 =================== =========== mode=%s Control block allocation mode which supports "adaptive" and "lfs". In "lfs" mode, there should be no random diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index f3f3e98fd6b0..b59db6c1932c 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -170,12 +170,9 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr, return exist; } -bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, +bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type) { - if (time_to_inject(sbi, FAULT_BLKADDR)) - return false; - switch (type) { case META_NAT: break; @@ -230,6 +227,20 @@ bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, return true; } +bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, + block_t blkaddr, int type) +{ + if (time_to_inject(sbi, FAULT_BLKADDR)) + return false; + return __f2fs_is_valid_blkaddr(sbi, blkaddr, type); +} + +bool f2fs_is_valid_blkaddr_raw(struct f2fs_sb_info *sbi, + block_t blkaddr, int type) +{ + return __f2fs_is_valid_blkaddr(sbi, blkaddr, type); +} + /* * Readahead CP/NAT/SIT/SSA/POR pages */ diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 9487581db08a..49e4de324841 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -61,6 +61,7 @@ enum { FAULT_DQUOT_INIT, FAULT_LOCK_OP, FAULT_BLKADDR, + FAULT_INCONSISTENCE, FAULT_MAX, }; @@ -3787,6 +3788,8 @@ struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index); struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); +bool f2fs_is_valid_blkaddr_raw(struct f2fs_sb_info *sbi, + block_t blkaddr, int type); int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, int type, bool sync); void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 4f3ed627f6a1..6c4c739d73b3 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -593,9 +593,13 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) f2fs_set_data_blkaddr(dn, NULL_ADDR); if (__is_valid_data_blkaddr(blkaddr)) { - if (!f2fs_is_valid_blkaddr(sbi, blkaddr, - DATA_GENERIC_ENHANCE)) + if (time_to_inject(sbi, FAULT_INCONSISTENCE)) + continue; + if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr, + DATA_GENERIC_ENHANCE)) { + f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); continue; + } if (compressed_cluster) valid_blocks++; } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 29b9e6e3eb5f..5659166b3918 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -62,6 +62,7 @@ const char *f2fs_fault_name[FAULT_MAX] = { [FAULT_DQUOT_INIT] = "dquot initialize", [FAULT_LOCK_OP] = "lock_op", [FAULT_BLKADDR] = "invalid blkaddr", + [FAULT_INCONSISTENCE] = "inconsistence", }; void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,