From nobody Sat Feb 7 15:10:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 243E747F79 for ; Thu, 29 Feb 2024 14:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709217525; cv=none; b=o/ZKMoR4fviiTSkfku9mEjgh0Xxp49TYwsa8XnCk3eRs04pjhLwxqZyIK42+r2Wxdlddhh6tOi6DhHgo8kbHHiSySmyuAdhgEvdPmjCl7Ca6y3af14mzLQPdyS/VJJ6uFIVRkrSWBTTqui/kqnqvjoTrm1n8OFqkQ5UppVp1B0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709217525; c=relaxed/simple; bh=Moqfr6mUAj0cy5t4bUR4kuQxOZ7ekFifn6MgoPalCOQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=bR2kzycxfHWvTBMUVGIPiUdTUS6AmhxHP0mdSoeOSg5N8w6Xbonw7q+F4T0/NlwEbx0y1h6rKNCTxQgfHJQPvON9x+RJEzut3zSXelE33wAkmRvawxeCL6SamfAisFlE2VInbNRuLb6q74qXOyE/iBzgQS55tWGwDTM+S3REs7o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kkKCgvoV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kkKCgvoV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65E45C43390; Thu, 29 Feb 2024 14:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709217524; bh=Moqfr6mUAj0cy5t4bUR4kuQxOZ7ekFifn6MgoPalCOQ=; h=From:To:Cc:Subject:Date:From; b=kkKCgvoVVMA6OC7WTQWRwingG9cDIc5Gx9viakKIL+5b/b7E6ocZVMm7GrUM2E2AP UPsoGOrjLKZLlZAGoN1nWoGySPsMKQ8XnrRTE6IJc3eWMRHb6svfJQXtP3XQB/KYad q+4H+RJ5pc+EXc0CmEZfW/+sVIJroamt4w37xL66pJSGghkjVo9LnvrsZ8IwuAxUcT AvQGSkNvam6AwRKZYu9G69b/d3kQ8breBo5/uAWW6Twa7i9WPqcIkwfTWAZXU1k2Uh MBlds/t2e+IQgCmZ2v4FCAsRgstYb/EV/CQsp/OFsLVq8MAvc396ZXwr0g6GMyWQTJ iDqRia1gZRLYw== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH] f2fs: support .shutdown in f2fs_sops Date: Thu, 29 Feb 2024 22:38:38 +0800 Message-Id: <20240229143838.45149-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support .shutdown callback in f2fs_sops, then, it can be called to shut down the file system when underlying block device is marked dead. Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/file.c | 70 ++++++++++++++++++++++++++++++------------------- fs/f2fs/super.c | 6 +++++ 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 85eb9a8a5ed3..80789255bf68 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3506,6 +3506,8 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dent= ry *dentry, struct iattr *attr); int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_e= nd); void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); +int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag, + bool readonly); int f2fs_precache_extents(struct inode *inode); int f2fs_fileattr_get(struct dentry *dentry, struct fileattr *fa); int f2fs_fileattr_set(struct mnt_idmap *idmap, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 4ca6c693b33a..d223175b3d5c 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2226,34 +2226,13 @@ static int f2fs_ioc_abort_atomic_write(struct file = *filp) return ret; } =20 -static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) +int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag, + bool readonly) { - struct inode *inode =3D file_inode(filp); - struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct super_block *sb =3D sbi->sb; - __u32 in; int ret =3D 0; =20 - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - if (get_user(in, (__u32 __user *)arg)) - return -EFAULT; - - if (in !=3D F2FS_GOING_DOWN_FULLSYNC) { - ret =3D mnt_want_write_file(filp); - if (ret) { - if (ret =3D=3D -EROFS) { - ret =3D 0; - f2fs_stop_checkpoint(sbi, false, - STOP_CP_REASON_SHUTDOWN); - trace_f2fs_shutdown(sbi, in, ret); - } - return ret; - } - } - - switch (in) { + switch (flag) { case F2FS_GOING_DOWN_FULLSYNC: ret =3D bdev_freeze(sb->s_bdev); if (ret) @@ -2292,6 +2271,9 @@ static int f2fs_ioc_shutdown(struct file *filp, unsig= ned long arg) goto out; } =20 + if (readonly) + goto out; + f2fs_stop_gc_thread(sbi); f2fs_stop_discard_thread(sbi); =20 @@ -2300,10 +2282,44 @@ static int f2fs_ioc_shutdown(struct file *filp, uns= igned long arg) =20 f2fs_update_time(sbi, REQ_TIME); out: - if (in !=3D F2FS_GOING_DOWN_FULLSYNC) - mnt_drop_write_file(filp); =20 - trace_f2fs_shutdown(sbi, in, ret); + trace_f2fs_shutdown(sbi, flag, ret); + + return ret; +} + +static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) +{ + struct inode *inode =3D file_inode(filp); + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + __u32 in; + int ret; + bool need_drop =3D false, readonly =3D false; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (get_user(in, (__u32 __user *)arg)) + return -EFAULT; + + if (in !=3D F2FS_GOING_DOWN_FULLSYNC) { + ret =3D mnt_want_write_file(filp); + if (ret) { + if (ret !=3D -EROFS) + return ret; + + /* fallback to nosync shutdown for readonly fs */ + in =3D F2FS_GOING_DOWN_NOSYNC; + readonly =3D true; + } else { + need_drop =3D true; + } + } + + ret =3D f2fs_do_shutdown(sbi, in, readonly); + + if (need_drop) + mnt_drop_write_file(filp); =20 return ret; } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 78a76583a4aa..0676c2dcbbf7 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2547,6 +2547,11 @@ static int f2fs_remount(struct super_block *sb, int = *flags, char *data) return err; } =20 +static void f2fs_shutdown(struct super_block *sb) +{ + f2fs_do_shutdown(F2FS_SB(sb), F2FS_GOING_DOWN_NOSYNC, false); +} + #ifdef CONFIG_QUOTA static bool f2fs_need_recovery(struct f2fs_sb_info *sbi) { @@ -3146,6 +3151,7 @@ static const struct super_operations f2fs_sops =3D { .unfreeze_fs =3D f2fs_unfreeze, .statfs =3D f2fs_statfs, .remount_fs =3D f2fs_remount, + .shutdown =3D f2fs_shutdown, }; =20 #ifdef CONFIG_FS_ENCRYPTION --=20 2.40.1