Re: [PATCH v4 3/6] btrfs: reject file operations if in shutdown state

David Sterba
2025-07-05T14:10:41Z

On Fri, Jul 04, 2025 at 10:12:31AM +0930, Qu Wenruo wrote:
> This includes the following callbacks of file_operations:
>
> - read_iter()
> - write_iter()
> - mmap()
> - open()
> - remap_file_range()
> - uring_cmd()
> - splice_read()
> This requires a small wrapper to do the extra shutdown check, then call
> the regular filemap_splice_read() function
>
> This should reject most of the file operations on a shutdown btrfs.
>
> The callback ioctl() is intentionally skipped, as ext4 doesn't do the
> shutdown check on ioctl() either, thus I believe there is some special
> require for ioctl() callback even if the fs is fully shutdown.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> fs/btrfs/file.c | 25 ++++++++++++++++++++++++-
> fs/btrfs/ioctl.c | 3 +++
> fs/btrfs/reflink.c | 3 +++
> 3 files changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 05b046c6806f..cb7d1d53fc13 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -1419,6 +1419,8 @@ ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from,
> struct btrfs_inode *inode = BTRFS_I(file_inode(file));
> ssize_t num_written, num_sync;
>
> + if (unlikely(btrfs_is_shutdown(inode->root->fs_info)))

This looks like a repetitive pattern, it would be better to do something
like

#define IS_SHUTDOWN(fs_info) (unlikely(btrfs_is_shutdown(fs_info))

Eventually we can use _Generic to pick the fs_info from the most
commonly used types, like inode or root.