Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	linux-btrfs@vger.kernel.org
Cc: Naohiro Aota <naohiro.aota@wdc.com>,
	David Sterba <dsterba@suse.com>, Boris Burkov <boris@bur.io>
Subject: Re: [PATCH v7 01/27] btrfs: zoned: don't wait for a zone finish after a filesystem error
Date: Tue, 17 Nov 2026 13:07:05 -0800	[thread overview]
Message-ID: <34e278a6-37f5-46bb-8344-1ea32e60bebb@kernel.org> (raw)
In-Reply-To: <20261117185850.4128157-2-johannes.thumshirn@wdc.com>

On 11/17/26 10:58, Johannes Thumshirn wrote:
> When no zone can be activated, buffered writeback in cow_file_range() and
> direct IO in btrfs_new_extent_direct() wait uninterruptibly for
> BTRFS_FS_NEED_ZONE_FINISH to be cleared, which only happens once a zone
> is finished.
> 
> After a transaction abort or an emergency shutdown no zone gets finished
> anymore, so the waiters sleep forever. With writeback holding locked
> folios, btrfs_cleanup_transaction() then blocks in
> invalidate_inode_pages2_range() as well. generic/388 hangs this way.
> 
> Clear the bit and wake the waiters when the filesystem error is set,
> clear it again if it gets set after an error was recorded, and let the
> waiters bail out with the filesystem error.
> 
> Fixes: 2ce543f47843 ("btrfs: zoned: wait until zone is finished when allocation didn't progress")
> Fixes: 776a838f1fa9 ("btrfs: zoned: wait for data BG to be finished on direct IO allocation")
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>  fs/btrfs/direct-io.c |  4 +++-
>  fs/btrfs/fs.h        |  1 +
>  fs/btrfs/inode.c     |  3 +++
>  fs/btrfs/messages.c  |  1 +
>  fs/btrfs/zoned.c     | 10 +++++++++-
>  5 files changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/direct-io.c b/fs/btrfs/direct-io.c
> index 2cad9f048f4a..7bf048dfced6 100644
> --- a/fs/btrfs/direct-io.c
> +++ b/fs/btrfs/direct-io.c
> @@ -191,7 +191,9 @@ static struct extent_map *btrfs_new_extent_direct(struct btrfs_inode *inode,
>  		ASSERT(btrfs_is_zoned(fs_info));
>  		wait_on_bit_io(&inode->root->fs_info->flags, BTRFS_FS_NEED_ZONE_FINISH,
>  			       TASK_UNINTERRUPTIBLE);
> -		goto again;
> +		ret = BTRFS_FS_ERROR(fs_info);
> +		if (likely(!ret))
> +			goto again;
>  	}
>  	if (ret)
>  		return ERR_PTR(ret);
> diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
> index 2dd167c32d61..84a6eb2ebf83 100644
> --- a/fs/btrfs/fs.h
> +++ b/fs/btrfs/fs.h
> @@ -1232,6 +1232,7 @@ static inline void btrfs_force_shutdown(struct btrfs_fs_info *fs_info)
>  	 * So here we only mark the fs error without flipping it RO.
>  	 */
>  	WRITE_ONCE(fs_info->fs_error, -EIO);
> +	clear_and_wake_up_bit(BTRFS_FS_NEED_ZONE_FINISH, &fs_info->flags);
>  	if (!test_and_set_bit(BTRFS_FS_STATE_EMERGENCY_SHUTDOWN, &fs_info->fs_state)) {
>  		btrfs_crit(fs_info, "emergency shutdown");
>  		fserror_report_shutdown(fs_info->sb, GFP_KERNEL);
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 4b29b82eb180..319488794320 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -1409,6 +1409,9 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
>  				wait_on_bit_io(&inode->root->fs_info->flags,
>  					       BTRFS_FS_NEED_ZONE_FINISH,
>  					       TASK_UNINTERRUPTIBLE);
> +				ret = BTRFS_FS_ERROR(fs_info);
> +				if (unlikely(ret))
> +					goto out_unlock;
>  				continue;
>  			}
>  			if (done_offset) {
> diff --git a/fs/btrfs/messages.c b/fs/btrfs/messages.c
> index 73acb69c3849..2722751401b0 100644
> --- a/fs/btrfs/messages.c
> +++ b/fs/btrfs/messages.c
> @@ -163,6 +163,7 @@ void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function
>  	 * send it down to the disk.
>  	 */
>  	WRITE_ONCE(fs_info->fs_error, error);
> +	clear_and_wake_up_bit(BTRFS_FS_NEED_ZONE_FINISH, &fs_info->flags);
>  
>  	/* Don't go through full error handling during mount. */
>  	if (!(sb->s_flags & SB_BORN))
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index b1be02eeba68..ca0aedb916bf 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -2773,8 +2773,16 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
>  	spin_unlock(&fs_info->zone_active_bgs_lock);
>  	mutex_unlock(&fs_info->chunk_mutex);
>  
> -	if (!ret)
> +	if (!ret) {
>  		set_bit(BTRFS_FS_NEED_ZONE_FINISH, &fs_info->flags);
> +		/*
> +		 * No zone gets finished after a filesystem error, don't let
> +		 * anybody wait for it. Pairs with the clear in the error paths.
> +		 */
> +		smp_mb__after_atomic();

Looks good to me, but inserting the comment block here between the set_bit() and
smp_mb__after_atomic() is odd looking. I would keep these together as they
should be.

The comment describes why the "if" is here, so let' move it right before it.
Also, the comment would be nicer as:

		/*
		 * No zone gets finished after a filesystem error, so do not let
		 * anybody wait for it. This pairs with the clear in the error
		 * path.
		 */


s/error, don't let/error, so do not let

> +		if (unlikely(BTRFS_FS_ERROR(fs_info)))
> +			clear_and_wake_up_bit(BTRFS_FS_NEED_ZONE_FINISH, &fs_info->flags);
> +	}
>  
>  	return ret;
>  }


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2026-11-17 21:07 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 18:58 [PATCH v7 00/27] btrfs: zoned: fixes for generic/747 Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 01/27] btrfs: zoned: don't wait for a zone finish after a filesystem error Johannes Thumshirn
2026-11-17 21:07   ` Damien Le Moal [this message]
2026-11-17 18:58 ` [PATCH v7 02/27] btrfs: zoned: reject dev-replace onto a target with different zone types Johannes Thumshirn
2026-11-17 21:08   ` Damien Le Moal
2026-11-17 18:58 ` [PATCH v7 03/27] btrfs: zoned: fix possible race for reserved_active_zones Johannes Thumshirn
2026-11-17 21:09   ` Damien Le Moal
2026-11-17 18:58 ` [PATCH v7 04/27] btrfs: zoned: don't use active zones for conventional stripes Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 05/27] btrfs: zoned: skip the append only metadata writeback path for conventional block groups Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 06/27] btrfs: zoned: never activate conventional metadata " Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 07/27] btrfs: zoned: use the regular allocator for " Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 08/27] btrfs: zoned: only take the metadata IO lock for append only " Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 09/27] btrfs: zoned: allow restricting the dev extent search to a zone type Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 10/27] btrfs: zoned: prefer conventional zones for metadata chunks Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 11/27] btrfs: zoned: use plain mutex lock in check_bg_is_active Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 12/27] btrfs: zoned: use plain mutex lock in btrfs_zoned_release_dirty_metadata Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 13/27] btrfs: zoned: remove btrfs_zoned_meta_io_(un)lock Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 14/27] btrfs: zoned: prefer sequential zones for data chunks Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 15/27] btrfs: zoned: wait for a running block group reclaim in RECLAIM_ZONES Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 16/27] btrfs: zoned: don't count in-flight data as available in statfs Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 17/27] btrfs: zoned: don't recheck the reclaim threshold of full zoned block-groups Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 18/27] btrfs: zoned: don't account superblock zones as available data space Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 19/27] btrfs: zoned: factor out resetting a block group in place Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 20/27] btrfs: zoned: prepare reserving the data relocation block group at runtime Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 21/27] btrfs: zoned: promote reset data block groups to the relocation target Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 22/27] btrfs: zoned: return finished relocation block groups to the data space_info Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 23/27] btrfs: zoned: reuse block groups emptied by reclaim as relocation target Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 24/27] btrfs: add btrfs_bg_type_to_num_stripes Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 25/27] btrfs: zoned: keep a zone free for relocation when allocating data chunks Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 26/27] btrfs: zoned: don't count the relocation zone reserve as available in statfs Johannes Thumshirn
2026-11-17 18:58 ` [PATCH v7 27/27] btrfs: zoned: provide zoned specific reclaim sweep Johannes Thumshirn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=34e278a6-37f5-46bb-8344-1ea32e60bebb@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=boris@bur.io \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=naohiro.aota@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox