* [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling
@ 2026-02-03 17:23 Adarsh Das
2026-02-03 17:23 ` [PATCH 1/2] btrfs: handle unexpected exact match in btrfs_set_inode_index_count() Adarsh Das
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Adarsh Das @ 2026-02-03 17:23 UTC (permalink / raw)
To: Chris Mason, David Sterba; +Cc: linux-btrfs, linux-kernel, Adarsh Das
Both patches fix cases where a search with offset (u64)-1 gets an
unexpected exact match. The first silently returned success, and the
second crashed the kernel. Both now both log an error and return -EUCLEAN.
Adarsh Das (2):
btrfs: handle unexpected exact match in btrfs_set_inode_index_count()
btrfs: replace BUG() with error handling in __btrfs_balance()
fs/btrfs/inode.c | 15 ++++++++++++---
fs/btrfs/volumes.c | 10 ++++++++--
2 files changed, 20 insertions(+), 5 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] btrfs: handle unexpected exact match in btrfs_set_inode_index_count()
2026-02-03 17:23 [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling Adarsh Das
@ 2026-02-03 17:23 ` Adarsh Das
2026-02-03 17:23 ` [PATCH 2/2] btrfs: replace BUG() with error handling in __btrfs_balance() Adarsh Das
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Adarsh Das @ 2026-02-03 17:23 UTC (permalink / raw)
To: Chris Mason, David Sterba; +Cc: linux-btrfs, linux-kernel, Adarsh Das
We search with offset (u64)-1 which should never match exactly.
Previously the code silently returned success without setting the index
count. Now logs an error and return -EUCLEAN instead.
Signed-off-by: Adarsh Das <adarshdas950@gmail.com>
---
fs/btrfs/inode.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index a2b5b440637e..9f46bfff1e4b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -6105,9 +6105,18 @@ static int btrfs_set_inode_index_count(struct btrfs_inode *inode)
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0)
return ret;
- /* FIXME: we should be able to handle this */
- if (ret == 0)
- return ret;
+
+ if (unlikely(ret == 0)) {
+ /*
+ * Key with offset -1 found, there would have to exist a dir
+ * index item with such offset, but this is out of the valid
+ * range.
+ */
+ btrfs_err(root->fs_info,
+ "unexpected exact match for dir index key, inode %llu",
+ btrfs_ino(inode));
+ return -EUCLEAN;
+ }
if (path->slots[0] == 0) {
inode->index_cnt = BTRFS_DIR_START_INDEX;
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] btrfs: replace BUG() with error handling in __btrfs_balance()
2026-02-03 17:23 [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling Adarsh Das
2026-02-03 17:23 ` [PATCH 1/2] btrfs: handle unexpected exact match in btrfs_set_inode_index_count() Adarsh Das
@ 2026-02-03 17:23 ` Adarsh Das
2026-02-03 21:06 ` [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling Qu Wenruo
2026-02-04 14:03 ` David Sterba
3 siblings, 0 replies; 5+ messages in thread
From: Adarsh Das @ 2026-02-03 17:23 UTC (permalink / raw)
To: Chris Mason, David Sterba; +Cc: linux-btrfs, linux-kernel, Adarsh Das
We search with offset (u64)-1 which should never match exactly.
Previously this was handled with BUG(). Now logs an error
and return -EUCLEAN.
Signed-off-by: Adarsh Das <adarshdas950@gmail.com>
---
fs/btrfs/volumes.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 8a08412f3529..0e1cc0c4ce68 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4112,8 +4112,14 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
* this shouldn't happen, it means the last relocate
* failed
*/
- if (ret == 0)
- BUG(); /* FIXME break ? */
+ if (unlikely(ret == 0)) {
+ btrfs_err(fs_info,
+ "unexpected exact match in chunk tree search, offset 0x%llx",
+ key.offset);
+ mutex_unlock(&fs_info->reclaim_bgs_lock);
+ ret = -EUCLEAN;
+ goto error;
+ }
ret = btrfs_previous_item(chunk_root, path, 0,
BTRFS_CHUNK_ITEM_KEY);
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling
2026-02-03 17:23 [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling Adarsh Das
2026-02-03 17:23 ` [PATCH 1/2] btrfs: handle unexpected exact match in btrfs_set_inode_index_count() Adarsh Das
2026-02-03 17:23 ` [PATCH 2/2] btrfs: replace BUG() with error handling in __btrfs_balance() Adarsh Das
@ 2026-02-03 21:06 ` Qu Wenruo
2026-02-04 14:03 ` David Sterba
3 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2026-02-03 21:06 UTC (permalink / raw)
To: Adarsh Das, Chris Mason, David Sterba; +Cc: linux-btrfs, linux-kernel
在 2026/2/4 03:53, Adarsh Das 写道:
> Both patches fix cases where a search with offset (u64)-1 gets an
> unexpected exact match. The first silently returned success, and the
> second crashed the kernel. Both now both log an error and return -EUCLEAN.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
>
> Adarsh Das (2):
> btrfs: handle unexpected exact match in btrfs_set_inode_index_count()
> btrfs: replace BUG() with error handling in __btrfs_balance()
>
> fs/btrfs/inode.c | 15 ++++++++++++---
> fs/btrfs/volumes.c | 10 ++++++++--
> 2 files changed, 20 insertions(+), 5 deletions(-)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling
2026-02-03 17:23 [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling Adarsh Das
` (2 preceding siblings ...)
2026-02-03 21:06 ` [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling Qu Wenruo
@ 2026-02-04 14:03 ` David Sterba
3 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2026-02-04 14:03 UTC (permalink / raw)
To: Adarsh Das; +Cc: Chris Mason, David Sterba, linux-btrfs, linux-kernel
On Tue, Feb 03, 2026 at 10:53:55PM +0530, Adarsh Das wrote:
> Both patches fix cases where a search with offset (u64)-1 gets an
> unexpected exact match. The first silently returned success, and the
> second crashed the kernel. Both now both log an error and return -EUCLEAN.
>
> Adarsh Das (2):
> btrfs: handle unexpected exact match in btrfs_set_inode_index_count()
> btrfs: replace BUG() with error handling in __btrfs_balance()
Added to for-next, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-02-04 14:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-03 17:23 [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling Adarsh Das
2026-02-03 17:23 ` [PATCH 1/2] btrfs: handle unexpected exact match in btrfs_set_inode_index_count() Adarsh Das
2026-02-03 17:23 ` [PATCH 2/2] btrfs: replace BUG() with error handling in __btrfs_balance() Adarsh Das
2026-02-03 21:06 ` [PATCH 0/2] btrfs: clean up two FIXMEs related to btrfs_search_slot output handling Qu Wenruo
2026-02-04 14:03 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox