Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp783842lql; Mon, 11 Mar 2024 18:42:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVIxbHUJhkAxvPzVA7hqMGarDAeNreitiMLPARBXIpeWPkvQ6EqCMDi3vQs1+OmDeWoDrxXrAHyTsTHGyfW7uEcySc4rNQuvH3UY7136A== X-Google-Smtp-Source: AGHT+IEm5u/Oz2mu5/ANFLbQwB2mjgFokQUnUalxWHcLJb6zRH3U6sXRgyjy1mr5XmmyF4kv2wak X-Received: by 2002:a05:6214:188f:b0:690:735e:2ecf with SMTP id cx15-20020a056214188f00b00690735e2ecfmr9091732qvb.49.1710207766951; Mon, 11 Mar 2024 18:42:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710207766; cv=pass; d=google.com; s=arc-20160816; b=D/L9NohYob9/p5OUEZ4rm9ockCcUm83NdgetWv/U/qEn8SJfIgciXoTiR70RTO4wkO J0+0yg0qT6j0Ojf2Yt2LYU6uvvz3nQ4fMlDMtmnasKlZ6s/AU7IVeyftmjsQyVvJT+Zp LBySG2Bx6Ov+8F85gidY5oIZW11WN01M9y1pCYILkLmQp4bYU9TpsuHGjpOVsAbVZxzr 2plWAUUw6a7I8rq+PQR9CTW2Jxc6ejSsYS9fiIHu72ERnHHQfIGqOolPiOuejyJSYQ8C D5yYxfUQOSf0WocMWa3v2MSNAHYkR78RdxQb2HGWvNFZvNkL0/c374K/xgqPwNYEjwYg O2BQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=BNtHHVS7sll8Zy59j1GCzNsoL5RYzJjgtdOuP0zhT2s=; fh=M2YGjA8H0K6JhoRvG2l4gXXjZQDxr3NJ0V13Z3ijGjg=; b=rfteOrEBkpBeMDJ/yZbACe4qhNmgUxlupfIp143yLca0ajuyCokDpOic7JFw0hwINC r2QubKu4UC9tg5/vgsGEEVbuQLweNjoeSOzT8selIUrpvUCx7DYRvHX/rBQBnrW5Qkzy X81A4QQWKC0Ccy/AizXdfK9ie6+TvVnEqnE77ol5JFNxDIunr1ZHjLnFU+yN2qCasuT9 /fyZp49dbpShP+LqJZSpFqPqpxZreNTDBGGjQxHXzuODd5gQ1hFv2d13KiEPLf4DwNi1 AfLjXdpFpruZqANvb7nviNDcY899ukWcxgdkTcpN0quwhyJ2jEyxeNY55RGAF578DITu jQFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IqyLkDuT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-99738-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99738-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 5-20020ad45ba5000000b0068cd964819asi6669973qvq.392.2024.03.11.18.42.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 18:42:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99738-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IqyLkDuT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-99738-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99738-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A84FB1C212BE for ; Tue, 12 Mar 2024 01:42:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FD2379C0; Tue, 12 Mar 2024 01:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IqyLkDuT" 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 4DE086FB2 for ; Tue, 12 Mar 2024 01:42:40 +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=1710207761; cv=none; b=fryYTYh6hZTncL4Gc7qhiUVT+ixT7tFOIwIj8r72Y9xT+MxzvehNtwGxgOVHRernbX9QXOOxBZBeKKPZ9ewUvJTe/GImbzvKJk9a9gIpmxo4Jl0GDkwtt+F0FIKtpM1C5Npxx+PHUZ6iqpH5b1XOONSJt5ZdccZlJQEgx43M7AE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710207761; c=relaxed/simple; bh=ioCglCiuFytXfIPfWrP5a+ai20J7qUrjXL07BC91CnE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=o3SN9tY0gaNAOod/d2aLRt4nJ560h0YLHwdvzJUzYEUM5JINhz9y6kHaCDWEtV6aAIhuMgH8KNxupU7eiDh1cPILVHXnem5nR/19dGnjZcQ6JkkbJbq8019n+yvpOnJ/6PCBgsuBIOH6fKWhVJfj7vom06Bd6XnmJh+UXNLJgXM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IqyLkDuT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2961C433F1; Tue, 12 Mar 2024 01:42:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710207760; bh=ioCglCiuFytXfIPfWrP5a+ai20J7qUrjXL07BC91CnE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=IqyLkDuT4UQHkI1VNrl7vmcMiMTwQPqZ7GdYQ2vFZotLCiDImiI1EMvCPgIu50F6u vcvrVnNTeVoD1z+lXm1+ywBLGU5W4bDxzaKhyho2yIuKbGIGxcIjo7mC40WWCDszWr WkuqQ/NfVB5kuKv2EhMXHgSvkQpxhsUJYDqWS66PgX28s7ZXV9771/uUd9FL4g8zlq /nLe6I50ZVLBdHKrbSYFWja5AzLw52kOPpvzRmhIvJcSIndBRx8OG8TBy106hevy07 3pFcmjhO6z5LFqu+logi37OQ2A3RU5gKEHk+eSLCkOeUXGNDAeyuJUkbJbZPcMI9QG hoCF8HR55TZkw== Message-ID: <63ece9a0-ccd1-43f7-ab51-cf5adc49be71@kernel.org> Date: Tue, 12 Mar 2024 09:42:39 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] f2fs: support .shutdown in f2fs_sops Content-Language: en-US To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <20240229143838.45149-1-chao@kernel.org> From: Chao Yu In-Reply-To: <20240229143838.45149-1-chao@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Ping, On 2024/2/29 22:38, Chao Yu wrote: > 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 dentry *dentry, > struct iattr *attr); > int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); > 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; > } > > -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 = file_inode(filp); > - struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > struct super_block *sb = sbi->sb; > - __u32 in; > int ret = 0; > > - if (!capable(CAP_SYS_ADMIN)) > - return -EPERM; > - > - if (get_user(in, (__u32 __user *)arg)) > - return -EFAULT; > - > - if (in != F2FS_GOING_DOWN_FULLSYNC) { > - ret = mnt_want_write_file(filp); > - if (ret) { > - if (ret == -EROFS) { > - ret = 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 = bdev_freeze(sb->s_bdev); > if (ret) > @@ -2292,6 +2271,9 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) > goto out; > } > > + if (readonly) > + goto out; > + > f2fs_stop_gc_thread(sbi); > f2fs_stop_discard_thread(sbi); > > @@ -2300,10 +2282,44 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) > > f2fs_update_time(sbi, REQ_TIME); > out: > - if (in != F2FS_GOING_DOWN_FULLSYNC) > - mnt_drop_write_file(filp); > > - 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 = file_inode(filp); > + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > + __u32 in; > + int ret; > + bool need_drop = false, readonly = false; > + > + if (!capable(CAP_SYS_ADMIN)) > + return -EPERM; > + > + if (get_user(in, (__u32 __user *)arg)) > + return -EFAULT; > + > + if (in != F2FS_GOING_DOWN_FULLSYNC) { > + ret = mnt_want_write_file(filp); > + if (ret) { > + if (ret != -EROFS) > + return ret; > + > + /* fallback to nosync shutdown for readonly fs */ > + in = F2FS_GOING_DOWN_NOSYNC; > + readonly = true; > + } else { > + need_drop = true; > + } > + } > + > + ret = f2fs_do_shutdown(sbi, in, readonly); > + > + if (need_drop) > + mnt_drop_write_file(filp); > > 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; > } > > +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 = { > .unfreeze_fs = f2fs_unfreeze, > .statfs = f2fs_statfs, > .remount_fs = f2fs_remount, > + .shutdown = f2fs_shutdown, > }; > > #ifdef CONFIG_FS_ENCRYPTION