btrfs: Use default subvolume as filesystem root
authorMatwey V. Kornilov <matwey.kornilov@gmail.com>
Sun, 1 Aug 2021 20:52:16 +0000 (23:52 +0300)
committerTom Rini <trini@konsulko.com>
Wed, 1 Sep 2021 14:11:24 +0000 (10:11 -0400)
commit94509b79b13e69c209199af0757afbde8d2ebd6d
treec17035ac834cf0dfd1e9cd132a72b0aed90a609b
parent48cf96fbdf9cf70c4f249c0207ce57c7dff4dd55
btrfs: Use default subvolume as filesystem root

BTRFS volume consists of a number of subvolumes which can be mounted separately
from each other. The top-level subvolume always exists even if no subvolumes
were created manually. A subvolume can be denoted as the default subvolume i.e.
the subvolume which is mounted by default.

The default "default subvolume" is the top-level one, but this is far from the
common practices used in the wild. For instance, openSUSE provides an OS
snapshot/rollback feature based on BTRFS. To achieve this, the actual OS root
filesystem is located into a separate subvolume which is "default" but not
"top-level". That means that the /boot/dtb/ directory is also located inside
this default subvolume instead of top-level one.

However, the existing btrfs u-boot driver always uses the top-level subvolume
as the filesystem root. This behaviour 1) is inconsistent with

    mount /dev/sda1 /target

command, which mount the default subvolume 2) leads to the issues when
/boot/dtb cannot be found properly (see the reference).

This patch uses the default subvolume as the filesystem root to overcome
mentioned issues.

Reference: https://bugzilla.suse.com/show_bug.cgi?id=1185656
Signed-off-by: Matwey V. Kornilov <matwey.kornilov@gmail.com>
Fixes: f06bfcf54d0e ("fs: btrfs: Crossport open_ctree_fs_info() from btrfs-progs")
Reviewed-by: Qu Wenruo <wqu@suse.com>
fs/btrfs/disk-io.c