OSDN Git Service

btrfs: fix race with relocation recovery and fs_root setup
authorJeff Mahoney <jeffm@suse.com>
Wed, 17 May 2017 15:38:34 +0000 (11:38 -0400)
committerDavid Sterba <dsterba@suse.com>
Thu, 1 Jun 2017 14:56:55 +0000 (16:56 +0200)
commita9b3311ef36b670909ea4443f306c8318082c8f0
tree008b6709533bf12d1d95da08547449351bdbf4f2
parent896533a7da929136d0432713f02a3edffece2826
btrfs: fix race with relocation recovery and fs_root setup

If we have to recover relocation during mount, we'll ultimately have to
evict the orphan inode.  That goes through the reservation dance, where
priority_reclaim_metadata_space and flush_space expect fs_info->fs_root
to be valid.  That's the next thing to be set up during mount, so we
crash, almost always in flush_space trying to join the transaction
but priority_reclaim_metadata_space is possible as well.  This call
path has been problematic in the past WRT whether ->fs_root is valid
yet.  Commit 957780eb278 (Btrfs: introduce ticketed enospc
infrastructure) added new users that are called in the direct path
instead of the async path that had already been worked around.

The thing is that we don't actually need the fs_root, specifically, for
anything.  We either use it to determine whether the root is the
chunk_root for use in choosing an allocation profile or as a root to pass
btrfs_join_transaction before immediately committing it.  Anything that
isn't the chunk root works in the former case and any root works in
the latter.

A simple fix is to use a root we know will always be there: the
extent_root.

Cc: <stable@vger.kernel.org> # v4.8+
Fixes: 957780eb278 (Btrfs: introduce ticketed enospc infrastructure)
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c