Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp41011rwb; Fri, 19 Aug 2022 16:26:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR5S9kmFVBQnefOHTj6jXcRuI7KhH58t8Z937OxSGYJtT2nMLLkFMQecMJT01U595MkVJnVd X-Received: by 2002:a17:907:d2a:b0:730:d34d:8a1c with SMTP id gn42-20020a1709070d2a00b00730d34d8a1cmr6204630ejc.574.1660951603302; Fri, 19 Aug 2022 16:26:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660951603; cv=none; d=google.com; s=arc-20160816; b=USQ67Zq1N9y9ffptOqekOMAeg+EVplJfhxcbmJL0yzQ8sCkgOXKG6IV3M8owlvM2m5 LewFwMcKsSz1ydqA1usU+ECnwi442S49zfqUJQ1I+GkkBl+SILvnJQWKafZFKalNvjGq NKcBP6/akJ7tCcnHgVCw3T/1g+0WA6n0yB2vwkRkA5q5ikavpL3XOU0wpHC359hxt6ZQ khr8GcD2tVsx6gSIASBtE84EHfl/Awzi9oAU27C8AqPaaET6ra9ix1JeolkLzxF71CIX B0khHDucR4HMj0/t2dVLp/cBNUST2ssGdQ10KTx8oHhkD6oc5L9cTOi+n3KrY8I9N1mL uGrA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=XhSiQiIUqASqEojqBeOeOWDhZzSayGUedaZ3A3cGQQ8=; b=y8aTH3TAVWmCwp1dkE2u57FaSpk/ECd9mEqlsoVE8dIPMPo8CxryaASkDk6+1XOrfX BpsB3IxN0jffKqE3kEkLvAYA4UjRFR59onDO9OkZMfpyapL8vUC7VRjvDknvcMaOYhdE IRCslfsmlRrHypwGc/H0CLqLzg5kRhVFlCGx9oIHy2NI6ZNCwibV4ScGDXIo8LJ2deNd el4Fokipku80OXyzeMY7HWUvH2co7v3tgrbZS1DTWfjMNTxfgtU6zO82YQcsrq0a+yIX qfe+5fI/D69VaewLQdepmk6fNKLdUiS7kr14R8Ytr2AgIr8ZMDOPrFOSQjkcZC8GpGff qUCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aMDxQNH9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs15-20020a170906dc8f00b0073c875a1721si3002966ejc.366.2022.08.19.16.26.17; Fri, 19 Aug 2022 16:26:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aMDxQNH9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243951AbiHSXPi (ORCPT + 99 others); Fri, 19 Aug 2022 19:15:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244132AbiHSXPW (ORCPT ); Fri, 19 Aug 2022 19:15:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F83D10A773 for ; Fri, 19 Aug 2022 16:15:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1E682B82995 for ; Fri, 19 Aug 2022 23:15:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA119C433C1; Fri, 19 Aug 2022 23:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660950917; bh=xfanyvshwE1RaGKDX1ptGODAoLpIUb8GI1syiWM0c4U=; h=From:To:Cc:Subject:Date:From; b=aMDxQNH9Y7ngPtlVngBTudaEvxLIRPP+CMTFFzFK+2aY/rDW0sZ2dYigfUU5VxvxN CjZD53qHKm/h9bxG3Jg6hF42Ce89hJHDvH2Xhy0fvV6jXzgugc1yCzca8KYFZb0BI7 hofEvc491FN7lGKD0r/Olrd7kijirMWK1280KF7yP2eNuSBanJ6n9NrE2wtx4uJ7jS +yQz2wVKXqULJ0hlo3itVgA77ioJW7r+4RsbjY+n4lbQh9KSYgeB0EnZwlMKLRn1qJ 2deN+l1IBw8WYvHUcOy0zmjR1eaSr9J64syK4mvO5cUc0urxFTsy8wpRgZ6VKVnXaz +CV1xwkugftmQ== From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH 1/2] f2fs: flush pending checkpoints when freezing super Date: Fri, 19 Aug 2022 16:15:13 -0700 Message-Id: <20220819231514.3609958-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This avoids -EINVAL when trying to freeze f2fs. Signed-off-by: Jaegeuk Kim --- fs/f2fs/checkpoint.c | 27 +++++++++++++++++++++------ fs/f2fs/f2fs.h | 1 + fs/f2fs/super.c | 5 ++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 8259e0fa97e1..37f7a9ea4746 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1892,15 +1892,30 @@ int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi) void f2fs_stop_ckpt_thread(struct f2fs_sb_info *sbi) { struct ckpt_req_control *cprc = &sbi->cprc_info; + struct task_struct *ckpt_task; - if (cprc->f2fs_issue_ckpt) { - struct task_struct *ckpt_task = cprc->f2fs_issue_ckpt; + if (!cprc->f2fs_issue_ckpt) + return; - cprc->f2fs_issue_ckpt = NULL; - kthread_stop(ckpt_task); + ckpt_task = cprc->f2fs_issue_ckpt; + cprc->f2fs_issue_ckpt = NULL; + kthread_stop(ckpt_task); - flush_remained_ckpt_reqs(sbi, NULL); - } + f2fs_flush_ckpt_thread(sbi); +} + +void f2fs_flush_ckpt_thread(struct f2fs_sb_info *sbi) +{ + struct ckpt_req_control *cprc = &sbi->cprc_info; + + if (!cprc->f2fs_issue_ckpt) + return; + + flush_remained_ckpt_reqs(sbi, NULL); + + /* Let's wait for the previous dispatched checkpoint. */ + while (atomic_read(&cprc->queued_ckpt)) + io_schedule_timeout(DEFAULT_IO_TIMEOUT); } void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 3c7cdb70fe2e..2a83fc34b372 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3707,6 +3707,7 @@ static inline bool f2fs_need_rand_seg(struct f2fs_sb_info *sbi) * checkpoint.c */ void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); +void f2fs_flush_ckpt_thread(struct f2fs_sb_info *sbi); struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 212ec2b4926b..48ac3de4a533 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1670,9 +1670,8 @@ static int f2fs_freeze(struct super_block *sb) if (is_sbi_flag_set(F2FS_SB(sb), SBI_IS_DIRTY)) return -EINVAL; - /* ensure no checkpoint required */ - if (!llist_empty(&F2FS_SB(sb)->cprc_info.issue_list)) - return -EINVAL; + /* Let's flush checkpoints and stop the thread. */ + f2fs_flush_ckpt_thread(F2FS_SB(sb)); /* to avoid deadlock on f2fs_evict_inode->SB_FREEZE_FS */ set_sbi_flag(F2FS_SB(sb), SBI_IS_FREEZING); -- 2.37.1.595.g718a3a8f04-goog