Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp709273pxv; Wed, 14 Jul 2021 13:38:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6m8vmPQif8XS1Cmy53yjVNgxz8N2wDLMY5Qs/1sEUpRZTJHBfrSHSonD9AtnsJWf2XFl5 X-Received: by 2002:a17:907:d89:: with SMTP id go9mr51316ejc.165.1626295117982; Wed, 14 Jul 2021 13:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626295117; cv=none; d=google.com; s=arc-20160816; b=bpNUONk+voWU2aF0W6FaCXpOZApCzfLM83uq4jl4DWQEfdiUEpDWtFev3eBtsnA4r+ 7d0b5S7xa/9E04bcD/mOeFYi9Z53PLYPDSiqqlmRgVOMLmTcY3F13Zp1RLo5esJY6lVl Sdl85Vh4XDAw89TtwARqmpQ+X7+XzlQyUGF9iA5VuWCxfSxx9tdCgo0Wc7gYkPtNkQ/k TSNz/WPxKYOD3f4WneBJdJsXszDKNtYH5A41zpg+W36mkdtmHZNqAAh42zo6ZjbS4bXQ +KUQafFjmFRbXBCpKdRkiLJTXXSkZTR7ppLUQ7/ZmhYyCcjR4fs4ej6pMj3qcbralJAV zBGA== 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=T2gePRK85A6LvcvTNsyknMtURDmZvzCUYyYRTFLIZuI=; b=kWLtL3tWObUHG+bM3pgMkDFL4LPlbV860wrvOA++I/j9dZTpytPOhkxrKnGp0DXP7b H35OumV9l77JWnRGBDhqPwnkjoiMBgT41mXDrHRHO4WdnHr/WLcML17NPaSEEB0XZnN8 sx1dLZfAPsS2zkwke9LcW45U3n3uucPeK1fOS9+/I+bvKGpUs2Cue6CixG3WiZJ+KQWC 58FURhgZPlQL0SCcvYZJtuGgN4nFALVx1cDxxk47h6vH5CqATWFO68tWN+vebRtCJt+5 BzwljUMk+XhFhoOnhiqsSW9MBbtfOB7plkHF5pxWm+PmhGM/LOOzq6ii38OvtRA2RZHd FhIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P73VSTHB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r4si3586145edp.476.2021.07.14.13.38.12; Wed, 14 Jul 2021 13:38:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P73VSTHB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238219AbhGNU0w (ORCPT + 99 others); Wed, 14 Jul 2021 16:26:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39551 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235738AbhGNU0n (ORCPT ); Wed, 14 Jul 2021 16:26:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626294231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T2gePRK85A6LvcvTNsyknMtURDmZvzCUYyYRTFLIZuI=; b=P73VSTHBgRxA+a33GIFsBdJiUvqqSUPZX2od5chUN6by46yUmnCqYuorQVuezXgYuPn8p/ Zn4ggePNSFyOApBzraUno2+x4RiMhWkfGg9XHA9XJufAkNRchA5YtRpfKc9aPy56xgzonD 0VtynSINSM810JNiEn1rcl7mRb2vaZE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-240-n9mOPQq3OAWspcS-D5xOsQ-1; Wed, 14 Jul 2021 16:23:47 -0400 X-MC-Unique: n9mOPQq3OAWspcS-D5xOsQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B612100CCE0; Wed, 14 Jul 2021 20:23:42 +0000 (UTC) Received: from horse.redhat.com (ovpn-114-201.rdu2.redhat.com [10.10.114.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id C938138E50; Wed, 14 Jul 2021 20:23:40 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 6355A226CA5; Wed, 14 Jul 2021 16:23:40 -0400 (EDT) From: Vivek Goyal To: viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, hch@lst.de, virtio-fs@redhat.com, v9fs-developer@lists.sourceforge.net, stefanha@redhat.com, miklos@szeredi.hu Subject: [PATCH v3 2/3] init: allow mounting arbitrary non-blockdevice filesystems as root Date: Wed, 14 Jul 2021 16:23:20 -0400 Message-Id: <20210714202321.59729-3-vgoyal@redhat.com> In-Reply-To: <20210714202321.59729-1-vgoyal@redhat.com> References: <20210714202321.59729-1-vgoyal@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig Currently the only non-blockdevice filesystems that can be used as the initial root filesystem are NFS and CIFS, which use the magic "root=/dev/nfs" and "root=/dev/cifs" syntax that requires the root device file system details to come from filesystem specific kernel command line options. Add a little bit of new code that allows to just pass arbitrary string mount options to any non-blockdevice filesystems so that it can be mounted as the root file system. For example a virtiofs root file system can be mounted using the following syntax: "root=myfs rootfstype=virtiofs rw" Based on an earlier patch from Vivek Goyal . Signed-off-by: Christoph Hellwig --- init/do_mounts.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/init/do_mounts.c b/init/do_mounts.c index ec32de3ad52b..bdeb90b8d669 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -534,6 +534,45 @@ static int __init mount_cifs_root(void) } #endif +static bool __init fs_is_nodev(char *fstype) +{ + struct file_system_type *fs = get_fs_type(fstype); + bool ret = false; + + if (fs) { + ret = !(fs->fs_flags & FS_REQUIRES_DEV); + put_filesystem(fs); + } + + return ret; +} + +static int __init mount_nodev_root(void) +{ + char *fs_names, *fstype; + int err = -EINVAL; + + fs_names = (void *)__get_free_page(GFP_KERNEL); + if (!fs_names) + return -EINVAL; + split_fs_names(fs_names, root_fs_names); + + for (fstype = fs_names; *fstype; fstype += strlen(fstype) + 1) { + if (!fs_is_nodev(fstype)) + continue; + err = do_mount_root(root_device_name, fstype, root_mountflags, + root_mount_data); + if (!err) + break; + if (err != -EACCES && err != -EINVAL) + panic("VFS: Unable to mount root \"%s\" (%s), err=%d\n", + root_device_name, fstype, err); + } + + free_page((unsigned long)fs_names); + return err; +} + void __init mount_root(void) { #ifdef CONFIG_ROOT_NFS @@ -550,6 +589,10 @@ void __init mount_root(void) return; } #endif + if (ROOT_DEV == 0 && root_device_name && root_fs_names) { + if (mount_nodev_root() == 0) + return; + } #ifdef CONFIG_BLOCK { int err = create_dev("/dev/root", ROOT_DEV); -- 2.31.1