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=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 D2F09C4338F for ; Sun, 1 Aug 2021 23:06:55 +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 2042760F8F for ; Sun, 1 Aug 2021 23:06:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2042760F8F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.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 66FA682E3F; Mon, 2 Aug 2021 01:06:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.b="fQe5/nt+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 709B6831CC; Mon, 2 Aug 2021 01:06:50 +0200 (CEST) Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.109.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BC1DB82005 for ; Mon, 2 Aug 2021 01:06:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=wqu@suse.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1627859206; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qAkTSSOVollsryvS2G7bVgzuyJxEi9aQUHHYJRZJsxo=; b=fQe5/nt+Tok8lHixiE7Q0KVSzebEMrhGVRi/0cKOHU9gbrtXwgj93T/y7usJnVO04lP3XO 1xe2xeG3J3cFv5qX+UX7KtcIckDD3nKt7AFacVKe/v7JWgnWInV79MieJiBQEoAffGDH3h v5OXRHDNfhFIWiBePSiNQzxdY9nK/vk= Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2106.outbound.protection.outlook.com [104.47.17.106]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-35-XoB8SILsPUOioihrJtohBA-1; Mon, 02 Aug 2021 01:06:45 +0200 X-MC-Unique: XoB8SILsPUOioihrJtohBA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IJCD3jtspXT2PEaW13aQXtiI6KlqBedjiiy/WL+fM2jo0EAwtJTnqR3f/yU5wYuPcrmPpBaEdpI4aXjORtQoNC3lZ/5t5AnySFTrhzP4hIvohwP+NHgqxoDfk3o7vG/kkFpdQjCljLAUepijAWIRwoJLeC3QDzZ7wBpArC2N8Bt0O2EiZvAXo+66mKm20JsvHG4O8RmbhUy7t5BRtwmyjGe1lnvSCxr3JOj/2UXgOQnkz1nhc3mWtiIEKvr9cHdc02PmHAXM7zztAj1V7Q2JwP0fe4gHYC4jA2AGqlqCk2egFcD29JvqMIzCrby0El9AretGoiLpnPpx23gi9FVmMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fRwaxX23dI1GvBKrY+9rwzSrdAvGIg7qvuRgAJtBTms=; b=kN7+YwM+K+lnYZ2eBzkd5gneYyhw23UCUY/5GJsiwiS02J0RnhlSoJqm9w1olNOjYiaPF72Q705d3tyPKPYYKSylrv5sAPQKOn0VrwgTNJp7bmWQvxv5bBI1lFg+1rhadKqOynQqJ3ZepDsTsIc00or23d3Fst6fF2QUszuGbv6GxiCM4UOLzcykN7ZJweyD+IR4qp/jT99HPZdKb3MXVEuCuw2SCl37R0/n6OKVzTLK1nafGhD8P0UtQAbcTzt1scra4QXnVD8BNOAC3+/xBiZNTZOu1j3zG5VMPg+dA3d9rA7W23sTswf34h4fNAihIWmxWZLg2DcAJRJOwRVxrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=suse.com; Received: from AM7PR04MB6821.eurprd04.prod.outlook.com (2603:10a6:20b:105::22) by AS8PR04MB8038.eurprd04.prod.outlook.com (2603:10a6:20b:2aa::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.21; Sun, 1 Aug 2021 23:06:44 +0000 Received: from AM7PR04MB6821.eurprd04.prod.outlook.com ([fe80::816b:1f6a:c279:1b65]) by AM7PR04MB6821.eurprd04.prod.outlook.com ([fe80::816b:1f6a:c279:1b65%3]) with mapi id 15.20.4373.026; Sun, 1 Aug 2021 23:06:44 +0000 Subject: Re: [PATCH] btrfs: Use default subvolume as filesystem root To: "Matwey V. Kornilov" , marek.behun@nic.cz CC: u-boot@lists.denx.de References: <20210801205216.22639-1-matwey.kornilov@gmail.com> From: Qu Wenruo Message-ID: <474eac73-5765-5bfe-acf0-03510f1ad04f@suse.com> Date: Mon, 2 Aug 2021 07:06:36 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 In-Reply-To: <20210801205216.22639-1-matwey.kornilov@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BYAPR11CA0079.namprd11.prod.outlook.com (2603:10b6:a03:f4::20) To AM7PR04MB6821.eurprd04.prod.outlook.com (2603:10a6:20b:105::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [0.0.0.0] (149.28.201.231) by BYAPR11CA0079.namprd11.prod.outlook.com (2603:10b6:a03:f4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20 via Frontend Transport; Sun, 1 Aug 2021 23:06:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37764ee7-92b9-4b34-8319-08d95541079f X-MS-TrafficTypeDiagnostic: AS8PR04MB8038: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9tLsW9DFyHFwa2G2i0GREb+rckVUWrrdOAP9Wh6QfobEvJJmG+EiFHh38Fvbh5tKwyMf/hQy+6BE2rUpzravFTvbXfbkcurJMbNm/Oji0/sQqmV4hbdA9OeuuaHKtk2joFR8AanYshACyxl72ih7PvIT1WVSqtJh70JpfKDs+LJScB+GphqzAm3wV7ZFxVPMZAX+tKK8yC1ngfSW/RY81J4Ga9Yi2vXSVRcBkRHkoDx/OhxgmrQedrw4yMTNbwa8Hu5kBT5EEH1Z6PBI4zM54Zd5O6fIDNztjETpCRtIKZVao/SByjvXIYbfBewAFSS5bN29SdcSL+3rzr67r3ODwHRUKhQ5JSGqGJ1hPkPW3nmNFuP3eSnQvVxVaJ03y+q2Em/HApPRRmFt+y3kf6gHt+aepwKOWKwcrg4ppR49Itl4e52Rw5KTpgvBwsAxd/Py03aVhepwx8vyJrSZB0sGHTEvjN27JHZYeWs1u4CPc0W0jqJdU/d+qNv8jDV4IOrmv+kKQA+IQZRd0aqCXmNV/RDWxkDhJV/215bac4h/xzefw2Cb8rQz4R6m9iHRH91FOR7I4g62NedswKaRmOWYumBOA9G37CiGzXrEfvTCMJD3sBPDfExsK/KJMDiUW54s40qQcKKCXP6hpsizCtgne+25PMjfiyyKSnepOCmJFxaTPs0Qgc05czv0vVJxRdhZ9i3lFHaq4fJS9/6ZT5IJlGDHocW5HDbG0tvAwmS4bNdzkM5VzM1O4etvjtqQjF4avu7Kn4XRrz80qCwui2Fsm6nnnNlWIAnzMnuAtyruhu/KBaihCmOO7A1cN7ClLBZ2Psg1KLVc2SsRRqiJZa1MxA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR04MB6821.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39850400004)(136003)(346002)(376002)(366004)(8936002)(36756003)(6486002)(86362001)(66556008)(38100700002)(66476007)(8676002)(4326008)(316002)(2906002)(16576012)(31696002)(26005)(66946007)(31686004)(2616005)(956004)(5660300002)(6666004)(6706004)(966005)(186003)(478600001)(83380400001)(78286007)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?8Tw+YrqjP93z3sEiAMatmTL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22NHcFi3K62gm0lTB8KlOKGQlxURFjH45CroNmoyfYYKt5exkfkMRshp+k?= =?us-ascii?Q?1RhVFdTJraLvvQyiDUTEHKo+3p68csL5HX6twLEKowCzcldA1CktCsbjpaz1?= =?us-ascii?Q?HA/bBC01liovnK+DODEhWlsUY3HeanNWi0fp4CqOsNCER9/SOiZgLu0gR6UM?= =?us-ascii?Q?TLthbbN2of173uvjDhXKzoWeOESyV+EylJV/hL4NzK5TO9JEW25S3jOBm5Wb?= =?us-ascii?Q?2aMMIXrSZKBeuWGu77aA88sb/fe0l70gEl1k6MNDJMERq6X+jCdF9hXBNSDI?= =?us-ascii?Q?Oc2AE22aGuwFq0lX4CiOHfTuiJ5bxaO7BQr/NJQgAQr4WoJFBSF6cPcsf74M?= =?us-ascii?Q?xsbtq6IjVi0oTk7ltJKh2w5pZ7uLVxwiyJYexLNtSPxJJyu7eSUbxbXhJArl?= =?us-ascii?Q?37YnLyazPN6eTJIdx6E6ytRz?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37764ee7-92b9-4b34-8319-08d95541079f X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB6821.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2021 23:06:44.1105 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CrGNqZXnnbgUJP1GOpknfaSAEv70bLgPD3kz9fGg+a6jjOqwfARbVYKMwAVtatx0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8038 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 On 2021/8/2 =E4=B8=8A=E5=8D=884:52, Matwey V. Kornilov wrote: > BTRFS volume consists of a number of subvolumes which can be mounted sepa= rately > from each other. The top-level subvolume always exists even if no subvolu= mes > were created manually. A subvolume can be denoted as the default subvolum= e i.e. > the subvolume which is mounted by default. >=20 > The default "default subvolume" is the top-level one, but this is far fro= m 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 no= t > "top-level". That means that the /boot/dtb/ directory is also located ins= ide > this default subvolume instead of top-level one. >=20 > However, the existing btrfs u-boot driver always uses the top-level subvo= lume > as the filesystem root. This behaviour 1) is inconsistent with >=20 > mount /dev/sda1 /target >=20 > command, which mount the default subvolume 2) leads to the issues when > /boot/dtb cannot be found properly (see the reference). I also noticed the problem in the past, but forgot to fix it.... >=20 > This patch uses the default subvolume as the filesystem root to overcome > mentioned issues. >=20 > Reference: https://bugzilla.suse.com/show_bug.cgi?id=3D1185656 > Signed-off-by: Matwey V. Kornilov Reviewed-by: Qu Wenruo Thanks, Qu > --- > fs/btrfs/disk-io.c | 38 +++++++++++++++++++++++++++++++++++--- > 1 file changed, 35 insertions(+), 3 deletions(-) >=20 > 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_f= s_info *fs_info, > return 0; > } > =20 > +static int get_default_subvolume(struct btrfs_fs_info *fs_info, > + struct btrfs_key *key_ret) > +{ > + struct btrfs_root *root =3D fs_info->tree_root; > + struct btrfs_dir_item *dir_item; > + struct btrfs_path path; > + int ret =3D 0; > + > + btrfs_init_path(&path); > + > + dir_item =3D btrfs_lookup_dir_item(NULL, root, &path, > + BTRFS_ROOT_TREE_DIR_OBJECTID, > + "default", 7, 0); > + if (IS_ERR(dir_item)) { > + ret =3D 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 =3D fs_info->super_copy; > @@ -833,9 +857,17 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_i= nfo) > =20 > fs_info->last_trans_committed =3D generation; > =20 > - key.objectid =3D BTRFS_FS_TREE_OBJECTID; > - key.type =3D BTRFS_ROOT_ITEM_KEY; > - key.offset =3D (u64)-1; > + ret =3D 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 =3D BTRFS_FS_TREE_OBJECTID; > + key.type =3D BTRFS_ROOT_ITEM_KEY; > + key.offset =3D (u64)-1; > + } > + > fs_info->fs_root =3D btrfs_read_fs_root(fs_info, &key); > =20 > if (IS_ERR(fs_info->fs_root)) >=20