Skip to content

Commit

Permalink
btrfs: zoned: fix API misuse of zone finish waiting
Browse files Browse the repository at this point in the history
commit d5b81ce upstream.

The commit 2ce543f ("btrfs: zoned: wait until zone is finished when
allocation didn't progress") implemented a zone finish waiting mechanism
to the write path of zoned mode. However, using
wait_var_event()/wake_up_all() on fs_info->zone_finish_wait is wrong and
wait_var_event() just hangs because no one ever wakes it up once it goes
into sleep.

Instead, we can simply use wait_on_bit_io() and clear_and_wake_up_bit()
on fs_info->flags with a proper barrier installed.

Fixes: 2ce543f ("btrfs: zoned: wait until zone is finished when allocation didn't progress")
CC: stable@vger.kernel.org # 5.16+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
naota authored and gregkh committed Sep 15, 2022
1 parent 9a196af commit fddebf9
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 9 deletions.
2 changes: 0 additions & 2 deletions fs/btrfs/ctree.h
Expand Up @@ -1065,8 +1065,6 @@ struct btrfs_fs_info {

spinlock_t zone_active_bgs_lock;
struct list_head zone_active_bgs;
/* Waiters when BTRFS_FS_NEED_ZONE_FINISH is set */
wait_queue_head_t zone_finish_wait;

#ifdef CONFIG_BTRFS_FS_REF_VERIFY
spinlock_t ref_verify_lock;
Expand Down
1 change: 0 additions & 1 deletion fs/btrfs/disk-io.c
Expand Up @@ -3173,7 +3173,6 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
init_waitqueue_head(&fs_info->transaction_blocked_wait);
init_waitqueue_head(&fs_info->async_submit_wait);
init_waitqueue_head(&fs_info->delayed_iputs_wait);
init_waitqueue_head(&fs_info->zone_finish_wait);

/* Usable values until the real ones are cached from the superblock */
fs_info->nodesize = 4096;
Expand Down
7 changes: 3 additions & 4 deletions fs/btrfs/inode.c
Expand Up @@ -1643,10 +1643,9 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
done_offset = end;

if (done_offset == start) {
struct btrfs_fs_info *info = inode->root->fs_info;

wait_var_event(&info->zone_finish_wait,
!test_bit(BTRFS_FS_NEED_ZONE_FINISH, &info->flags));
wait_on_bit_io(&inode->root->fs_info->flags,
BTRFS_FS_NEED_ZONE_FINISH,
TASK_UNINTERRUPTIBLE);
continue;
}

Expand Down
3 changes: 1 addition & 2 deletions fs/btrfs/zoned.c
Expand Up @@ -2016,8 +2016,7 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
/* For active_bg_list */
btrfs_put_block_group(block_group);

clear_bit(BTRFS_FS_NEED_ZONE_FINISH, &fs_info->flags);
wake_up_all(&fs_info->zone_finish_wait);
clear_and_wake_up_bit(BTRFS_FS_NEED_ZONE_FINISH, &fs_info->flags);

return 0;
}
Expand Down

0 comments on commit fddebf9

Please sign in to comment.