Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp72682pxb; Mon, 13 Sep 2021 13:16:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4pifOunZoy8rMF9DqFXM7xPZCBxrPx8Fgr9zhk5SyTDVKwlXpLo1+hw+gVlpojOvAu52F X-Received: by 2002:a17:906:8281:: with SMTP id h1mr14298545ejx.352.1631564177462; Mon, 13 Sep 2021 13:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631564177; cv=none; d=google.com; s=arc-20160816; b=UXMIbAHdiIUHOhZTfl+CNVFw3SiUybXhZGmnkicqQ3vVmDkyW1ADoNzD/21fbT3TGI w8GeadbQAP4Mh11In8nobVecnTdNz6UzKFrRvNDleMuijvTWJdU9QgM8z5RyrvC9RihU hpeyuh5c+VW5oMeIXMvSWBNLDLWsbbaELZkjgxULPEerbMHSLMl+Y0zuV8QV5EZPtDAc x3i9YxLBhZ9ZQd+IfRi+4IWH3k0KXCezogJS1VNT+ockSIP12qTevgqsIF+emOa5dMjv oBt+3TP//YZ2wtdapQ4ALWPDIsDirFXhN6Hh+l30OZRYplH4JGfYGxh0SCfr9FUvizfm C8Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gwm03WkS02hpSYwOpehQUv5vRq8HgUHWdLJ9ubo3Zo8=; b=pouvI5ZAgPGgAOi3UeDzsLamiawIuGJgXpDwLwib/1WKTvGAgNibtUB/doz0vAulsj NCb43oX+fYmRYSYF8r/IlAxLrEmlgQwFcCa1Lie0I1LdA7OqsOQ1NNlkPclRUQt0jx84 OhN9vRWvnNfjGm3dolGQ3C+e4jt2UuvMaR/6BwIPIB8KSX1uFPtHUY3PbKhmgYHuGGwP DtlCozcvfYXn7P2r51uUddxgcTrJqYq9VmsResK2uZF69qjvFcgwEceUjUzjGc+HE0qh XWTcoIA00IlKpwoSaeGUsLRcVJekC9xImV3FJdDWvRryzHiHJ+po0Rpy+w9PIKeosgnn bQLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GqDuORCp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d24si468111edj.121.2021.09.13.13.15.53; Mon, 13 Sep 2021 13:16:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GqDuORCp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243909AbhIMNvE (ORCPT + 99 others); Mon, 13 Sep 2021 09:51:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:51786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243755AbhIMNqw (ORCPT ); Mon, 13 Sep 2021 09:46:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 53BAB6159A; Mon, 13 Sep 2021 13:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539925; bh=rmyUtVsEdh0gseDg+t15mYDPwUXTV9Y5f3XzJUbybiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GqDuORCpAj8mxVEizpXcZVMyI35S+oXneDXIy8W5Kib0sVKfkr9ZhicwRigMtOuZw 8NDsv9zyArMAySSa61krodeBUFCG/oB7/D7g3A8SctYElaJ54hcc37InkFMUwc1ovw gxGlcp13wzX5GZC5afSKkoXF5JGCwllYBTfBFHJY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Jaegeuk Kim Subject: [PATCH 5.10 217/236] f2fs: guarantee to write dirty data when enabling checkpoint back Date: Mon, 13 Sep 2021 15:15:22 +0200 Message-Id: <20210913131107.750805752@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jaegeuk Kim commit dddd3d65293a52c2c3850c19b1e5115712e534d8 upstream. We must flush all the dirty data when enabling checkpoint back. Let's guarantee that first by adding a retry logic on sync_inodes_sb(). In addition to that, this patch adds to flush data in fsync when checkpoint is disabled, which can mitigate the sync_inodes_sb() failures in advance. Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/file.c | 5 ++--- fs/f2fs/super.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -259,8 +259,7 @@ static int f2fs_do_sync_file(struct file }; unsigned int seq_id = 0; - if (unlikely(f2fs_readonly(inode->i_sb) || - is_sbi_flag_set(sbi, SBI_CP_DISABLED))) + if (unlikely(f2fs_readonly(inode->i_sb))) return 0; trace_f2fs_sync_file_enter(inode); @@ -274,7 +273,7 @@ static int f2fs_do_sync_file(struct file ret = file_write_and_wait_range(file, start, end); clear_inode_flag(inode, FI_NEED_IPU); - if (ret) { + if (ret || is_sbi_flag_set(sbi, SBI_CP_DISABLED)) { trace_f2fs_sync_file_exit(inode, cp_reason, datasync, ret); return ret; } --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1764,8 +1764,17 @@ restore_flag: static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) { + int retry = DEFAULT_RETRY_IO_COUNT; + /* we should flush all the data to keep data consistency */ - sync_inodes_sb(sbi->sb); + do { + sync_inodes_sb(sbi->sb); + cond_resched(); + congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT); + } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--); + + if (unlikely(retry < 0)) + f2fs_warn(sbi, "checkpoint=enable has some unwritten data."); down_write(&sbi->gc_lock); f2fs_dirty_to_prefree(sbi);