From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-dm3nam03on0090.outbound.protection.outlook.com ([104.47.41.90]:39552 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727861AbeIBRT7 (ORCPT ); Sun, 2 Sep 2018 13:19:59 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH AUTOSEL 4.18 042/131] f2fs: fix to detect looped node chain correctly Date: Sun, 2 Sep 2018 13:03:54 +0000 Message-ID: <20180902064601.183036-42-alexander.levin@microsoft.com> References: <20180902064601.183036-1-alexander.levin@microsoft.com> In-Reply-To: <20180902064601.183036-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Chao Yu [ Upstream commit 82902c06bd17dbf6e8184299842ca5c68880970f ] Below dmesg was printed when testing generic/388 of fstest: F2FS-fs (zram1): find_fsync_dnodes: detect looped node chain, blkaddr:52661= 5, next:526616 F2FS-fs (zram1): Cannot recover all fsync data errno=3D-22 F2FS-fs (zram1): Mounted with checkpoint version =3D 22300d0e F2FS-fs (zram1): find_fsync_dnodes: detect looped node chain, blkaddr:52661= 5, next:526616 F2FS-fs (zram1): Cannot recover all fsync data errno=3D-22 The reason is that we initialize free_blocks with free blocks of filesystem, so if filesystem is full, free_blocks can be zero, below condition will be true, so that, it will fail recovery. if (++loop_cnt >=3D free_blocks || blkaddr =3D=3D next_blkaddr_of_node(page)) To fix this issue, initialize free_blocks with correct value which includes over-privision blocks. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/recovery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index 38f25f0b193a..ad70e62c5da4 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -241,8 +241,8 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, = struct list_head *head, struct page *page =3D NULL; block_t blkaddr; unsigned int loop_cnt =3D 0; - unsigned int free_blocks =3D sbi->user_block_count - - valid_user_blocks(sbi); + unsigned int free_blocks =3D MAIN_SEGS(sbi) * sbi->blocks_per_seg - + valid_user_blocks(sbi); int err =3D 0; =20 /* get node pages in the current segment */ --=20 2.17.1