From patchwork Tue May 25 14:15:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12279101 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.7 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,URIBL_BLOCKED,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 9AF8BC2B9F8 for ; Tue, 25 May 2021 14:15:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7DFB86142B for ; Tue, 25 May 2021 14:15:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233687AbhEYORU (ORCPT ); Tue, 25 May 2021 10:17:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233680AbhEYORT (ORCPT ); Tue, 25 May 2021 10:17:19 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E78BBC061574; Tue, 25 May 2021 07:15:48 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id u7so7851673plq.4; Tue, 25 May 2021 07:15:48 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=q7paX5pQtdRcKci/3W+wcYLEJPlSnAsnPdHVHTh/LRs=; b=kZPYJZ2NriOTxsBJWsFwZD5m3eB72ohfiBtGOIygKTvBAi71wXk/LaofKxL8E/Cmmp /9WIG2KdR7v/AIyrstAH42UFQLVqGOoq12HccXDTCgX/J6HyaX2QHuVdjPDE/s/jbldl co7drts/PmPPNhRheVVd/vNw44LfuuxaPXXldZKu2OR4TQ//jvGkz4HNjokaI5x222Vv U9Oz5q4eqdU7kk5IV/AnRiKy2lOavB/vWb2P6tpk0txl+wieW53+wiwV1ISUq2c7kJyg ut6QPBVgeZhhS8vyQNgP1lCoieD+qmxDEh8K4LFMEvJGgdSCAHtLP05zxEHiOhsWQQ7X miNA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=q7paX5pQtdRcKci/3W+wcYLEJPlSnAsnPdHVHTh/LRs=; b=lmQjW5OrQwfBUNWYpQH9PJfU/EDE5pPWl0/1qQvH8eDrkLuqeUjvg8N0N8yGs4/Wd/ mYKgUaNUEWCnjNYRf3KKrBQQiVXOUC3d8P0I5c3Qr+W3jFCeqfz3tMuT6s8xS+OtanjS MFGAPLDf7+6q12D3Oh5FTYNyM1zuhazOVubyTAuHcg1EhRj+0Q5W+XcCpJ0IvOAlzZUz +80KVV9HaophFY0AkJaDiNAUcjaB5KH6Y+Vz+bacHaEUsJV6ydiIIBmpqch2SXA6ISlV F/T9UELqsYje3+5I2d6TS9Z73ntUpqNPE+M9hQyYf5CtBcvMExoXZ8EXZfDaeWUAVwR0 WyRQ== X-Gm-Message-State: AOAM532aHEALPBK2rLk9mMdh/pAih3LVZbt0Yhe/DF0PzX+yzlsc5h36 cKOJocGBDzoUeobCIGWHgHM= X-Google-Smtp-Source: ABdhPJzrVPjpB4mQHlYIzhvYjyB97jdU6BH0RKj1WI24txL8A8w2JSeu/zutAQrPsW/68V65B++0gQ== X-Received: by 2002:a17:90a:6b4f:: with SMTP id x15mr4924419pjl.25.1621952148403; Tue, 25 May 2021 07:15:48 -0700 (PDT) Received: from localhost ([178.236.46.205]) by smtp.gmail.com with ESMTPSA id u1sm14606242pgh.80.2021.05.25.07.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 07:15:47 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: dong.menglong@zte.com.cn To: mcgrof@kernel.org, josh@joshtriplett.org Cc: viro@zeniv.linux.org.uk, keescook@chromium.org, samitolvanen@google.com, ojeda@kernel.org, johan@kernel.org, bhelgaas@google.com, masahiroy@kernel.org, dong.menglong@zte.com.cn, joe@perches.com, axboe@kernel.dk, hare@suse.de, jack@suse.cz, tj@kernel.org, gregkh@linuxfoundation.org, song@kernel.org, neilb@suse.de, akpm@linux-foundation.org, f.fainelli@gmail.com, arnd@arndb.de, linux@rasmusvillemoes.dk, wangkefeng.wang@huawei.com, brho@google.com, mhiramat@kernel.org, rostedt@goodmis.org, vbabka@suse.cz, glider@google.com, pmladek@suse.com, chris@chrisdown.name, ebiederm@xmission.com, jojing64@gmail.com, terrelln@fb.com, geert@linux-m68k.org, mingo@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, jeyu@kernel.org Subject: [PATCH v2 1/3] init/main.c: introduce function ramdisk_exec_exist() Date: Tue, 25 May 2021 22:15:22 +0800 Message-Id: <20210525141524.3995-2-dong.menglong@zte.com.cn> X-Mailer: git-send-email 2.32.0.rc0 In-Reply-To: <20210525141524.3995-1-dong.menglong@zte.com.cn> References: <20210525141524.3995-1-dong.menglong@zte.com.cn> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Menglong Dong Introduce the function ramdisk_exec_exist, which is used to check the exist of 'ramdisk_execute_command'. Add the flag 'LOOKUP_DOWN' to 'init_eaccess' to make it follow the mount on '/' while path lookup. Signed-off-by: Menglong Dong --- fs/init.c | 2 +- init/main.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/init.c b/fs/init.c index 5c36adaa9b44..a1839fdcf467 100644 --- a/fs/init.c +++ b/fs/init.c @@ -115,7 +115,7 @@ int __init init_eaccess(const char *filename) struct path path; int error; - error = kern_path(filename, LOOKUP_FOLLOW, &path); + error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DOWN, &path); if (error) return error; error = path_permission(&path, MAY_ACCESS); diff --git a/init/main.c b/init/main.c index eb01e121d2f1..1153571ca977 100644 --- a/init/main.c +++ b/init/main.c @@ -1522,6 +1522,11 @@ void __init console_on_rootfs(void) fput(file); } +bool __init ramdisk_exec_exist(void) +{ + return init_eaccess(ramdisk_execute_command) == 0; +} + static noinline void __init kernel_init_freeable(void) { /* @@ -1568,7 +1573,7 @@ static noinline void __init kernel_init_freeable(void) * check if there is an early userspace init. If yes, let it do all * the work */ - if (init_eaccess(ramdisk_execute_command) != 0) { + if (!ramdisk_exec_exist()) { ramdisk_execute_command = NULL; prepare_namespace(); } From patchwork Tue May 25 14:15:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12279103 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.7 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,URIBL_BLOCKED,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 A5E02C2B9F8 for ; Tue, 25 May 2021 14:16:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84F846142C for ; Tue, 25 May 2021 14:16:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233795AbhEYORa (ORCPT ); Tue, 25 May 2021 10:17:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233757AbhEYOR1 (ORCPT ); Tue, 25 May 2021 10:17:27 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64A64C061574; Tue, 25 May 2021 07:15:54 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id cu11-20020a17090afa8bb029015d5d5d2175so13315578pjb.3; Tue, 25 May 2021 07:15:54 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=EJ7U/OKohkc8JHO0oQ9gAirJ7L2O/GLriRaj6yb1ZLY=; b=ez7oG5GKjYNk4c1VjKKzyT4Z9Di4jXim+4kAnRtwDSjItVjE87HVaynuT+CgxIjKCV WoAena0QO8l4MPQTxXnSxzK8HbpTJ2BCT+staKimBjOYS6CeF8RmQMSEWyTL4bD9HKUO NiKlETZV+bGNa4RoIKJkCo+CrArpdkxliza0+F7neb9X3VyawOoNAkAtn2nJY5RVrHio 27SjHei+DE945LBW/yIzYgvTJFPQaWRKWUCGbXAxcRryCy2hhnxamaO73u9mTc4XCwsi j9lnosxxnvpEFjNfwEukiwpYNqr/NiFT3qaPc14qvdHrvGE5pBLDkDpFp7QCLKpfE5ix wSSw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=EJ7U/OKohkc8JHO0oQ9gAirJ7L2O/GLriRaj6yb1ZLY=; b=c7h8FXJviBl4g3QkpW1pbQjTvlZ7YVeMMvv6UgLiNEdlGRBTzw3aKYXQk6gfN1sVvs U8AIfFgdiFHe0y2K2K3siADj4IVv9bbpA/hwU85O/XLBc1PzpjebfCrw2CmHQZaKl9CK pgtJZTVLLUYc0B4NY6PYG0Bc1VvZCW58V5JNrNiR1B7wm0g5BQmbGpTk48JTNBBeTLgE kNf3u+roeDh/N/D0laN1xOCbnym6sR51clVn/CNi9UE73br5ImBHAPzg2OgRdDl2V9uX cU2EV7CxFAyPg/N+sYYzvHqI2dmpSM0NpCCmrFlJRKAVCAbqfVilW7+cNxTBCyd42goV OC0A== X-Gm-Message-State: AOAM533cXmtwfaZ6IYkuQpr35/JZi/kkY4S12GqeUPWQnZoqSwMB2P2R g4HxSkRZ3dC8HVOBQRBp518= X-Google-Smtp-Source: ABdhPJzYB3/sYAqu7jiFiglEGj3LMWQJEiaYmbPCv2VqIlmV/QxLzRU1z5PG7SoKIYVoo+ulouJ4gg== X-Received: by 2002:a17:902:758f:b029:f4:ad8e:b2c7 with SMTP id j15-20020a170902758fb02900f4ad8eb2c7mr30568686pll.58.1621952153903; Tue, 25 May 2021 07:15:53 -0700 (PDT) Received: from localhost ([178.236.46.205]) by smtp.gmail.com with ESMTPSA id 10sm14944566pgl.39.2021.05.25.07.15.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 07:15:53 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: dong.menglong@zte.com.cn To: mcgrof@kernel.org, josh@joshtriplett.org Cc: viro@zeniv.linux.org.uk, keescook@chromium.org, samitolvanen@google.com, ojeda@kernel.org, johan@kernel.org, bhelgaas@google.com, masahiroy@kernel.org, dong.menglong@zte.com.cn, joe@perches.com, axboe@kernel.dk, hare@suse.de, jack@suse.cz, tj@kernel.org, gregkh@linuxfoundation.org, song@kernel.org, neilb@suse.de, akpm@linux-foundation.org, f.fainelli@gmail.com, arnd@arndb.de, linux@rasmusvillemoes.dk, wangkefeng.wang@huawei.com, brho@google.com, mhiramat@kernel.org, rostedt@goodmis.org, vbabka@suse.cz, glider@google.com, pmladek@suse.com, chris@chrisdown.name, ebiederm@xmission.com, jojing64@gmail.com, terrelln@fb.com, geert@linux-m68k.org, mingo@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, jeyu@kernel.org Subject: [PATCH v2 2/3] init/do_cmounts.c: introduce 'user_root' for initramfs Date: Tue, 25 May 2021 22:15:23 +0800 Message-Id: <20210525141524.3995-3-dong.menglong@zte.com.cn> X-Mailer: git-send-email 2.32.0.rc0 In-Reply-To: <20210525141524.3995-1-dong.menglong@zte.com.cn> References: <20210525141524.3995-1-dong.menglong@zte.com.cn> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Menglong Dong If using container platforms such as Docker, upon initialization it wants to use pivot_root() so that currently mounted devices do not propagate to containers. An example of value in this is that a USB device connected prior to the creation of a containers on the host gets disconnected after a container is created; if the USB device was mounted on containers, but already removed and umounted on the host, the mount point will not go away until all containers unmount the USB device. Another reason for container platforms such as Docker to use pivot_root is that upon initialization the net-namspace is mounted under /var/run/docker/netns/ on the host by dockerd. Without pivot_root Docker must either wait to create the network namespace prior to the creation of containers or simply deal with leaking this to each container. pivot_root is supported if the rootfs is a initrd or block device, but it's not supported if the rootfs uses an initramfs (tmpfs). This means container platforms today must resort to using block devices if they want to pivot_root from the rootfs. A workaround to use chroot() is not a clean viable option given every container will have a duplicate of every mount point on the host. In order to support using container platforms such as Docker on all the supported rootfs types we must extend Linux to support pivot_root on initramfs as well. This patch does the work to do just that. pivot_root will unmount the mount of the rootfs from its parent mount and mount the new root to it. However, when it comes to initramfs, it donesn't work, because the root filesystem has not parent mount, which makes initramfs not supported by pivot_root. In order to support pivot_root on initramfs we introduce a second "user_root" mount which is created before we do the cpio unpacking. The filesystem of the "user_root" mount is the same the rootfs. While mounting the 'user_root', 'rootflags' is passed to it, and it means that we can set options for the mount of rootfs in boot cmd now. For example, the size of tmpfs can be set with 'rootflags=size=1024M'. Signed-off-by: Menglong Dong --- init/do_mounts.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++ init/do_mounts.h | 18 ++++++++- init/initramfs.c | 10 +++++ usr/Kconfig | 10 +++++ 4 files changed, 138 insertions(+), 1 deletion(-) diff --git a/init/do_mounts.c b/init/do_mounts.c index a78e44ee6adb..2fd168cca480 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -617,6 +617,107 @@ void __init prepare_namespace(void) init_chroot("."); } +#ifdef CONFIG_INITRAMFS_USER_ROOT +#ifdef CONFIG_TMPFS +static __init bool is_tmpfs_enabled(void) +{ + return (!root_fs_names || strstr(root_fs_names, "tmpfs")) && + !saved_root_name[0]; +} +#endif + +static __init bool is_ramfs_enabled(void) +{ + return true; +} + +struct fs_user_root { + bool (*enabled)(void); + char *dev_name; + char *fs_name; +}; + +static struct fs_user_root user_roots[] __initdata = { +#ifdef CONFIG_TMPFS + { + .enabled = is_tmpfs_enabled, + .dev_name = "tmpfs", + .fs_name = "tmpfs", + }, +#endif + { + .enabled = is_ramfs_enabled, + .dev_name = "ramfs", + .fs_name = "ramfs" + } +}; +static struct fs_user_root * __initdata user_root; + +/* + * The syscall 'pivot_root' is used to change root and it is able to + * clean the old mounts, which make it preferred by container platforms + * such as Docker. However, initramfs is not supported by pivot_root, + * and 'chroot()' has to be used, which is unable to clean the mounts + * that propagate from HOST. These useless mounts make the release of + * removable device or network namespace a big problem. + * + * To make initramfs supported by pivot_root, the mount of the root + * filesystem should have a parent, which will make it unmountable. In + * this function, the second mount, which is called 'user root', is + * created and mounted on '/root', and it will be made the root filesystem + * in end_mount_user_root() by init_chroot(). + * + * The 'user root' has a parent mount, which makes it unmountable and + * pivot_root work. + * + * What's more, root_mountflags and root_mount_data are used here, which + * makes the 'rootflags' in boot cmd work for 'user root'. + */ +int __init mount_user_root(void) +{ + return do_mount_root(user_root->dev_name, + user_root->fs_name, + root_mountflags & ~MS_RDONLY, + root_mount_data); +} + +/* + * This function is used to chroot to new initramfs root that + * we unpacked on success. It will chdir to '/' and umount + * the secound mount on failure. + */ +void __init end_mount_user_root(bool succeed) +{ + init_chdir("/"); + if (!succeed) { + init_umount("/root", 0); + return; + } + + init_mount("/root", "/", NULL, MS_MOVE, NULL); + if (!ramdisk_exec_exist()) { + init_umount("/..", 0); + return; + } + + init_chroot("/.."); +} + +void __init init_user_rootfs(void) +{ + struct fs_user_root *root; + int i; + + for (i = 0; i < ARRAY_SIZE(user_roots); i++) { + root = &user_roots[i]; + if (root->enabled()) { + user_root = root; + break; + } + } +} +#endif + static bool is_tmpfs; static int rootfs_init_fs_context(struct fs_context *fc) { diff --git a/init/do_mounts.h b/init/do_mounts.h index 7a29ac3e427b..3802c7a3ba91 100644 --- a/init/do_mounts.h +++ b/init/do_mounts.h @@ -10,9 +10,25 @@ #include #include +extern int root_mountflags; + void mount_block_root(char *name, int flags); void mount_root(void); -extern int root_mountflags; +bool ramdisk_exec_exist(void); + +#ifdef CONFIG_INITRAMFS_USER_ROOT + +int mount_user_root(void); +void end_mount_user_root(bool succeed); +void init_user_rootfs(void); + +#else + +static inline int mount_user_root(void) { return 0; } +static inline void end_mount_user_root(bool succeed) { } +static inline void init_user_rootfs(void) { } + +#endif static inline __init int create_dev(char *name, dev_t dev) { diff --git a/init/initramfs.c b/init/initramfs.c index af27abc59643..ffa78932ae65 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -16,6 +16,8 @@ #include #include +#include "do_mounts.h" + static ssize_t __init xwrite(struct file *file, const char *p, size_t count, loff_t *pos) { @@ -682,15 +684,23 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie) else printk(KERN_INFO "Unpacking initramfs...\n"); + init_user_rootfs(); + + if (mount_user_root()) + panic("Failed to create user root"); + err = unpack_to_rootfs((char *)initrd_start, initrd_end - initrd_start); if (err) { + end_mount_user_root(false); #ifdef CONFIG_BLK_DEV_RAM populate_initrd_image(err); #else printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err); #endif + goto done; } + end_mount_user_root(true); done: /* * If the initrd region is overlapped with crashkernel reserved region, diff --git a/usr/Kconfig b/usr/Kconfig index 8bbcf699fe3b..f9c96de539c3 100644 --- a/usr/Kconfig +++ b/usr/Kconfig @@ -52,6 +52,16 @@ config INITRAMFS_ROOT_GID If you are not sure, leave it set to "0". +config INITRAMFS_USER_ROOT + bool "Create 'user root' to make pivot_root supported" + default y + help + Before unpacking cpio, create a second mount and make it become + the root filesystem. Therefore, initramfs will be supported by + pivot_root(). + + If container platforms is used with initramfs, say Y. + config RD_GZIP bool "Support initial ramdisk/ramfs compressed using gzip" default y From patchwork Tue May 25 14:15:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12279105 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.7 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,URIBL_BLOCKED,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 5B396C2B9F8 for ; Tue, 25 May 2021 14:16:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34E396142B for ; Tue, 25 May 2021 14:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233850AbhEYORf (ORCPT ); Tue, 25 May 2021 10:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233794AbhEYORa (ORCPT ); Tue, 25 May 2021 10:17:30 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEC9DC061574; Tue, 25 May 2021 07:15:59 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id i5so22884066pgm.0; Tue, 25 May 2021 07:15:59 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=SuUtFT7bIVivZR5ps0dFd9PsqAyY9zXdI0c6lNEWZ/Q=; b=cWgSLD1R917gAZOpogiffvofkdeLhXfBzx+5hzb+UqnvK7FtUp4PnY+3Ll3EgmVBNT sVyiBBk/tFdg7+oOeWWm42sQDhKwAWwp11ecTxDKK61GrpJBZL6v5GA+GNoZQoYxVEmA 4aPwqX1QwrCNkdhCtvZjQcCfb6YKfczcBNK56MAsrzM4McCCoXZhYrdZSSNo+MlriYjQ dch7QPTdNQ5Uqi0//WL6k1LXb3mUw0GWYNDkUxDDaOueheQLJbUVhpHhjhNWZx8g6p8a mg5COU6q9GRUWk9F9g2EQtNTf3tmEa5KQ050O2C2SKpNCWAiHRwwB9+EF5ccXgbDOZL5 z61g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=SuUtFT7bIVivZR5ps0dFd9PsqAyY9zXdI0c6lNEWZ/Q=; b=nMSVuwuXXrMGhCT0lqfX+Vh6y5gfolUPuzRZCZmmH5M9uAb0AtrXCZJZUUu0LfIHoQ J8uiLh3f3i7W2UrXbip9lFkikHVPre1OsrqKcIkGJX+JEUtRbqJlXKEzYqIvtDQqYgHf EUaOQiC4JEPTXO606EQ/MqltrlSDrxSYuMZCHSOXIAh60+kaeJNXEQ/STbUHYCivS+AH OHWnxWera/XdWGj/rIXWIHlewAvw7+dtNrrkUJhRgzvuUydKYLl9niWx6wOochZUhAil arAGIskJNatYtRjoeNL9f+RVFPfXR32Uotp2I6azIgz7CPmwluTVYKDw7Ix9YCzgX517 OWIA== X-Gm-Message-State: AOAM530jH4VrCsDZyHjeGi+rvtb8GqSgHy2qeCh9sodlltTV5lbT6t3C YKGJW/i9sStrMjNDkKKOpHU= X-Google-Smtp-Source: ABdhPJwlXHT/ygDAwnSyyXOqbP4rCUtJ42z7h7gzukjpVvVpJc37jxPThlv3OpxUWgYHQaEQKk/+7A== X-Received: by 2002:a62:5c1:0:b029:2a9:7589:dd30 with SMTP id 184-20020a6205c10000b02902a97589dd30mr30144626pff.66.1621952159421; Tue, 25 May 2021 07:15:59 -0700 (PDT) Received: from localhost ([178.236.46.205]) by smtp.gmail.com with ESMTPSA id gt23sm12687791pjb.13.2021.05.25.07.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 07:15:59 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: dong.menglong@zte.com.cn To: mcgrof@kernel.org, josh@joshtriplett.org Cc: viro@zeniv.linux.org.uk, keescook@chromium.org, samitolvanen@google.com, ojeda@kernel.org, johan@kernel.org, bhelgaas@google.com, masahiroy@kernel.org, dong.menglong@zte.com.cn, joe@perches.com, axboe@kernel.dk, hare@suse.de, jack@suse.cz, tj@kernel.org, gregkh@linuxfoundation.org, song@kernel.org, neilb@suse.de, akpm@linux-foundation.org, f.fainelli@gmail.com, arnd@arndb.de, linux@rasmusvillemoes.dk, wangkefeng.wang@huawei.com, brho@google.com, mhiramat@kernel.org, rostedt@goodmis.org, vbabka@suse.cz, glider@google.com, pmladek@suse.com, chris@chrisdown.name, ebiederm@xmission.com, jojing64@gmail.com, terrelln@fb.com, geert@linux-m68k.org, mingo@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, jeyu@kernel.org Subject: [PATCH v2 3/3] init/do_mounts.c: fix rootfs_fs_type with ramfs Date: Tue, 25 May 2021 22:15:24 +0800 Message-Id: <20210525141524.3995-4-dong.menglong@zte.com.cn> X-Mailer: git-send-email 2.32.0.rc0 In-Reply-To: <20210525141524.3995-1-dong.menglong@zte.com.cn> References: <20210525141524.3995-1-dong.menglong@zte.com.cn> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Menglong Dong As for the existence of 'user root' which is introduced in previous patch, 'rootfs_fs_type', which is used as the root of mount tree, is not used directly any more. So it make no sense to make it tmpfs while 'INITRAMFS_USER_ROOT' is enabled. Make 'rootfs_fs_type' ramfs when 'INITRAMFS_USER_ROOT' enabled. Signed-off-by: Menglong Dong --- include/linux/init.h | 5 +++++ init/do_mounts.c | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/init.h b/include/linux/init.h index 045ad1650ed1..d65b12fe438c 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -148,7 +148,12 @@ extern unsigned int reset_devices; /* used by init/main.c */ void setup_arch(char **); void prepare_namespace(void); +#ifndef CONFIG_INITRAMFS_USER_ROOT void __init init_rootfs(void); +#else +static inline void __init init_rootfs(void) { } +#endif + extern struct file_system_type rootfs_fs_type; #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX) diff --git a/init/do_mounts.c b/init/do_mounts.c index 2fd168cca480..74f5b0fc8bdf 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -716,7 +716,14 @@ void __init init_user_rootfs(void) } } } -#endif + +struct file_system_type rootfs_fs_type = { + .name = "rootfs", + .init_fs_context = ramfs_init_fs_context, + .kill_sb = kill_litter_super, +}; + +#else static bool is_tmpfs; static int rootfs_init_fs_context(struct fs_context *fc) @@ -739,3 +746,4 @@ void __init init_rootfs(void) (!root_fs_names || strstr(root_fs_names, "tmpfs"))) is_tmpfs = true; } +#endif