Re: [PATCH 2/4] btrfs: mark device addition as sb_writing

Naohiro Aota
2022-03-14T02:31:50Z

On Fri, Mar 11, 2022 at 02:21:14PM +0000, Filipe Manana wrote:
> On Fri, Mar 11, 2022 at 04:38:03PM +0900, Naohiro Aota wrote:
> > btrfs_init_new_device() calls btrfs_relocate_sys_chunk() which incurs
> > file-system internal writing. That writing can cause a deadlock with
> > FS freezing like as described in like as described in commit
> > 26559780b953 ("btrfs: zoned: mark relocation as writing").
> >
> > Mark the device addition as sb_writing. This is also consistent with
> > the removing device ioctl counterpart.
> >
> > Fixes: 5accdf82ba25 ("fs: Improve filesystem freezing handling")
>
> Same comment as the previous patch about this.
>
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> > ---
> > fs/btrfs/ioctl.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> > index 238cee5b5254..ffa30fd3eed2 100644
> > --- a/fs/btrfs/ioctl.c
> > +++ b/fs/btrfs/ioctl.c
> > @@ -3484,6 +3484,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_fs_info *fs_info, void __user *arg)
> > return -EINVAL;
> > }
> >
> > + sb_start_write(fs_info->sb);
>
> Why not use mnt_want_write_file(), just like all the other ioctls that need
> to do some change to the fs?

This is just because there are no "struct file *" here.

> We don't have the struct file * here at btrfs_ioctl_add_dev(), but we have
> it in its caller, btrfs_ioctl().

So, I'll fix the patch in this way. Thanks.

> Thanks.
>
> > if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_DEV_ADD)) {
> > if (!btrfs_exclop_start_try_lock(fs_info, BTRFS_EXCLOP_DEV_ADD))
> > return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
> > @@ -3516,6 +3517,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_fs_info *fs_info, void __user *arg)
> > btrfs_exclop_balance(fs_info, BTRFS_EXCLOP_BALANCE_PAUSED);
> > else
> > btrfs_exclop_finish(fs_info);
> > + sb_end_write(fs_info->sb);
> > return ret;
> > }
> >
> > --
> > 2.35.1
> >