Skip to content

Commit ca5e4ea

Browse files
naotakdave
authored andcommitted
btrfs: zoned: mark relocation as writing
There is a hung_task issue with running generic/068 on an SMR device. The hang occurs while a process is trying to thaw the filesystem. The process is trying to take sb->s_umount to thaw the FS. The lock is held by fsstress, which calls btrfs_sync_fs() and is waiting for an ordered extent to finish. However, as the FS is frozen, the ordered extents never finish. Having an ordered extent while the FS is frozen is the root cause of the hang. The ordered extent is initiated from btrfs_relocate_chunk() which is called from btrfs_reclaim_bgs_work(). This commit adds sb_*_write() around btrfs_relocate_chunk() call site. For the usual "btrfs balance" command, we already call it with mnt_want_file() in btrfs_ioctl_balance(). Fixes: 18bb8bb ("btrfs: zoned: automatically reclaim zones") CC: stable@vger.kernel.org # 5.13+ Link: naota#56 Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 9f5710b commit ca5e4ea

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

fs/btrfs/block-group.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,15 +1522,20 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
15221522
if (!test_bit(BTRFS_FS_OPEN, &fs_info->flags))
15231523
return;
15241524

1525-
if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE))
1525+
sb_start_write(fs_info->sb);
1526+
1527+
if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) {
1528+
sb_end_write(fs_info->sb);
15261529
return;
1530+
}
15271531

15281532
/*
15291533
* Long running balances can keep us blocked here for eternity, so
15301534
* simply skip reclaim if we're unable to get the mutex.
15311535
*/
15321536
if (!mutex_trylock(&fs_info->reclaim_bgs_lock)) {
15331537
btrfs_exclop_finish(fs_info);
1538+
sb_end_write(fs_info->sb);
15341539
return;
15351540
}
15361541

@@ -1605,6 +1610,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
16051610
spin_unlock(&fs_info->unused_bgs_lock);
16061611
mutex_unlock(&fs_info->reclaim_bgs_lock);
16071612
btrfs_exclop_finish(fs_info);
1613+
sb_end_write(fs_info->sb);
16081614
}
16091615

16101616
void btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info)

fs/btrfs/volumes.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8304,10 +8304,12 @@ static int relocating_repair_kthread(void *data)
83048304
target = cache->start;
83058305
btrfs_put_block_group(cache);
83068306

8307+
sb_start_write(fs_info->sb);
83078308
if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) {
83088309
btrfs_info(fs_info,
83098310
"zoned: skip relocating block group %llu to repair: EBUSY",
83108311
target);
8312+
sb_end_write(fs_info->sb);
83118313
return -EBUSY;
83128314
}
83138315

@@ -8335,6 +8337,7 @@ static int relocating_repair_kthread(void *data)
83358337
btrfs_put_block_group(cache);
83368338
mutex_unlock(&fs_info->reclaim_bgs_lock);
83378339
btrfs_exclop_finish(fs_info);
8340+
sb_end_write(fs_info->sb);
83388341

83398342
return ret;
83408343
}

0 commit comments

Comments
 (0)