Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6870C4338F for ; Sun, 1 Aug 2021 20:53:12 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E0A5E61029 for ; Sun, 1 Aug 2021 20:53:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E0A5E61029 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CF44B8322E; Sun, 1 Aug 2021 22:53:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PcpemHJs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D73DF83239; Sun, 1 Aug 2021 22:53:08 +0200 (CEST) Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B290F8311A for ; Sun, 1 Aug 2021 22:53:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=matwey.kornilov@gmail.com Received: by mail-lj1-x232.google.com with SMTP id a7so21247661ljq.11 for ; Sun, 01 Aug 2021 13:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xyHK7F90SBsQM3Ue5hMxXGsuygsFBXVk2KrCI3p661M=; b=PcpemHJs4Wsf1zZa4rugsKCLhfq+UVFQCcXBKRIzXlm3TXScmG1DIllc2rqo3GZyVt J+rfad94U38OD0l/bQISD0GSlwaPJLsFARkpXeg4Dl5tdQIiBanE5dUpFACrk1ssqd/W c6NVWGhr7VoVYn4vDXvFTcD5S5N6s3FlCeyfA2GanIDsaMAcYhO2vSC6FGaFLUKDSBQP kjzBt11pyQC8zNmYFufzHuroMioggDeNM68INgOLvlEGNwre3lDxWNuE/ArX1Rc+e77l dtDrAb07ZxPeTGzEof4nL+QwW5fEJ5j8VwW1KGvsIzW6sWFrU8SM6x6ScPhliLB8BHRg IFCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xyHK7F90SBsQM3Ue5hMxXGsuygsFBXVk2KrCI3p661M=; b=KC3hQSZmglunk0LOvG0O+4Xjz9XfTLlUEjAzkbUSuBHEPA3yV/SAztUz+IZcivGWC0 7dEfXq4VQ8IUqKUBo/kNysi29294IQzHq9/3JBZaLaExHqD1Td73lv5yYGYcQ0fODG+z gqnpdBLEun9xn+I0bsamlxg8jLWuR/taHDyScrW0st9wA8B/zk5qKtjMVvGX0rESUck1 kyb0DtnEnX+8VxN6/nPgYEbIVQ/yaYNTjv3/b2MlxCYgsT+bhHoXQ/iRYvS7Wfk9S6JV V3neuXTFRsHkKPxYep0DcStEyBJlMr6g/YppX1hRAW+4hMh5NT4yhWhwlTR6pWHKgwPG rUeA== X-Gm-Message-State: AOAM531jpGwVtVnfKjjSZPu+uZoFMf3tpFoGJcnbDckJyjKobKLe1ezj IATh8tZ39Fg5gJy4Ajb+p8Q= X-Google-Smtp-Source: ABdhPJwuMSFLhxO4vQFbGxIyLI/rN0S3uuER4NMML/U3N3i7remqfTsQ0o1utjPypb7Dtqlu4XGCQw== X-Received: by 2002:a2e:2f05:: with SMTP id v5mr9343350ljv.66.1627851184770; Sun, 01 Aug 2021 13:53:04 -0700 (PDT) Received: from oak.local ([2001:470:28:561:65f9:bd11:57d5:87de]) by smtp.gmail.com with ESMTPSA id g11sm759035lfv.291.2021.08.01.13.53.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Aug 2021 13:53:03 -0700 (PDT) From: "Matwey V. Kornilov" To: marek.behun@nic.cz, wqu@suse.com Cc: u-boot@lists.denx.de, "Matwey V. Kornilov" Subject: [PATCH] btrfs: Use default subvolume as filesystem root Date: Sun, 1 Aug 2021 23:52:16 +0300 Message-Id: <20210801205216.22639-1-matwey.kornilov@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean 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 --- fs/btrfs/disk-io.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 349411c3cc..12f9579fcf 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -804,6 +804,30 @@ static int setup_root_or_create_block(struct btrfs_fs_info *fs_info, return 0; } +static int get_default_subvolume(struct btrfs_fs_info *fs_info, + struct btrfs_key *key_ret) +{ + struct btrfs_root *root = fs_info->tree_root; + struct btrfs_dir_item *dir_item; + struct btrfs_path path; + int ret = 0; + + btrfs_init_path(&path); + + dir_item = btrfs_lookup_dir_item(NULL, root, &path, + BTRFS_ROOT_TREE_DIR_OBJECTID, + "default", 7, 0); + if (IS_ERR(dir_item)) { + ret = PTR_ERR(dir_item); + goto out; + } + + btrfs_dir_item_key_to_cpu(path.nodes[0], dir_item, key_ret); +out: + btrfs_release_path(&path); + return ret; +} + int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info) { struct btrfs_super_block *sb = fs_info->super_copy; @@ -833,9 +857,17 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info) fs_info->last_trans_committed = generation; - key.objectid = BTRFS_FS_TREE_OBJECTID; - key.type = BTRFS_ROOT_ITEM_KEY; - key.offset = (u64)-1; + ret = get_default_subvolume(fs_info, &key); + if (ret) { + /* + * The default dir item isn't there. Linux kernel behaviour is + * to silently use the top-level subvolume in this case. + */ + key.objectid = BTRFS_FS_TREE_OBJECTID; + key.type = BTRFS_ROOT_ITEM_KEY; + key.offset = (u64)-1; + } + fs_info->fs_root = btrfs_read_fs_root(fs_info, &key); if (IS_ERR(fs_info->fs_root)) -- 2.31.1