btrfs: add missing run of delayed items after unlink during log replay
authorFilipe Manana <fdmanana@suse.com>
Mon, 28 Feb 2022 16:29:28 +0000 (16:29 +0000)
committerDavid Sterba <dsterba@suse.com>
Wed, 2 Mar 2022 15:53:11 +0000 (16:53 +0100)
commit4751dc99627e4d1465c5bfa8cb7ab31ed418eff5
tree92563c73405eeec84b8bdc9c5ba95f03d1b26fba
parentd4aef1e122d8bbdc15ce3bd0bc813d6b44a7d63a
btrfs: add missing run of delayed items after unlink during log replay

During log replay, whenever we need to check if a name (dentry) exists in
a directory we do searches on the subvolume tree for inode references or
or directory entries (BTRFS_DIR_INDEX_KEY keys, and BTRFS_DIR_ITEM_KEY
keys as well, before kernel 5.17). However when during log replay we
unlink a name, through btrfs_unlink_inode(), we may not delete inode
references and dir index keys from a subvolume tree and instead just add
the deletions to the delayed inode's delayed items, which will only be
run when we commit the transaction used for log replay. This means that
after an unlink operation during log replay, if we attempt to search for
the same name during log replay, we will not see that the name was already
deleted, since the deletion is recorded only on the delayed items.

We run delayed items after every unlink operation during log replay,
except at unlink_old_inode_refs() and at add_inode_ref(). This was due
to an overlook, as delayed items should be run after evert unlink, for
the reasons stated above.

So fix those two cases.

Fixes: 0d836392cadd5 ("Btrfs: fix mount failure after fsync due to hard link recreation")
Fixes: 1f250e929a9c9 ("Btrfs: fix log replay failure after unlink and link combination")
CC: stable@vger.kernel.org # 4.19+
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tree-log.c