linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] btrfs: fix BUG trying to resume balance without resume flag
@ 2018-05-17  7:16 Anand Jain
  2018-05-17 12:10 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Anand Jain @ 2018-05-17  7:16 UTC (permalink / raw)
  To: linux-btrfs

We set the BTRFS_BALANCE_RESUME flag in the btrfs_recover_balance()
only, which isn't called during the remount. So when resuming from
the paused balance we hit the BUG.

 kernel: kernel BUG at fs/btrfs/volumes.c:3890!
 ::
 kernel:  balance_kthread+0x51/0x60 [btrfs]
 kernel:  kthread+0x111/0x130
 ::
 kernel: RIP: btrfs_balance+0x12e1/0x1570 [btrfs] RSP: ffffba7d0090bde8

Reproducer:
  On a mounted BTRFS.

  btrfs balance start --full-balance /btrfs
  btrfs balance pause /btrfs
  mount -o remount,ro /dev/sdb /btrfs
  mount -o remount,rw /dev/sdb /btrfs

To fix this set the BTRFS_BALANCE_RESUME flag in btrfs_resume_balance_async().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2->v3: . Hold fs_info->balance_lock because in remount context there can
	be more the one thread accessing the balance_ctl.
	. Don't remove the BTRFS_BALANCE_RESUME set at recover_balance
	as in the original code.
	. Add comments.
v1->v2: btrfs_resume_balance_async() can be called only from remount or
        mount, we don't need to hold fs_info->balance_lock.

 fs/btrfs/volumes.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 40e4259bdd51..c68976856d87 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4112,6 +4112,15 @@ int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info)
 		return 0;
 	}
 
+	/*
+	 * A remount ro->rw sequence should continue with the
+	 * paused balance irrespective of who pauses it, system or
+	 * the user as of now, so set the resume flag.
+	 */
+	spin_lock(&fs_info->balance_lock);
+	fs_info->balance_ctl->flags |= BTRFS_BALANCE_RESUME;
+	spin_unlock(&fs_info->balance_lock);
+
 	tsk = kthread_run(balance_kthread, fs_info, "btrfs-balance");
 	return PTR_ERR_OR_ZERO(tsk);
 }
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] btrfs: fix BUG trying to resume balance without resume flag
  2018-05-17  7:16 [PATCH v3] btrfs: fix BUG trying to resume balance without resume flag Anand Jain
@ 2018-05-17 12:10 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2018-05-17 12:10 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Thu, May 17, 2018 at 03:16:51PM +0800, Anand Jain wrote:
> We set the BTRFS_BALANCE_RESUME flag in the btrfs_recover_balance()
> only, which isn't called during the remount. So when resuming from
> the paused balance we hit the BUG.
> 
>  kernel: kernel BUG at fs/btrfs/volumes.c:3890!
>  ::
>  kernel:  balance_kthread+0x51/0x60 [btrfs]
>  kernel:  kthread+0x111/0x130
>  ::
>  kernel: RIP: btrfs_balance+0x12e1/0x1570 [btrfs] RSP: ffffba7d0090bde8
> 
> Reproducer:
>   On a mounted BTRFS.
> 
>   btrfs balance start --full-balance /btrfs
>   btrfs balance pause /btrfs
>   mount -o remount,ro /dev/sdb /btrfs
>   mount -o remount,rw /dev/sdb /btrfs
> 
> To fix this set the BTRFS_BALANCE_RESUME flag in btrfs_resume_balance_async().
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Reviewed-by: David Sterba <dsterba@suse.com>

> ---
> v2->v3: . Hold fs_info->balance_lock because in remount context there can
> 	be more the one thread accessing the balance_ctl.
> 	. Don't remove the BTRFS_BALANCE_RESUME set at recover_balance
> 	as in the original code.
> 	. Add comments.
> v1->v2: btrfs_resume_balance_async() can be called only from remount or
>         mount, we don't need to hold fs_info->balance_lock.
> 
>  fs/btrfs/volumes.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 40e4259bdd51..c68976856d87 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -4112,6 +4112,15 @@ int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info)
>  		return 0;
>  	}
>  
> +	/*
> +	 * A remount ro->rw sequence should continue with the
> +	 * paused balance irrespective of who pauses it, system or
> +	 * the user as of now, so set the resume flag.
> +	 */

Please format comments to full 80 column width. Fixed.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-17 12:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-17  7:16 [PATCH v3] btrfs: fix BUG trying to resume balance without resume flag Anand Jain
2018-05-17 12:10 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).