Skip to content

Commit 1c88823

Browse files
Saphereyekdave
authored andcommitted
btrfs: handle unexpected exact match in btrfs_set_inode_index_count()
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. Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Adarsh Das <adarshdas950@gmail.com> Reviewed-by: David Sterba <dsterba@suse.com>, Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 161ab30 commit 1c88823

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

fs/btrfs/inode.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6149,9 +6149,18 @@ static int btrfs_set_inode_index_count(struct btrfs_inode *inode)
61496149
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
61506150
if (ret < 0)
61516151
return ret;
6152-
/* FIXME: we should be able to handle this */
6153-
if (ret == 0)
6154-
return ret;
6152+
6153+
if (unlikely(ret == 0)) {
6154+
/*
6155+
* Key with offset -1 found, there would have to exist a dir
6156+
* index item with such offset, but this is out of the valid
6157+
* range.
6158+
*/
6159+
btrfs_err(root->fs_info,
6160+
"unexpected exact match for DIR_INDEX key, inode %llu",
6161+
btrfs_ino(inode));
6162+
return -EUCLEAN;
6163+
}
61556164

61566165
if (path->slots[0] == 0) {
61576166
inode->index_cnt = BTRFS_DIR_START_INDEX;

0 commit comments

Comments
 (0)