diff mbox series

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

Message ID 09e63a62afe0c03bac24cfbfe37316f97e13e113.1646983176.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series protect relocation with sb_start_write | expand

Commit Message

Naohiro Aota March 11, 2022, 7:38 a.m. UTC
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")
Cc: stable@vger.kernel.org
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/ioctl.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Filipe Manana March 11, 2022, 2:21 p.m. UTC | #1
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?

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

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
>
Naohiro Aota March 14, 2022, 2:31 a.m. UTC | #2
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
> >
diff mbox series

Patch

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);
 	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;
 }