Commit 1c88823a authored by Adarsh Das's avatar Adarsh Das Committed by David Sterba
Browse files

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: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarAdarsh Das <adarshdas950@gmail.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com&gt;,>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 161ab30d
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -6149,9 +6149,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;