Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751875AbeACUEE (ORCPT + 1 other); Wed, 3 Jan 2018 15:04:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:49166 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751769AbeACUEC (ORCPT ); Wed, 3 Jan 2018 15:04:02 -0500 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D61402133D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=jaegeuk@kernel.org Date: Wed, 3 Jan 2018 12:04:01 -0800 From: Jaegeuk Kim To: Yunlong Song Cc: chao@kernel.org, yuchao0@huawei.com, yunlong.song@icloud.com, miaoxie@huawei.com, bintian.wang@huawei.com, shengyong1@huawei.com, heyunlei@huawei.com, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] f2fs: check segment type before recover data Message-ID: <20180103200401.GC30014@jaegeuk-macbookpro.roam.corp.google.com> References: <1514619768-134531-1-git-send-email-yunlong.song@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1514619768-134531-1-git-send-email-yunlong.song@huawei.com> User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 12/30, Yunlong Song wrote: > In some case, the node blocks has wrong blkaddr whose segment type is > NODE, e.g., recover inode has missing xattr flag and the blkaddr is in > the xattr range. Since fsck.f2fs does not check the recovery nodes, this > will cause __f2fs_replace_block change the curseg of node and do the > update_sit_entry(sbi, new_blkaddr, 1) with no next_blkoff refresh, as a > result, when recovery process write checkpoint and sync nodes, the > next_blkoff of curseg is used in the segment bit map, then it will > cause f2fs_bug_on. So let's check the segment type before recover data, > and stop recover if it is not in DATA segment. Then, why not checking this in __f2fs_replace_block()? And, you can do this, only if se->valid_blocks != 0 at this point. > > Signed-off-by: Yunlong Song > --- > fs/f2fs/recovery.c | 3 ++- > fs/f2fs/segment.h | 3 +++ > 2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c > index 7d63faf..e8fee4a 100644 > --- a/fs/f2fs/recovery.c > +++ b/fs/f2fs/recovery.c > @@ -478,7 +478,8 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, > } > > /* dest is valid block, try to recover from src to dest */ > - if (is_valid_blkaddr(sbi, dest, META_POR)) { > + if (is_valid_blkaddr(sbi, dest, META_POR) && > + is_data_blkaddr(sbi, dest)) { > > if (src == NULL_ADDR) { > err = reserve_new_block(&dn); > diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h > index 71a2aaa..5c5a215 100644 > --- a/fs/f2fs/segment.h > +++ b/fs/f2fs/segment.h > @@ -115,6 +115,9 @@ > #define SECTOR_TO_BLOCK(sectors) \ > ((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK) > > +#define is_data_blkaddr(sbi, blkaddr) \ > + (IS_DATASEG(get_seg_entry(sbi, GET_SEGNO(sbi, blkaddr))->type)) > + > /* > * indicate a block allocation direction: RIGHT and LEFT. > * RIGHT means allocating new sections towards the end of volume. > -- > 1.8.5.2