From: Qu Wenruo <wqu@suse.com>
To: dsterba@suse.cz
Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz
Subject: Re: [PATCH v4 5/6] btrfs: implement shutdown ioctl
Date: Sun, 6 Jul 2025 13:07:19 +0930 [thread overview]
Message-ID: <6642f8b5-d357-4fb6-a295-906178a633f9@suse.com> (raw)
In-Reply-To: <20250705142230.GC4453@twin.jikos.cz>
在 2025/7/5 23:52, David Sterba 写道:
> On Fri, Jul 04, 2025 at 10:12:33AM +0930, Qu Wenruo wrote:
>> The shutdown ioctl should follow the XFS one, which use magic number 'X',
>> and ioctl number 125, with a u32 as flags.
>>
>> For now btrfs don't distinguish DEFAULT and LOGFLUSH flags (just like
>> f2fs), both will freeze the fs first (implies committing the current
>> transaction), setting the SHUTDOWN flag and finally thaw the fs.
>>
>> For NOLOGFLUSH flag, the freeze/thaw part is skipped thus the current
>> transaction is aborted.
>>
>> The new shutdown ioctl is hidden behind experimental features for more
>> testing.
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>> fs/btrfs/ioctl.c | 40 ++++++++++++++++++++++++++++++++++++++
>> include/uapi/linux/btrfs.h | 9 +++++++++
>> 2 files changed, 49 insertions(+)
>>
>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>> index 2f3b7be13bea..94eb7a8499db 100644
>> --- a/fs/btrfs/ioctl.c
>> +++ b/fs/btrfs/ioctl.c
>> @@ -5194,6 +5194,36 @@ static int btrfs_ioctl_subvol_sync(struct btrfs_fs_info *fs_info, void __user *a
>> return 0;
>> }
>>
>> +#ifdef CONFIG_BTRFS_EXPERIMENTAL
>> +static int btrfs_emergency_shutdown(struct btrfs_fs_info *fs_info, u32 flags)
>> +{
>> + int ret = 0;
>> +
>> + if (flags >= BTRFS_SHUTDOWN_FLAGS_LAST)
>> + return -EINVAL;
>> +
>> + if (btrfs_is_shutdown(fs_info))
>> + return 0;
>> +
>> + switch (flags) {
>> + case BTRFS_SHUTDOWN_FLAGS_LOGFLUSH:
>> + case BTRFS_SHUTDOWN_FLAGS_DEFAULT:
>> + ret = freeze_super(fs_info->sb, FREEZE_HOLDER_KERNEL, NULL);
>
> Recently I've looked at scrub blocking filesystem freezing and it does
> not work because it blocks on the semaphore taken in mnt_want_write,
> also taken in freeze_super().
>
> I have an idea for fix, basically pause scrub, undo mnt_want_write
> and then call freeze_super. So we'll need that too for shutdown. Once
> implemented the fixup would be to use btrfs_freeze_super callback here.
It may not be that simple.
freeze_super() itself is doing extra works related to the
stage/freeze_owner/etc.
I'm not sure if it's a good idea to completely skip that part.
I'd prefer scrub to check the frozen stage, and if it's already in any
FREEZE stages, exit early.
Thanks,
Qu
>
>> + if (ret)
>> + return ret;
>> + btrfs_force_shutdown(fs_info);
>> + ret = thaw_super(fs_info->sb, FREEZE_HOLDER_KERNEL, NULL);
>> + if (ret)
>> + return ret;
>> + break;
>> + case BTRFS_SHUTDOWN_FLAGS_NOLOGFLUSH:
>> + btrfs_force_shutdown(fs_info);
>> + break;
>> + }
>> + return ret;
>> +}
>> +#endif
>> +
>> long btrfs_ioctl(struct file *file, unsigned int
>> cmd, unsigned long arg)
>> {
>
>> --- a/include/uapi/linux/btrfs.h
>> +++ b/include/uapi/linux/btrfs.h
>> @@ -1096,6 +1096,12 @@ enum btrfs_err_code {
>> BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET,
>> };
>>
>> +/* Flags for IOC_SHUTDOWN, should match XFS' flags. */
>> +#define BTRFS_SHUTDOWN_FLAGS_DEFAULT 0x0
>> +#define BTRFS_SHUTDOWN_FLAGS_LOGFLUSH 0x1
>> +#define BTRFS_SHUTDOWN_FLAGS_NOLOGFLUSH 0x2
>> +#define BTRFS_SHUTDOWN_FLAGS_LAST 0x3
>> +
>> #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
>> struct btrfs_ioctl_vol_args)
>> #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
>> @@ -1217,6 +1223,9 @@ enum btrfs_err_code {
>> #define BTRFS_IOC_SUBVOL_SYNC_WAIT _IOW(BTRFS_IOCTL_MAGIC, 65, \
>> struct btrfs_ioctl_subvol_wait)
>>
>> +/* Shutdown ioctl should follow XFS's interfaces, thus not using btrfs magic. */
>> +#define BTRFS_IOC_SHUTDOWN _IOR('X', 125, __u32)
>
> In XFS it's
>
> #define XFS_IOC_GOINGDOWN _IOR ('X', 125, uint32_t)
>
> It's right to use the same definition and ioctl value as this will
> be a generic ioctl eventually, with 3 users at least. I like the name
> SHUTDOWN better, ext4 also uses that.
next prev parent reply other threads:[~2025-07-06 3:37 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-04 0:42 [PATCH v4 0/6] btrfs: add remove_bdev() callback Qu Wenruo
2025-07-04 0:42 ` [PATCH v4 1/6] fs: enhance and rename shutdown() callback to remove_bdev() Qu Wenruo
2025-07-04 9:00 ` (subset) " Christian Brauner
2025-07-04 9:05 ` Jan Kara
2025-07-07 23:02 ` Dave Chinner
2025-07-07 23:22 ` Qu Wenruo
2025-07-08 0:45 ` Darrick J. Wong
2025-07-08 2:09 ` Qu Wenruo
2025-07-08 3:06 ` Qu Wenruo
2025-07-08 5:05 ` Dave Chinner
2025-07-08 5:41 ` Qu Wenruo
2025-07-08 7:55 ` Christian Brauner
2025-07-08 22:59 ` Dave Chinner
2025-07-08 23:07 ` Qu Wenruo
2025-07-09 0:35 ` Kent Overstreet
2025-07-09 0:55 ` Qu Wenruo
2025-07-09 1:13 ` Kent Overstreet
2025-07-10 8:33 ` Christian Brauner
2025-07-10 10:54 ` Christoph Hellwig
2025-07-08 10:20 ` Jan Kara
2025-07-08 20:20 ` Darrick J. Wong
2025-07-08 22:12 ` Qu Wenruo
2025-07-10 8:40 ` Christian Brauner
2025-07-10 9:54 ` Qu Wenruo
2025-07-11 9:34 ` Christian Brauner
2025-07-10 10:52 ` Christoph Hellwig
2025-07-04 0:42 ` [PATCH v4 2/6] btrfs: introduce a new fs state, EMERGENCY_SHUTDOWN Qu Wenruo
2025-07-04 0:42 ` [PATCH v4 3/6] btrfs: reject file operations if in shutdown state Qu Wenruo
2025-07-05 14:10 ` David Sterba
2025-07-04 0:42 ` [PATCH v4 4/6] btrfs: reject delalloc ranges " Qu Wenruo
2025-07-04 0:42 ` [PATCH v4 5/6] btrfs: implement shutdown ioctl Qu Wenruo
2025-07-05 14:22 ` David Sterba
2025-07-06 3:37 ` Qu Wenruo [this message]
2025-07-07 20:51 ` David Sterba
2025-07-07 23:04 ` Qu Wenruo
2025-07-08 0:53 ` David Sterba
2025-07-04 0:42 ` [PATCH v4 6/6] btrfs: implement remove_bdev super operation callback Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6642f8b5-d357-4fb6-a295-906178a633f9@suse.com \
--to=wqu@suse.com \
--cc=brauner@kernel.org \
--cc=dsterba@suse.cz \
--cc=jack@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox