]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ext4: remove EA inode entry from mbcache on inode eviction
authorJan Kara <jack@suse.cz>
Tue, 12 Jul 2022 10:54:22 +0000 (12:54 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:55 +0000 (11:41 +0100)
[ Upstream commit 6a4a8513ca9140cb4975192b6e0db3e7f28e0d67 ]

Currently we remove EA inode from mbcache as soon as its xattr refcount
drops to zero. However there can be pending attempts to reuse the inode
and thus refcount handling code has to handle the situation when
refcount increases from zero anyway. So save some work and just keep EA
inode in mbcache until it is getting evicted. At that moment we are sure
following iget() of EA inode will fail anyway (or wait for eviction to
finish and load things from the disk again) and so removing mbcache
entry at that moment is fine and simplifies the code a bit.

CC: stable@vger.kernel.org
Fixes: 4e4b07fdbb82 ("ext4: convert to mbcache2")
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20220712105436.32204-3-jack@suse.cz
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Stable-dep-of: a44e84a9b776 ("ext4: fix deadlock due to mbcache entry corruption")
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ext4/inode.c
fs/ext4/xattr.c
fs/ext4/xattr.h

index a26e5ed6d61ccf479cd4af35071e9eba2acfc482..b38427b8d08343ef35f4e475dcc394fe4bc0e0ed 100644 (file)
@@ -207,6 +207,8 @@ void ext4_evict_inode(struct inode *inode)
 
        trace_ext4_evict_inode(inode);
 
+       if (EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)
+               ext4_evict_ea_inode(inode);
        if (inode->i_nlink) {
                /*
                 * When journalling data dirty buffers are tracked only in the
index 8f0e8b60ea20450d076e87613645f6d4a4979014..4ade87a32315e4a99130570df5426e006825779c 100644 (file)
@@ -434,6 +434,14 @@ error:
        return err;
 }
 
+/* Remove entry from mbcache when EA inode is getting evicted */
+void ext4_evict_ea_inode(struct inode *inode)
+{
+       if (EA_INODE_CACHE(inode))
+               mb_cache_entry_delete(EA_INODE_CACHE(inode),
+                       ext4_xattr_inode_get_hash(inode), inode->i_ino);
+}
+
 static int
 ext4_xattr_inode_verify_hashes(struct inode *ea_inode,
                               struct ext4_xattr_entry *entry, void *buffer,
@@ -1019,10 +1027,8 @@ static int ext4_xattr_ensure_credits(handle_t *handle, struct inode *inode,
 static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,
                                       int ref_change)
 {
-       struct mb_cache *ea_inode_cache = EA_INODE_CACHE(ea_inode);
        struct ext4_iloc iloc;
        s64 ref_count;
-       u32 hash;
        int ret;
 
        inode_lock(ea_inode);
@@ -1045,14 +1051,6 @@ static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,
 
                        set_nlink(ea_inode, 1);
                        ext4_orphan_del(handle, ea_inode);
-
-                       if (ea_inode_cache) {
-                               hash = ext4_xattr_inode_get_hash(ea_inode);
-                               mb_cache_entry_create(ea_inode_cache,
-                                                     GFP_NOFS, hash,
-                                                     ea_inode->i_ino,
-                                                     true /* reusable */);
-                       }
                }
        } else {
                WARN_ONCE(ref_count < 0, "EA inode %lu ref_count=%lld",
@@ -1065,12 +1063,6 @@ static int ext4_xattr_inode_update_ref(handle_t *handle, struct inode *ea_inode,
 
                        clear_nlink(ea_inode);
                        ext4_orphan_add(handle, ea_inode);
-
-                       if (ea_inode_cache) {
-                               hash = ext4_xattr_inode_get_hash(ea_inode);
-                               mb_cache_entry_delete(ea_inode_cache, hash,
-                                                     ea_inode->i_ino);
-                       }
                }
        }
 
index 990084e00374fc8f97ec4a2db7ae8c719c2ae887..231ef308d10cbcce14087268cb118ae3ebc78af7 100644 (file)
@@ -190,6 +190,7 @@ extern void ext4_xattr_inode_array_free(struct ext4_xattr_inode_array *array);
 
 extern int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
                            struct ext4_inode *raw_inode, handle_t *handle);
+extern void ext4_evict_ea_inode(struct inode *inode);
 
 extern const struct xattr_handler *ext4_xattr_handlers[];