FAILED: patch "[PATCH] btrfs: zoned: fix missing chunk metadata reservation" failed to apply to 6.6-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 8bc4d7209611e8aa9d5409b6a4a86a9eb91b69a3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026080520-wikipedia-kindness-ddd8@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 8bc4d7209611e8aa9d5409b6a4a86a9eb91b69a3 Mon Sep 17 00:00:00 2001
From: Guanghui Yang <[email protected]>
Date: Tue, 14 Jul 2026 17:55:43 +0800
Subject: [PATCH] btrfs: zoned: fix missing chunk metadata reservation
reserve_chunk_space() stores the return value of btrfs_zoned_activate_one_bg() in ret. The helper can return 1 after successfully activating a block group, but ret is later used to decide whether to reserve metadata for chunk tree updates.
As a result, successful activation skips btrfs_block_rsv_add() and leaves trans->chunk_bytes_reserved unchanged. Use a separate variable for the activation result so positive success does not affect the later reservation. Keep activation failures in ret instead of returning early so the function uses the common tail path.
fs/btrfs/block-group.c +19 -15
@@ -4532,25 +4532,29 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,if (IS_ERR (bg)) { ret =PTR_ERR (bg); }else { +int activate_ret; +/* * We have a new chunk. We also need to activate it for * zoned filesystem. */ - ret =btrfs_zoned_activate_one_bg (info, true); -if (ret <0 ) -return ; - -/* -* If we fail to add the chunk item here, we end up -* trying again at phase 2 of chunk allocation, at -* btrfs_create_pending_block_groups(). So ignore -* any error here. An ENOSPC here could happen, due to -* the cases described at do_chunk_alloc() - the system -* block group we just created was just turned into RO -* mode by a scrub for example, or a running discard -* temporarily removed its free space entries, etc. -*/ -btrfs_chunk_alloc_add_chunk_item (trans, bg); + activate_ret =btrfs_zoned_activate_one_bg (info, true); +if (activate_ret <0 ) { + ret = activate_ret; + }else { +/* +* If we fail to add the chunk item here, we end +* up trying again at phase 2 of chunk allocation, +* at btrfs_create_pending_block_groups(). So +* ignore any error here. An ENOSPC here could +* happen, due to the cases described at +* do_chunk_alloc() - the system block group we +* just created was just turned into RO mode by a +* scrub for example, or a running discard +* temporarily removed its free space entries, etc. +*/ +btrfs_chunk_alloc_add_chunk_item (trans, bg); + } } }
Sasha Levin
maintainerPATCH 1/4 btrfs: add debug build only WARN
From: David Sterba <[email protected]>
[ Upstream commit 3db15c6ca6feb2c5000a1cbb39c33866e0349abd ]
Add conditional WARN() wrapper that's enabled only in debug build. It should be used for unexpected conditions that should be noisy. Use it instead of ASSERT(0). As it will not lead to BUG() make sure that continuing is still possible, e.g. the error is handled anyway.
Stable-dep-of: 8bc4d7209611 ("btrfs: zoned: fix missing chunk metadata reservation")
--- fs/btrfs/messages.h | 7 +++++++ 1 file changed, 7 insertions(+)
fs/btrfs/messages.h +7 -0
@@ -181,6 +181,13 @@ do { \#define ASSERT (expr) (void)(expr)#endif +#ifdef CONFIG_BTRFS_DEBUG +/* Verbose warning only under debug build. */ +#define DEBUG_WARN(args...) WARN(1, KERN_ERR args) +#else +#define DEBUG_WARN (...) do {} while(0) +#endif + __printf(5, 6)__cold void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 btrfs: add space_info argument to btrfs_chunk_alloc()
From: Naohiro Aota <[email protected]>
[ Upstream commit 098a442d5b6d440602604dc1a88706a2a91bce4e ]
Take a btrfs_space_info argument in btrfs_chunk_alloc(). New block group will belong to that space_info.
Stable-dep-of: 8bc4d7209611 ("btrfs: zoned: fix missing chunk metadata reservation")
--- fs/btrfs/block-group.c | 27 +++++++++++++++++---------- fs/btrfs/block-group.h | 3 ++- fs/btrfs/extent-tree.c | 6 ++++-- fs/btrfs/space-info.c | 2 +- fs/btrfs/transaction.c | 5 +++-- 5 files changed, 27 insertions(+), 16 deletions(-)
fs/btrfs/block-group.c +17 -10
@@ -2929,6 +2929,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache, bool do_chunk_alloc) {struct btrfs_fs_info *fs_info = cache->fs_info; +struct btrfs_space_info *space_info = cache->space_info;struct btrfs_trans_handle *trans;struct btrfs_root *root =btrfs_block_group_root (fs_info);u64 alloc_flags;
@@ -2981,7 +2982,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,*/ alloc_flags =btrfs_get_alloc_profile (fs_info, cache->flags);if (alloc_flags != cache->flags) { - ret =btrfs_chunk_alloc (trans, alloc_flags, + ret =btrfs_chunk_alloc (trans, space_info, alloc_flags,CHUNK_ALLOC_FORCE );/* * ENOSPC is allowed here, we may have enough space
@@ -3009,15 +3010,15 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache, (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM)) goto unlock_out; - alloc_flags =btrfs_get_alloc_profile (fs_info, cache->space_info->flags); - ret =btrfs_chunk_alloc (trans, alloc_flags,CHUNK_ALLOC_FORCE ); + alloc_flags =btrfs_get_alloc_profile (fs_info, space_info->flags); + ret =btrfs_chunk_alloc (trans, space_info, alloc_flags,CHUNK_ALLOC_FORCE );if (ret <0 ) goto out;/* * We have allocated a new chunk. We also need to activate that chunk to * grant metadata tickets for zoned filesystem. */ - ret =btrfs_zoned_activate_one_bg (fs_info, cache->space_info, true); + ret =btrfs_zoned_activate_one_bg (fs_info, space_info, true);if (ret <0 ) goto out;
@@ -3875,8 +3876,15 @@ static int should_alloc_chunk(const struct btrfs_fs_info *fs_info,int btrfs_force_chunk_alloc (struct btrfs_trans_handle *trans,u64 type) {u64 alloc_flags =btrfs_get_alloc_profile (trans->fs_info, type); +struct btrfs_space_info *space_info; + + space_info =btrfs_find_space_info (trans->fs_info, type); +if (!space_info) { +DEBUG_WARN (); +return -EINVAL ; + } -return btrfs_chunk_alloc (trans, alloc_flags,CHUNK_ALLOC_FORCE ); +return btrfs_chunk_alloc (trans, space_info, alloc_flags,CHUNK_ALLOC_FORCE ); }static struct btrfs_block_group *do_chunk_alloc (struct btrfs_trans_handle *trans,u64 flags)
@@ -4072,6 +4080,8 @@ static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans* * This function, btrfs_chunk_alloc(), belongs to phase 1. * +* @space_info: specify which space_info the new chunk should belong to. +* * If @force is CHUNK_ALLOC_FORCE: * - return 1 if it successfully allocates a chunk, * - return errors including -ENOSPC otherwise.
@@ -4080,11 +4090,11 @@ static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans* - return 1 if it successfully allocates a chunk, * - return errors including -ENOSPC otherwise. */ -int btrfs_chunk_alloc (struct btrfs_trans_handle *trans,u64 flags, +int btrfs_chunk_alloc (struct btrfs_trans_handle *trans, +struct btrfs_space_info *space_info,u64 flags,enum btrfs_chunk_alloc_enum force) {struct btrfs_fs_info *fs_info = trans->fs_info; -struct btrfs_space_info *space_info;struct btrfs_block_group *ret_bg;bool wait_for_alloc = false;bool should_alloc = false;
@@ -4123,9 +4133,6 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,if (flags &BTRFS_BLOCK_GROUP_SYSTEM )return -ENOSPC ; - space_info =btrfs_find_space_info (fs_info, flags); -ASSERT (space_info); - do { spin_lock(&space_info->lock); if (force < space_info->force_alloc)
fs/btrfs/block-group.h +2 -1
@@ -327,7 +327,8 @@ int btrfs_add_reserved_bytes(struct btrfs_block_group *cache, bool force_wrong_size_class);void btrfs_free_reserved_bytes (struct btrfs_block_group *cache,u64 num_bytes,int delalloc); -int btrfs_chunk_alloc (struct btrfs_trans_handle *trans,u64 flags, +int btrfs_chunk_alloc (struct btrfs_trans_handle *trans, +struct btrfs_space_info *space_info,u64 flags,enum btrfs_chunk_alloc_enum force);int btrfs_force_chunk_alloc (struct btrfs_trans_handle *trans,u64 type);void check_system_chunk (struct btrfs_trans_handle *trans,const u64 type);
fs/btrfs/extent-tree.c +4 -2
@@ -4034,6 +4034,7 @@ static int can_allocate_chunk(struct btrfs_fs_info *fs_info,static int find_free_extent_update_loop (struct btrfs_fs_info *fs_info,struct btrfs_key *ins,struct find_free_extent_ctl *ffe_ctl, +struct btrfs_space_info *space_info,bool full_search) {struct btrfs_root *root = fs_info->chunk_root;
@@ -4088,7 +4089,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info,return ret; } - ret =btrfs_chunk_alloc (trans, ffe_ctl->flags, + ret =btrfs_chunk_alloc (trans, space_info, ffe_ctl->flags,CHUNK_ALLOC_FORCE_FOR_EXTENT );/* Do not bail out on ENOSPC since we can do more. */
@@ -4488,7 +4489,8 @@ static noinline int find_free_extent(struct btrfs_root *root, }up_read (&space_info->groups_sem); - ret =find_free_extent_update_loop (fs_info, ins, ffe_ctl, full_search); + ret =find_free_extent_update_loop (fs_info, ins, ffe_ctl, space_info, + full_search);if (ret >0 ) goto search;
fs/btrfs/space-info.c +1 -1
@@ -807,7 +807,7 @@ static void flush_space(struct btrfs_fs_info *fs_info, ret =PTR_ERR (trans);break ; } - ret =btrfs_chunk_alloc (trans, + ret =btrfs_chunk_alloc (trans, space_info,btrfs_get_alloc_profile (fs_info, space_info->flags), (state ==ALLOC_CHUNK ) ?CHUNK_ALLOC_NO_FORCE :CHUNK_ALLOC_FORCE );
fs/btrfs/transaction.c +3 -2
@@ -729,9 +729,10 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,* value here. */ if (do_chunk_alloc && num_bytes) { -u64 flags = h->block_rsv->space_info->flags; +struct btrfs_space_info *space_info = h->block_rsv->space_info; +u64 flags = space_info->flags; -btrfs_chunk_alloc (h,btrfs_get_alloc_profile (fs_info, flags), +btrfs_chunk_alloc (h, space_info,btrfs_get_alloc_profile (fs_info, flags),CHUNK_ALLOC_NO_FORCE ); }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 btrfs: remove fs_info argument from btrfs_zoned_activate_one_bg()
In reply to Sasha LevinFrom: Filipe Manana <[email protected]>
[ Upstream commit a232ff90d14657c8637c6e94b606bb5d700a2ecb ]
We don't need it since we can grab fs_info from the given space_info. So remove the fs_info argument.
Stable-dep-of: 8bc4d7209611 ("btrfs: zoned: fix missing chunk metadata reservation")
--- fs/btrfs/block-group.c | 4 ++-- fs/btrfs/zoned.c | 5 ++--- fs/btrfs/zoned.h | 6 ++---- 3 files changed, 6 insertions(+), 9 deletions(-)
fs/btrfs/block-group.c +2 -2
@@ -3018,7 +3018,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,* We have allocated a new chunk. We also need to activate that chunk to * grant metadata tickets for zoned filesystem. */ - ret =btrfs_zoned_activate_one_bg (fs_info, space_info, true); + ret =btrfs_zoned_activate_one_bg (space_info, true);if (ret <0 ) goto out;
@@ -4284,7 +4284,7 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,* We have a new chunk. We also need to activate it for * zoned filesystem. */ - ret =btrfs_zoned_activate_one_bg (fs_info, info, true); + ret =btrfs_zoned_activate_one_bg (info, true);if (ret <0 )return ;
fs/btrfs/zoned.c +2 -3
@@ -2453,10 +2453,9 @@ int btrfs_zone_finish_one_bg(struct btrfs_fs_info *fs_info)return ret <0 ? ret :1 ; } -int btrfs_zoned_activate_one_bg (struct btrfs_fs_info *fs_info, -struct btrfs_space_info *space_info, -bool do_finish) +int btrfs_zoned_activate_one_bg (struct btrfs_space_info *space_info,bool do_finish) { +struct btrfs_fs_info *fs_info = space_info->fs_info;struct btrfs_block_group *bg;int index;
fs/btrfs/zoned.h +2 -4
@@ -81,8 +81,7 @@ bool btrfs_zoned_should_reclaim(const struct btrfs_fs_info *fs_info);void btrfs_zoned_release_data_reloc_bg (struct btrfs_fs_info *fs_info,u64 logical,u64 length);int btrfs_zone_finish_one_bg (struct btrfs_fs_info *fs_info); -int btrfs_zoned_activate_one_bg (struct btrfs_fs_info *fs_info, -struct btrfs_space_info *space_info,bool do_finish); +int btrfs_zoned_activate_one_bg (struct btrfs_space_info *space_info,bool do_finish);void btrfs_check_active_zone_reservation (struct btrfs_fs_info *fs_info);#else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
@@ -253,8 +252,7 @@ static inline int btrfs_zone_finish_one_bg(struct btrfs_fs_info *fs_info)return 1 ; } -static inline int btrfs_zoned_activate_one_bg (struct btrfs_fs_info *fs_info, -struct btrfs_space_info *space_info, +static inline int btrfs_zoned_activate_one_bg (struct btrfs_space_info *space_info,bool do_finish) {/* Consider all the block groups are active */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 btrfs: zoned: fix missing chunk metadata reservation
In reply to Sasha LevinFrom: Guanghui Yang <[email protected]>
[ Upstream commit 8bc4d7209611e8aa9d5409b6a4a86a9eb91b69a3 ]
reserve_chunk_space() stores the return value of btrfs_zoned_activate_one_bg() in ret. The helper can return 1 after successfully activating a block group, but ret is later used to decide whether to reserve metadata for chunk tree updates.
As a result, successful activation skips btrfs_block_rsv_add() and leaves trans->chunk_bytes_reserved unchanged. Use a separate variable for the activation result so positive success does not affect the later reservation. Keep activation failures in ret instead of returning early so the function uses the common tail path.
--- fs/btrfs/block-group.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
fs/btrfs/block-group.c +19 -15
@@ -4280,25 +4280,29 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,if (IS_ERR (bg)) { ret =PTR_ERR (bg); }else { +int activate_ret; +/* * We have a new chunk. We also need to activate it for * zoned filesystem. */ - ret =btrfs_zoned_activate_one_bg (info, true); -if (ret <0 ) -return ; - -/* -* If we fail to add the chunk item here, we end up -* trying again at phase 2 of chunk allocation, at -* btrfs_create_pending_block_groups(). So ignore -* any error here. An ENOSPC here could happen, due to -* the cases described at do_chunk_alloc() - the system -* block group we just created was just turned into RO -* mode by a scrub for example, or a running discard -* temporarily removed its free space entries, etc. -*/ -btrfs_chunk_alloc_add_chunk_item (trans, bg); + activate_ret =btrfs_zoned_activate_one_bg (info, true); +if (activate_ret <0 ) { + ret = activate_ret; + }else { +/* +* If we fail to add the chunk item here, we end +* up trying again at phase 2 of chunk allocation, +* at btrfs_create_pending_block_groups(). So +* ignore any error here. An ENOSPC here could +* happen, due to the cases described at +* do_chunk_alloc() - the system block group we +* just created was just turned into RO mode by a +* scrub for example, or a running discard +* temporarily removed its free space entries, etc. +*/ +btrfs_chunk_alloc_add_chunk_item (trans, bg); + } } }
Signature · 1 line
2.53.0