From: Adarsh Das <adarshdas950@gmail.com>
To: Chris Mason <clm@fb.com>, David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Adarsh Das <adarshdas950@gmail.com>
Subject: [PATCH 1/2] btrfs: handle unexpected exact match in btrfs_set_inode_index_count()
Date: Tue, 3 Feb 2026 22:53:56 +0530 [thread overview]
Message-ID: <20260203172357.65383-2-adarshdas950@gmail.com> (raw)
In-Reply-To: <20260203172357.65383-1-adarshdas950@gmail.com>
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
next prev parent reply other threads:[~2026-02-03 17:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=20260203172357.65383-2-adarshdas950@gmail.com \
--to=adarshdas950@gmail.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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