btrfs: fix BUG trying to resume balance without resume flag
PATCH v3 1/1 btrfs: fix BUG trying to resume balance without resume flag
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().
---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(+)
fs/btrfs/volumes.c +9 -0
@@ -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); }
Signature · 1 line
2.7.0
Quoted 14 lines · Anand Jain
We set the
BTRFS_BALANCE_RESUMEflag in thebtrfs_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:ffffba7d0090bde8Reproducer:
On a mounted BTRFS.
Quoted 8 lines
btrfs balance start --full-balance /btrfs btrfs balance pause /btrfs mount -o remount,ro /dev/sdb /btrfs mount -o remount,rw /dev/sdb /btrfsTo fix this set the
BTRFS_BALANCE_RESUMEflag inbtrfs_resume_balance_async().Signed-off-by Anand Jain <[email protected]>
Quoted 17 lines
---
v2->v3: . Holdfs_info->balance_lockbecause in remount context there can
be more the one thread accessing thebalance_ctl.
. Don't remove theBTRFS_BALANCE_RESUMEset atrecover_balanceas in the original code.
. Add comments.v1->v2:btrfs_resume_balance_async()can be called only from remount ormount, we don't need to hold fs_info->balance_lock.fs/btrfs/volumes.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/btrfs/volumes.c +0
-0
fs/btrfs/volumes.c int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info) · line 4119
Quoted 8 lines
fs/btrfs/volumes.c +5
-0@@ -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.