Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753390AbeAJGnj (ORCPT + 1 other); Wed, 10 Jan 2018 01:43:39 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:3719 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753343AbeAJGni (ORCPT ); Wed, 10 Jan 2018 01:43:38 -0500 Subject: Re: [PATCH] f2fs: handle newly created page when revoking inmem pages To: Daeho Jeong , , References: <1515552234-27964-1-git-send-email-daeho.jeong@samsung.com> From: Chao Yu Message-ID: Date: Wed, 10 Jan 2018 14:43:19 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1515552234-27964-1-git-send-email-daeho.jeong@samsung.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 2018/1/10 10:43, Daeho Jeong wrote: > When committing inmem pages is successful, we revoke already committed > blocks in __revoke_inmem_pages() and finally replace the committed > ones with the old blocks using f2fs_replace_block(). However, if > the committed block was newly created one, the address of the old > block is NEW_ADDR and __f2fs_replace_block() cannot handle NEW_ADDR > as new_blkaddr properly and a kernel panic occurrs. Good catch! > > Signed-off-by: Daeho Jeong > Tested-by: Shu Tan > --- > fs/f2fs/segment.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > index c117e09..463f420 100644 > --- a/fs/f2fs/segment.c > +++ b/fs/f2fs/segment.c > @@ -248,7 +248,11 @@ static int __revoke_inmem_pages(struct inode *inode, > goto next; > } > get_node_info(sbi, dn.nid, &ni); > - f2fs_replace_block(sbi, &dn, dn.data_blkaddr, > + if (cur->old_addr == NEW_ADDR) { > + invalidate_blocks(sbi, dn.data_blkaddr); > + f2fs_update_data_blkaddr(&dn, NULL_ADDR); Original intention here is to recover status to the timing before committing atomic write. As at that timing blkaddr in dnode should be cur->old_addr(NEW_ADDR), so we need to change to call: f2fs_update_data_blkaddr(&dn, NEW_ADDR); Otherwise, metadata will become inconsistent, because blkaddr value is NULL_ADDR means that current block is not preallocated, but total_valid_block_count has already been updated. Right? Thanks, > + } else > + f2fs_replace_block(sbi, &dn, dn.data_blkaddr, > cur->old_addr, ni.version, true, true); > f2fs_put_dnode(&dn); > } >