From patchwork Mon May 6 10:33:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13655283 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 04267C10F16 for ; Mon, 6 May 2024 10:33:30 +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 1s3vey-0005Ui-Mt; Mon, 06 May 2024 10:33:28 +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 1s3vex-0005Uc-KK for linux-f2fs-devel@lists.sourceforge.net; Mon, 06 May 2024 10:33:27 +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=E31uoUDJOzIfmIKHvU27ZHbfL5V9s59Wb7nHBi2/TxA=; b=GHn1NYDipcj5vAEci551am2vvc u1urQf2NExF6QmgFRXfWq5guYxorsMcz6ySkkPM4Bw7EtNHp2gcFVjMjNy5QuLq7hu64DGlDKRWsw dX1fPGF69Gc37F5YsgcrVTplajpxhG0eiYwrtVth+UBWM1KaEk9gqG9zMjq0zYAFApgs=; 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=E31uoUDJOzIfmIKHvU27ZHbfL5V9s59Wb7nHBi2/TxA=; b=W hDwDbhU8qvtO5ljiEkXkvA4G9je40qwbJCpoItZbgNZG19W1AQzUjY3VgqyEkxs++FEyApRfQKTTa E76avXhKH/tOfValGIAxSelUuE8SHAGDLBvxFLWoHE7y4a2CFleNR/4PfFvdoHv1SZlz7SGnfoD/j bV/p7KDW0V1Hs8g8=; Received: from sin.source.kernel.org ([145.40.73.55]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1s3vew-00042m-U5 for linux-f2fs-devel@lists.sourceforge.net; Mon, 06 May 2024 10:33:27 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 33677CE0B99 for ; Mon, 6 May 2024 10:33:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CA1BC116B1; Mon, 6 May 2024 10:33:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714991599; bh=ArQZcPL9NskSWJ33AcpZ7fqpChWS94RCsV5KimDJTWY=; h=From:To:Cc:Subject:Date:From; b=PO3HNL/NaetYrGgi4hGaAP0vK2LQfQyHtc5/VlCpgZx3gPrczk+9ZmblggC9/m3z3 85Z76E4GjDW7N/t/6kY7dkRuAJ3BujwzquOE3LVHB3ZTgCNhqtIDxPjVfIlabMw2s9 P1TC86GbAmremkhH1O2Vr3ed1AgbwQ+d7Y4Lm0OTFfgosuABRvprrwIN1MIU4SpKjl Htn29yMbng/+bMit+Ic0OEZ/gV43EjgcfojFEiiaBkHUBSaT7qt2qsjd/zZcw/hWiP GK8HfY+W8UNX9nazhsaKQ6INN3BtApxRKariBmzFuNCOpcvznZ4qLkEvQqW+a+W7GP mIEhU2Oxr68dA== From: Chao Yu To: jaegeuk@kernel.org Date: Mon, 6 May 2024 18:33:11 +0800 Message-Id: <20240506103313.773503-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Headers-End: 1s3vew-00042m-U5 Subject: [f2fs-dev] [PATCH 1/3] f2fs: fix to release node block count in error path of f2fs_new_node_page() 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 It missed to call dec_valid_node_count() to release node block count in error path, fix it. Fixes: 141170b759e0 ("f2fs: fix to avoid use f2fs_bug_on() in f2fs_new_node_page()") Signed-off-by: Chao Yu --- fs/f2fs/node.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index b3de6d6cdb02..ae39971825bc 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1313,15 +1313,14 @@ struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs) #ifdef CONFIG_F2FS_CHECK_FS err = f2fs_get_node_info(sbi, dn->nid, &new_ni, false); - if (err) { - dec_valid_node_count(sbi, dn->inode, !ofs); - goto fail; - } + if (err) + goto out_dec; + if (unlikely(new_ni.blk_addr != NULL_ADDR)) { err = -EFSCORRUPTED; set_sbi_flag(sbi, SBI_NEED_FSCK); f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); - goto fail; + goto out_dec; } #endif new_ni.nid = dn->nid; @@ -1345,7 +1344,8 @@ struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs) if (ofs == 0) inc_valid_inode_count(sbi); return page; - +out_dec: + dec_valid_node_count(sbi, dn->inode, !ofs); fail: clear_node_page_dirty(page); f2fs_put_page(page, 1); From patchwork Mon May 6 10:33:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13655284 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 8524CC25B5F for ; Mon, 6 May 2024 10:33:31 +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 1s3vf0-0008Mo-Ib; Mon, 06 May 2024 10:33:30 +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 1s3vez-0008Mg-5r for linux-f2fs-devel@lists.sourceforge.net; Mon, 06 May 2024 10:33:29 +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=f83KS+WRix2D0FSfjaIBor9+kyUWES/deZ9Qxf/EmwE=; b=K4lsRzkIgbvtYS2MEJQe7bhiWa 5LZuK6Lo/xYUJUg1wQxDMd1uKx6dDx2o4TD0GR+kUVD9ynn/0wYWSK+EjhH8T/IOMEwJUDKsOTRmo 1frFSMTkXkpJX+fnXCMOcSVf/vtyR668CG9oUjG5fLVlxwpFVo2l5rCaICjVfatMcjO4=; 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=f83KS+WRix2D0FSfjaIBor9+kyUWES/deZ9Qxf/EmwE=; b=E/R5hFp1BftsKTMkM0ygYcpBCp I9TnvKS//Rb75yqjFIn+GvEhZhZRDPhg7qoOZnZG64EwU2XfbRNkgQ2p93PwMtrs4LVU2YTYweMaX GVX/44fNRonDCKfbCvJWtfcx0WBp7B3QrPG+bmYnkMryNPjd3xbi/WpAmYOJqV7sOjHM=; Received: from sin.source.kernel.org ([145.40.73.55]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1s3vey-00042s-L8 for linux-f2fs-devel@lists.sourceforge.net; Mon, 06 May 2024 10:33:29 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id E533CCE0C68 for ; Mon, 6 May 2024 10:33:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1719C4AF18; Mon, 6 May 2024 10:33:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714991601; bh=8d1H5ohN2OC867yx9Kz7v2nSEmt59J3n2trihH6jcFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YsUNro59jXc0yxJ2XMnh1j9/+xx9X43rLu3WZgQ+WYy1DLyp0VXzPVAyd5JINd7OS mvA2tpZ98mnK26t8zizcnuhFu1QgMA9zoCbmiF6wNmNxlICzZhknuj6R7Pa+uI/EC5 j5UShNpxwcq7gFizl1h1OSlAw1gYAF4FhnGQ2a3YG0ps0INegJv9hwiBKjhnUnY9QG yZlHbyIMcPno4wbhtwShSaksSCOrWPHW/F/CURfu9m5IdvH7MVDceI0baf+6oZTJKy pfqHJagIy1wclYghDINnZLBp/A7E+hRG095sFYt9xnJXO79st8DLBHnk2aBwl7yK2B Jjre/ozJIZDgA== From: Chao Yu To: jaegeuk@kernel.org Date: Mon, 6 May 2024 18:33:12 +0800 Message-Id: <20240506103313.773503-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240506103313.773503-1-chao@kernel.org> References: <20240506103313.773503-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1s3vey-00042s-L8 Subject: [f2fs-dev] [PATCH 2/3] f2fs: fix to add missing iput() in gc_data_segment() 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 During gc_data_segment(), if inode state is abnormal, it missed to call iput(), fix it. Fixes: 132e3209789c ("f2fs: remove false alarm on iget failure during GC") Fixes: 9056d6489f5a ("f2fs: fix to do sanity check on inode type during garbage collection") Signed-off-by: Chao Yu --- fs/f2fs/gc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 8852814dab7f..e86c7f01539a 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1554,10 +1554,15 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, int err; inode = f2fs_iget(sb, dni.ino); - if (IS_ERR(inode) || is_bad_inode(inode) || - special_file(inode->i_mode)) + if (IS_ERR(inode)) continue; + if (is_bad_inode(inode) || + special_file(inode->i_mode)) { + iput(inode); + continue; + } + err = f2fs_gc_pinned_control(inode, gc_type, segno); if (err == -EAGAIN) { iput(inode); From patchwork Mon May 6 10:33:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13655285 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 D8245C25B5C for ; Mon, 6 May 2024 10:33:36 +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 1s3vf5-0001aX-Q9; Mon, 06 May 2024 10:33:36 +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 1s3vf3-0001aH-L5 for linux-f2fs-devel@lists.sourceforge.net; Mon, 06 May 2024 10:33:34 +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=9TqVmNuqsqcU9JKAjxrzBlB0XJkzsjnj2NxN8iX4bsY=; b=WNLc1GWvEDD6AhmKP5qehCozFR KQjumx9crKNpTiWLPL/SK4G4BKVsjUYaxnUy2nr+REy8aB5f5mlh8dP27aShfaEzO4OCS6shCz/Vk +7feUbK6BYFtWdqSq48UwB8GP5kfJ/ur722IuJGPsAaubsUWuB1drt1I+I9aXeTKia/c=; 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=9TqVmNuqsqcU9JKAjxrzBlB0XJkzsjnj2NxN8iX4bsY=; b=ef/QiXrrUL9jtKRlJcWbk3ibcS 2KjfJs1c33qvOjlSt47JNToYJzKDYKKWW3zdqfxctOK8g19nCItH0/JXj0aW/iVF46jQ8Pizi5wqe o9CT7ohmmZeCPaChOo26sgwvowDAKNV3MoLcxoOUY4YdFJX8wyZCzYbIvtuuN4UD3CUY=; 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 1s3vf3-00043D-KS for linux-f2fs-devel@lists.sourceforge.net; Mon, 06 May 2024 10:33:34 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 494556117B; Mon, 6 May 2024 10:33:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A29B2C116B1; Mon, 6 May 2024 10:33:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714991603; bh=hbVH4a2LMnYUE7XaNzFKCA9lmmoLLYRfxfA+UzcjhHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OVnlREIFEJYCkGh6gKiF0Pznv5yXHDeBviRdV7sMv9dlSEhNkG8O0yL3CURYxOSWO peo1a2H6IyVgnnKgMpxQNEhBcXjZcqMYqeGl5j4r3NAeaCEMG0r5ocMc8Cuexsdeqq PVJem+EOFVIo807lc+GXx3QwCxSBBjgWMKxRHuGk0e2QuufstNhqZZBI7c3F6gQP6C zjxYBhh9eYDwba76fqyulTnqdb0aGg1+LLM0MdScReoarkJfT0HTMbVr7RRvqLPc9b +fcqD5ElJJ+B+K5uI+S4bGyzHYbFSbdTByoGhnDFV183Vy/1bZNDM5Ht/8y+Liu7B+ +SLSGo2B8F8ag== From: Chao Yu To: jaegeuk@kernel.org Date: Mon, 6 May 2024 18:33:13 +0800 Message-Id: <20240506103313.773503-3-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240506103313.773503-1-chao@kernel.org> References: <20240506103313.773503-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1s3vf3-00043D-KS Subject: [f2fs-dev] [PATCH 3/3] f2fs: fix to do sanity check on i_nid for inline_data inode 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, syzbot+848062ba19c8782ca5c8@syzkaller.appspotmail.com, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net syzbot reports a f2fs bug as below: ------------[ cut here ]------------ kernel BUG at fs/f2fs/inline.c:258! CPU: 1 PID: 34 Comm: kworker/u8:2 Not tainted 6.9.0-rc6-syzkaller-00012-g9e4bc4bcae01 #0 RIP: 0010:f2fs_write_inline_data+0x781/0x790 fs/f2fs/inline.c:258 Call Trace: f2fs_write_single_data_page+0xb65/0x1d60 fs/f2fs/data.c:2834 f2fs_write_cache_pages fs/f2fs/data.c:3133 [inline] __f2fs_write_data_pages fs/f2fs/data.c:3288 [inline] f2fs_write_data_pages+0x1efe/0x3a90 fs/f2fs/data.c:3315 do_writepages+0x35b/0x870 mm/page-writeback.c:2612 __writeback_single_inode+0x165/0x10b0 fs/fs-writeback.c:1650 writeback_sb_inodes+0x905/0x1260 fs/fs-writeback.c:1941 wb_writeback+0x457/0xce0 fs/fs-writeback.c:2117 wb_do_writeback fs/fs-writeback.c:2264 [inline] wb_workfn+0x410/0x1090 fs/fs-writeback.c:2304 process_one_work kernel/workqueue.c:3254 [inline] process_scheduled_works+0xa12/0x17c0 kernel/workqueue.c:3335 worker_thread+0x86d/0xd70 kernel/workqueue.c:3416 kthread+0x2f2/0x390 kernel/kthread.c:388 ret_from_fork+0x4d/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 The root cause is: inline_data inode can be fuzzed, so that there may be valid blkaddr in its direct node, once f2fs triggers background GC to migrate the block, it will hit f2fs_bug_on() during dirty page writeback. Let's add sanity check on i_nid field for inline_data inode, meanwhile, forbid to migrate inline_data inode's data block to fix this issue. Reported-by: syzbot+848062ba19c8782ca5c8@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-f2fs-devel/000000000000d103ce06174d7ec3@google.com Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 2 +- fs/f2fs/gc.c | 6 ++++++ fs/f2fs/inline.c | 17 ++++++++++++++++- fs/f2fs/inode.c | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index fced2b7652f4..c876813b5532 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4146,7 +4146,7 @@ extern struct kmem_cache *f2fs_inode_entry_slab; * inline.c */ bool f2fs_may_inline_data(struct inode *inode); -bool f2fs_sanity_check_inline_data(struct inode *inode); +bool f2fs_sanity_check_inline_data(struct inode *inode, struct page *ipage); bool f2fs_may_inline_dentry(struct inode *inode); void f2fs_do_read_inline_data(struct page *page, struct page *ipage); void f2fs_truncate_inline_inode(struct inode *inode, diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index e86c7f01539a..041957750478 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1563,6 +1563,12 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, continue; } + if (f2fs_has_inline_data(inode)) { + iput(inode); + set_sbi_flag(sbi, SBI_NEED_FSCK); + continue; + } + err = f2fs_gc_pinned_control(inode, gc_type, segno); if (err == -EAGAIN) { iput(inode); diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index ac00423f117b..067600fed3d4 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -33,11 +33,26 @@ bool f2fs_may_inline_data(struct inode *inode) return !f2fs_post_read_required(inode); } -bool f2fs_sanity_check_inline_data(struct inode *inode) +static bool has_node_blocks(struct inode *inode, struct page *ipage) +{ + struct f2fs_inode *ri = F2FS_INODE(ipage); + int i; + + for (i = 0; i < DEF_NIDS_PER_INODE; i++) { + if (ri->i_nid[i]) + return true; + } + return false; +} + +bool f2fs_sanity_check_inline_data(struct inode *inode, struct page *ipage) { if (!f2fs_has_inline_data(inode)) return false; + if (has_node_blocks(inode, ipage)) + return false; + if (!support_inline_data(inode)) return true; diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index c26effdce9aa..1423cd27a477 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -343,7 +343,7 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page) } } - if (f2fs_sanity_check_inline_data(inode)) { + if (f2fs_sanity_check_inline_data(inode, node_page)) { f2fs_warn(sbi, "%s: inode (ino=%lx, mode=%u) should not have inline_data, run fsck to fix", __func__, inode->i_ino, inode->i_mode); return false;