btrfs: clean up two FIXMEs related to btrfs_search_slot output handling
cover btrfs: clean up two FIXMEs related to btrfs_search_slot output handling
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(-)
Signature · 1 line
2.53.0
PATCH 1/2 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.
--- fs/btrfs/inode.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
fs/btrfs/inode.c +12 -3
@@ -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 ;
Signature · 1 line
2.53.0
PATCH 2/2 btrfs: replace BUG() with error handling in __btrfs_balance()
In reply to Adarsh DasWe search with offset (u64)-1 which should never match exactly. Previously this was handled with BUG(). Now logs an error and return -EUCLEAN.
--- fs/btrfs/volumes.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +8 -2
@@ -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 );
Signature · 1 line
2.53.0
Quoted 3 lines · 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.
Thanks,
Qu
Quoted 9 lines
Adarsh Das (2):
btrfs: handle unexpected exact match inbtrfs_set_inode_index_count()
btrfs: replaceBUG()with error handling in__btrfs_balance()fs/btrfs/inode.c | 15 ++++++++++++--- fs/btrfs/volumes.c | 10 ++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-)
Quoted 7 lines · 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 inbtrfs_set_inode_index_count()
btrfs: replaceBUG()with error handling in__btrfs_balance()
Added to for-next, thanks.