diff mbox series

[v2,1/4] btrfs: mark resumed async balance as writing

Message ID bd1ecbdfca4a2873d3825afba00d462a84f7264f.1647436353.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 16, 2022, 1:22 p.m. UTC
When btrfs balance is interrupted with umount, the background balance
resumes on the next mount. There is a potential deadlock with FS freezing
here like as described in commit 26559780b953 ("btrfs: zoned: mark
relocation as writing").

Mark the process as sb_writing. To preserve the order of sb_start_write()
(or mnt_want_write_file()) and btrfs_exclop_start(), call sb_start_write()
at btrfs_resume_balance_async() before taking fs_info->super_lock.

Cc: stable@vger.kernel.org # 4.9+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/volumes.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Filipe Manana March 16, 2022, 3:57 p.m. UTC | #1
On Wed, Mar 16, 2022 at 10:22:37PM +0900, Naohiro Aota wrote:
> When btrfs balance is interrupted with umount, the background balance
> resumes on the next mount. There is a potential deadlock with FS freezing
> here like as described in commit 26559780b953 ("btrfs: zoned: mark
> relocation as writing").
> 
> Mark the process as sb_writing. To preserve the order of sb_start_write()
> (or mnt_want_write_file()) and btrfs_exclop_start(), call sb_start_write()
> at btrfs_resume_balance_async() before taking fs_info->super_lock.

This paragraph is now outdated, it should go away as it applied only to v1.
The ordering problem is no longer relevant and we don't do anything at
btrfs_resume_balance_async() anymore.

> 
> Cc: stable@vger.kernel.org # 4.9+
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>

Other than that, it looks good.

Reviewed-by: Filipe Manana <fdmanana@suse.com>

Thanks.

> ---
>  fs/btrfs/volumes.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 3fd17e87815a..3471698fd831 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -4430,10 +4430,12 @@ static int balance_kthread(void *data)
>  	struct btrfs_fs_info *fs_info = data;
>  	int ret = 0;
>  
> +	sb_start_write(fs_info->sb);
>  	mutex_lock(&fs_info->balance_mutex);
>  	if (fs_info->balance_ctl)
>  		ret = btrfs_balance(fs_info, fs_info->balance_ctl, NULL);
>  	mutex_unlock(&fs_info->balance_mutex);
> +	sb_end_write(fs_info->sb);
>  
>  	return ret;
>  }
> -- 
> 2.35.1
>
Naohiro Aota March 17, 2022, 7:11 a.m. UTC | #2
On Wed, Mar 16, 2022 at 03:57:32PM +0000, Filipe Manana wrote:
> On Wed, Mar 16, 2022 at 10:22:37PM +0900, Naohiro Aota wrote:
> > When btrfs balance is interrupted with umount, the background balance
> > resumes on the next mount. There is a potential deadlock with FS freezing
> > here like as described in commit 26559780b953 ("btrfs: zoned: mark
> > relocation as writing").
> > 
> > Mark the process as sb_writing. To preserve the order of sb_start_write()
> > (or mnt_want_write_file()) and btrfs_exclop_start(), call sb_start_write()
> > at btrfs_resume_balance_async() before taking fs_info->super_lock.
> 
> This paragraph is now outdated, it should go away as it applied only to v1.
> The ordering problem is no longer relevant and we don't do anything at
> btrfs_resume_balance_async() anymore.

Oops. I took the last sentence and unified it with the first paragraph.

> > 
> > Cc: stable@vger.kernel.org # 4.9+
> > Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> 
> Other than that, it looks good.
> 
> Reviewed-by: Filipe Manana <fdmanana@suse.com>

Thanks.

> Thanks.
> 
> > ---
> >  fs/btrfs/volumes.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> > index 3fd17e87815a..3471698fd831 100644
> > --- a/fs/btrfs/volumes.c
> > +++ b/fs/btrfs/volumes.c
> > @@ -4430,10 +4430,12 @@ static int balance_kthread(void *data)
> >  	struct btrfs_fs_info *fs_info = data;
> >  	int ret = 0;
> >  
> > +	sb_start_write(fs_info->sb);
> >  	mutex_lock(&fs_info->balance_mutex);
> >  	if (fs_info->balance_ctl)
> >  		ret = btrfs_balance(fs_info, fs_info->balance_ctl, NULL);
> >  	mutex_unlock(&fs_info->balance_mutex);
> > +	sb_end_write(fs_info->sb);
> >  
> >  	return ret;
> >  }
> > -- 
> > 2.35.1
> >
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 3fd17e87815a..3471698fd831 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4430,10 +4430,12 @@  static int balance_kthread(void *data)
 	struct btrfs_fs_info *fs_info = data;
 	int ret = 0;
 
+	sb_start_write(fs_info->sb);
 	mutex_lock(&fs_info->balance_mutex);
 	if (fs_info->balance_ctl)
 		ret = btrfs_balance(fs_info, fs_info->balance_ctl, NULL);
 	mutex_unlock(&fs_info->balance_mutex);
+	sb_end_write(fs_info->sb);
 
 	return ret;
 }