linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: zoned: fix API misuse of zone finish waiting
@ 2022-08-31  4:55 Naohiro Aota
  2022-09-06 15:51 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Naohiro Aota @ 2022-08-31  4:55 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Naohiro Aota

The commit 2ce543f47843 ("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.

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

Fixes: 2ce543f47843 ("btrfs: zoned: wait until zone is finished when allocation didn't progress")
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/ctree.h   | 2 --
 fs/btrfs/disk-io.c | 1 -
 fs/btrfs/inode.c   | 7 +++----
 fs/btrfs/zoned.c   | 3 +--
 4 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0069bc86c04f..5d03fc267b58 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1089,8 +1089,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;
 
 	/* Updates are not protected by any lock */
 	struct btrfs_commit_stats commit_stats;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 912e0b2bd0c5..b5470ac2db5b 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3079,7 +3079,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;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index b9d40e25d978..e5284f2686c8 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1644,10 +1644,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;
 		}
 
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index dc96b3331bfb..9c6a8c38c67e 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -2010,8 +2010,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;
 }
-- 
2.37.3


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

* Re: [PATCH] btrfs: zoned: fix API misuse of zone finish waiting
  2022-08-31  4:55 [PATCH] btrfs: zoned: fix API misuse of zone finish waiting Naohiro Aota
@ 2022-09-06 15:51 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2022-09-06 15:51 UTC (permalink / raw)
  To: Naohiro Aota; +Cc: linux-btrfs

On Wed, Aug 31, 2022 at 01:55:48PM +0900, Naohiro Aota wrote:
> The commit 2ce543f47843 ("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.
> 
> Indeed, we can simply use wait_on_bit_io() and clear_and_wake_up_bit() on
> fs_info->flags with a proper barrier installed.
> 
> Fixes: 2ce543f47843 ("btrfs: zoned: wait until zone is finished when allocation didn't progress")
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>

Added to misc-next, thanks.

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

end of thread, other threads:[~2022-09-06 16:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-31  4:55 [PATCH] btrfs: zoned: fix API misuse of zone finish waiting Naohiro Aota
2022-09-06 15:51 ` 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).