From patchwork Sun Aug 1 20:52:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matwey V. Kornilov" X-Patchwork-Id: 490131 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:1185:0:0:0:0 with SMTP id f5csp1340079jas; Sun, 1 Aug 2021 13:53:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySEQOCCzhTSwjSq7jXbpKCujjrRm8cvGESwNjQayTLM80vyBAN7pxAAnNBWM844xacIFIM X-Received: by 2002:a17:906:4fd6:: with SMTP id i22mr12782081ejw.92.1627851193010; Sun, 01 Aug 2021 13:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627851193; cv=none; d=google.com; s=arc-20160816; b=XAzq8Ai9egPO+73PXMA6NHoO5nIzBeXSEj099aIOIUl0m3rgHTynn0mqNogriJaOIv YzUv7Er8uTjqJlPvgzaZxlXEtLADTMbdnKX5zh6PN3Qs6jJ4ycAtM6WaxLTswMfYp5fp VHtP8JaaCEqcWckfW07TLYAk23DuMPVfT/fUAjLbdA0mfMCEx7pmxHA+2I8iTVCyGQdl 5svPASF5uaTqw42UEfevOmj7FAinVlob72v5k0pZYojkqN6P0l5617W5ZQw0jmPBw6me FFA6EGo3Gal2T08RDNXOdS6+WXf9f96SLx296SVhg/tQCNXvC20oZumTEKdhk4A+NKoC LdeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=xyHK7F90SBsQM3Ue5hMxXGsuygsFBXVk2KrCI3p661M=; b=qW9MnTKMeWVXlOC4EWLgIX24r4kvstTHUEUmgO5+w7goB3Z82goyzo7mY3dkH/aQVJ EdILthPYOU/H+DaVDB4jbPL+jhRLXVRXBpLj9UoXaFSwva288BOUnfjGQb6imYHilGIO N2pjcSwe4R/IQLef7oWozwFY8TwAfvFeUvmmEORIO9P4nzjxpiW4QsIfpDrcBTmDXJV2 qUQdFeVvBx79TVTJ1lk+chR/UMvjEWqi4Km3SJvAzpUELhvmbv/IQlQgc9N3Io7qrt+0 Gzd2wWonSCUaH1Sl+yiPlNsieevUppUPutNn7xxVD6WzySm7XW17FSOyeVBb8qW/fGXx +1tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PcpemHJs; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ga26si7654815ejb.30.2021.08.01.13.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Aug 2021 13:53:12 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PcpemHJs; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 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-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 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(-) -- 2.31.1 Reviewed-by: Qu Wenruo 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))