Btrfs: fix btrfs_evict_inode to handle abnormal inodes correctly

"Linux Kernel Mailing List" <[email protected]> Fri, 16 Feb 2018 17:44:22 +0000 (UTC)
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/e8f1bc1493855e32b7a2a019decc3c353d94daf6
Commit:     e8f1bc1493855e32b7a2a019decc3c353d94daf6
Parent:     55237a5f2431a72435e3ed39e4306e973c0446b7
Refname:    refs/heads/master
Author:     Liu Bo <[email protected]>
AuthorDate: Thu Jan 25 11:02:53 2018 -0700
Committer:  David Sterba <[email protected]>
CommitDate: Fri Feb 2 16:24:35 2018 +0100

    Btrfs: fix btrfs_evict_inode to handle abnormal inodes correctly
    
    This regression is introduced in
    commit 3d48d9810de4 ("btrfs: Handle uninitialised inode eviction").
    
    There are two problems,
    
    a) it is ->destroy_inode() that does the final free on inode, not
       ->evict_inode(),
    b) clear_inode() must be called before ->evict_inode() returns.
    
    This could end up hitting BUG_ON(inode->i_state != (I_FREEING | I_CLEAR));
    in evict() because I_CLEAR is set in clear_inode().
    
    Fixes: commit 3d48d9810de4 ("btrfs: Handle uninitialised inode eviction")
    Cc: <[email protected]> # v4.7-rc6+
    Signed-off-by: Liu Bo <[email protected]>
    Reviewed-by: Nikolay Borisov <[email protected]>
    Reviewed-by: Josef Bacik <[email protected]>
    Signed-off-by: David Sterba <[email protected]>
---
 fs/btrfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index a68a4acd16e5..44a152d8f32f 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5281,7 +5281,7 @@ void btrfs_evict_inode(struct inode *inode)
 	trace_btrfs_inode_evict(inode);
 
 	if (!root) {
-		kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
+		clear_inode(inode);
 		return;
 	}
 
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html