From patchwork Wed May 31 12:55:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 101436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2857808vqr; Wed, 31 May 2023 06:00:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5rBoh9lZ1XcxNnXO5L2b/aBAhShpbGinyN7OOhDfISm6H8EZiFm8Y3/J13Hk/UrO3oznTb X-Received: by 2002:a05:6a00:a0b:b0:63d:47c8:856e with SMTP id p11-20020a056a000a0b00b0063d47c8856emr7723092pfh.2.1685538003830; Wed, 31 May 2023 06:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685538003; cv=none; d=google.com; s=arc-20160816; b=OldtlGAz678jDeF8ikh61IFqGaAEbZ+gnOQQB+VdDViu7CPxVOc3c608BLdgbeS8fh xar6dClnkQIl77fJej+FOxRMg4OvM73fEgRb7deiRxhBjBdgJkhtUFlwjpZI9Wt0T6Lq abviR43k2r4y3axu2pgILdESPJLVJh0nbe+A8awEbLaNgG6A0mizttT0Vnt7HBAy5SNX XqfIMQv5AfowRAfr+cWnb9W+OTwwAYDlj7ehfOklwq7zrCSTWivqEVdLtAB8vK6FRf0i 5PNg3EkdDFaXWtzV1bAASUR/HkXTvk/2zSDnNAJOWml47MoFov8QjFg77RltNqHYHJ9p sn0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=os0MBKKbxqig3Onswrq7Zcvd+L0EYsCNlnX80lA2o9g=; b=QoXEz+GidiWRH4jpUGmhSigCiOSNglWSntijZRxRlTvM80iXeKrKl0QYMzd4WZKpSV UY9LOXi9fZUndcwGPAjxdYJgxTURIblZFPc3UCKAB7/p4ad+ePU0ZzRe3B+kpLDzvmcZ XjZgq/+GBZpwY1YdLFnr8dyR39jGZJuIAWJDkOenb3lk62erkJ/hXhw/TqNeIFjuQVB6 TVYTUGr3u9tl3ZngvwuAaolsddg3pYX+CbIWI2fRFwo0Ha+vuX2DgZ1RVZ6G6kR7fywE 1UXBtse58VhDPM/wz0ZJPQl/XRFlVCIYzsmmIZcj/OFPj1cdMffV4tli5SxMo2UKJWeu fm1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=kOvm0LaA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u190-20020a6379c7000000b0051b0d0897c4si923828pgc.818.2023.05.31.05.59.49; Wed, 31 May 2023 06:00:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=kOvm0LaA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236216AbjEaM5n (ORCPT + 99 others); Wed, 31 May 2023 08:57:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236210AbjEaM5J (ORCPT ); Wed, 31 May 2023 08:57:09 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A305C10D1; Wed, 31 May 2023 05:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=os0MBKKbxqig3Onswrq7Zcvd+L0EYsCNlnX80lA2o9g=; b=kOvm0LaAWl7nz57TenEhRzPypi CWUwnYtRfjXbSOCh0my3koxRwcGAO1RH+oRFFS4rQ3ZkPFNV1vRpWCw5isvoD0f+GjtJODmMa6XMp nB0qpbJpytkzbpPNyEVc4CEhioNBfSqDSTKZ+hJtxeocq2Pn8oy4Z7IcVYCMAWu7W6EtLp8/xA13l UC2SEsNpbC2dd+WEr/Ae+/3TilmnnrsOVj43lDHAJ2wqamP0L8eiMGfL2GxHVznytgyP2N6ac4+yO KDQtY+TZ2ACFir3yrWy1cvP3126LKnmFPnA7g5Ohvf5mYUHLYUIaxTCDUKR+r1lpu7wXtg49JAaA5 CuUgdLYw==; Received: from [2001:4bb8:182:6d06:2e49:a56:513a:92ee] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4LNS-00HRLT-2f; Wed, 31 May 2023 12:56:35 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Mike Snitzer , Joern Engel , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Pavel Machek , Loic Poulain , dm-devel@redhat.com, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-mtd@lists.infradead.org, linux-pm@vger.kernel.org Subject: [PATCH 10/24] init: handle ubi/mtd root mounting like all other root types Date: Wed, 31 May 2023 14:55:21 +0200 Message-Id: <20230531125535.676098-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531125535.676098-1-hch@lst.de> References: <20230531125535.676098-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767414697823301162?= X-GMAIL-MSGID: =?utf-8?q?1767414697823301162?= Assign a Root_Generic magic value for UBI/MTD root and handle the root mounting in mount_root like all other root types. Besides making the code more clear this also means that UBI/MTD root can be used together with an initrd (not that anyone should care). Also factor parsing of the root name into a helper now that it can be easily done and will get more complicated with subsequent patches. Signed-off-by: Christoph Hellwig --- include/linux/root_dev.h | 1 + init/do_mounts.c | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/linux/root_dev.h b/include/linux/root_dev.h index ed3ea8da642972..847c9a06101b76 100644 --- a/include/linux/root_dev.h +++ b/include/linux/root_dev.h @@ -9,6 +9,7 @@ enum { Root_NFS = MKDEV(UNNAMED_MAJOR, 255), Root_CIFS = MKDEV(UNNAMED_MAJOR, 254), + Root_Generic = MKDEV(UNNAMED_MAJOR, 253), Root_RAM0 = MKDEV(RAMDISK_MAJOR, 0), }; diff --git a/init/do_mounts.c b/init/do_mounts.c index 74cc96bffbdd71..be6d14733ba02f 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -591,6 +591,10 @@ void __init mount_root(char *root_device_name) case Root_CIFS: mount_cifs_root(); break; + case Root_Generic: + mount_root_generic(root_device_name, root_device_name, + root_mountflags); + break; case 0: if (root_device_name && root_fs_names && mount_nodev_root(root_device_name) == 0) @@ -602,6 +606,14 @@ void __init mount_root(char *root_device_name) } } +static dev_t __init parse_root_device(char *root_device_name) +{ + if (!strncmp(root_device_name, "mtd", 3) || + !strncmp(root_device_name, "ubi", 3)) + return Root_Generic; + return name_to_dev_t(root_device_name); +} + /* * Prepare the namespace - decide what/where to mount, load ramdisks, etc. */ @@ -624,15 +636,8 @@ void __init prepare_namespace(void) md_run_setup(); - if (saved_root_name[0]) { - if (!strncmp(saved_root_name, "mtd", 3) || - !strncmp(saved_root_name, "ubi", 3)) { - mount_root_generic(saved_root_name, saved_root_name, - root_mountflags); - goto out; - } - ROOT_DEV = name_to_dev_t(saved_root_name); - } + if (saved_root_name[0]) + ROOT_DEV = parse_root_device(saved_root_name); if (initrd_load(saved_root_name)) goto out;