btrfs: lift read-write mount setup from mount and remount
authorBoris Burkov <boris@bur.io>
Wed, 18 Nov 2020 23:06:16 +0000 (15:06 -0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 9 Dec 2020 18:16:07 +0000 (19:16 +0100)
commit44c0ca211a4da92513fffc545b5374b45b0c4fc5
treed9ef2689a16c4b8a1b355b4399bd374581cb5bbc
parent47876f7ceffa0e6af7476e052b3c061f1f2c1d9f
btrfs: lift read-write mount setup from mount and remount

Mounting rw and remounting from ro to rw naturally share invariants and
functionality which result in a correctly setup rw filesystem. Luckily,
there is even a strong unity in the code which implements them. In
mount's open_ctree, these operations mostly happen after an early return
for ro file systems, and in remount, they happen in a section devoted to
remounting ro->rw, after some remount specific validation passes.

However, there are unfortunately a few differences. There are small
deviations in the order of some of the operations, remount does not
start orphan cleanup in root_tree or fs_tree, remount does not create
the free space tree, and remount does not handle "one-shot" mount
options like clear_cache and uuid tree rescan.

Since we want to add building the free space tree to remount, and also
to start the same orphan cleanup process on a filesystem mounted as ro
then remounted rw, we would benefit from unifying the logic between the
two code paths.

This patch only lifts the existing common functionality, and leaves a
natural path for fixing the discrepancies.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/disk-io.h
fs/btrfs/super.c