btrfs: move btrfs_kill_delayed_inode_items into evict
authorJosef Bacik <josef@toxicpanda.com>
Fri, 3 Dec 2021 22:18:07 +0000 (17:18 -0500)
committerDavid Sterba <dsterba@suse.com>
Fri, 7 Jan 2022 13:18:24 +0000 (14:18 +0100)
We have a special case in btrfs_truncate_inode_items() to call
btrfs_kill_delayed_inode_items() if min_type == 0, which is only called
during evict.

Instead move this out into evict proper, and add some comments because I
erroneously attempted to remove this code altogether without
understanding what we were doing.

Evict is updating the inode only because we only care about making sure
the i_nlink count has hit disk.  If we had pending deletions we don't
want to process those via the delayed inode updates, we simply want to
drop all of them and reclaim the reserved metadata space.  Then from
there the btrfs_truncate_inode_items() will do the work to remove all of
the items as appropriate.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode-item.c
fs/btrfs/inode.c

index 379baeccc7d670bfd23b8acda44efc7b92110d80..a7c1408cada82c6346afbee80303d90cd71187b0 100644 (file)
@@ -488,15 +488,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
                return -ENOMEM;
        path->reada = READA_BACK;
 
-       /*
-        * This function is also used to drop the items in the log tree before
-        * we relog the inode, so if root != BTRFS_I(inode)->root, it means
-        * it is used to drop the logged items. So we shouldn't kill the delayed
-        * items.
-        */
-       if (min_type == 0 && root == inode->root)
-               btrfs_kill_delayed_inode_items(inode);
-
        key.objectid = ino;
        key.offset = (u64)-1;
        key.type = (u8)-1;
index 9f9cd6c598fe0e8343a0aecbd40aeb669db9ad07..7aabf419e9676a39966c824ea2ed830fa458cc3c 100644 (file)
@@ -5226,10 +5226,22 @@ void btrfs_evict_inode(struct inode *inode)
                goto no_delete;
        }
 
+       /*
+        * This makes sure the inode item in tree is uptodate and the space for
+        * the inode update is released.
+        */
        ret = btrfs_commit_inode_delayed_inode(BTRFS_I(inode));
        if (ret)
                goto no_delete;
 
+       /*
+        * This drops any pending insert or delete operations we have for this
+        * inode.  We could have a delayed dir index deletion queued up, but
+        * we're removing the inode completely so that'll be taken care of in
+        * the truncate.
+        */
+       btrfs_kill_delayed_inode_items(BTRFS_I(inode));
+
        rsv = btrfs_alloc_block_rsv(fs_info, BTRFS_BLOCK_RSV_TEMP);
        if (!rsv)
                goto no_delete;