btrfs: get correct owning_root when dropping snapshot
authorJosef Bacik <josef@toxicpanda.com>
Fri, 13 Oct 2023 19:18:17 +0000 (15:18 -0400)
committerDavid Sterba <dsterba@suse.com>
Fri, 3 Nov 2023 15:39:06 +0000 (16:39 +0100)
commitd8ba2a91fc3cd0347823435971f58f473cbba7aa
treef55073ec71e673d2e838d1a8f2f828ec620f61bb
parent776a838f1fa95670c1c1cf7109a898090b473fa3
btrfs: get correct owning_root when dropping snapshot

Dave reported a bug where we were aborting the transaction while trying
to cleanup the squota reservation for an extent.

This turned out to be because we're doing btrfs_header_owner(next) in
do_walk_down when we decide to free the block.  However in this code
block we haven't explicitly read next, so it could be stale.  We would
then get whatever garbage happened to be in the pages at this point.
The commit that introduced that is "btrfs: track owning root in
btrfs_ref".

Fix this by saving the owner_root when we do the
btrfs_lookup_extent_info().  We always do this in do_walk_down, it is
how we make the decision of whether or not to delete the block.  This is
cheap because we've already done the extent item lookup at this point,
so it's straightforward to just grab the owner root as well.

Then we can use this when deleting the metadata block without needing to
force a read of the extent buffer to find the owner.

This fixes the problem that Dave reported.

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/ctree.c
fs/btrfs/extent-tree.c
fs/btrfs/extent-tree.h