From mboxrd@z Thu Jan 1 00:00:00 1970 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=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 BEFC8C433E8 for ; Tue, 28 Jul 2020 16:35:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B03522B42 for ; Tue, 28 Jul 2020 16:35:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="LxM66CH3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731812AbgG1QfK (ORCPT ); Tue, 28 Jul 2020 12:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731478AbgG1QfJ (ORCPT ); Tue, 28 Jul 2020 12:35:09 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 194C5C061794; Tue, 28 Jul 2020 09:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=i1H+gCppzv/oG+6sLkbZmKQE2JPL8SjqHA8WTb2gSvU=; b=LxM66CH3HTPccSmCXgX61L4i3x lcFVojpvIzaXLMSJtSHVOjYQc1VPg8nqUMGKn26icgHeCTDwa8cHthtW0NyH9IL7x2K6H/JISRVQ8 JPjpG3xAigGpx594tGH/CGBwTS6i+qC6/bKK6FkfnsZJZTHT+M/4vF+It4SBOG2cwOdDfrVoib8bQ SKzq5r8Fy6WzZpVjLBXx+/sapnEvfU8lNNYQaRCR8MWe4VeeF/i1AciLsd00Ig8++1b8MByywdmZX UNpBAk8J1tPn5xuPMOXn0AlyHrb5reNQLbLvHkH954tGZ9cpRydpCm4IgPR8ell8DTsT3PERwJxOn 5Vw0CBQg==; Received: from [2001:4bb8:180:6102:fd04:50d8:4827:5508] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1k0SZD-00075W-DO; Tue, 28 Jul 2020 16:35:04 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH 23/23] init: add an init_dup helper Date: Tue, 28 Jul 2020 18:34:16 +0200 Message-Id: <20200728163416.556521-24-hch@lst.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200728163416.556521-1-hch@lst.de> References: <20200728163416.556521-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add a simple helper to grab a reference to a file and install it at the next available fd, and switch the early init code over to it. Signed-off-by: Christoph Hellwig --- fs/init.c | 12 ++++++++++++ include/linux/init_syscalls.h | 1 + init/main.c | 7 +++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fs/init.c b/fs/init.c index db5c48a85644fa..730e05acda2392 100644 --- a/fs/init.c +++ b/fs/init.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -251,3 +252,14 @@ int __init init_utimes(char *filename, struct timespec64 *ts) path_put(&path); return error; } + +int __init init_dup(struct file *file) +{ + int fd; + + fd = get_unused_fd_flags(0); + if (fd < 0) + return fd; + fd_install(get_unused_fd_flags(0), get_file(file)); + return 0; +} diff --git a/include/linux/init_syscalls.h b/include/linux/init_syscalls.h index 3654b525ac0b17..92045d18cbfc99 100644 --- a/include/linux/init_syscalls.h +++ b/include/linux/init_syscalls.h @@ -16,3 +16,4 @@ int __init init_unlink(const char *pathname); int __init init_mkdir(const char *pathname, umode_t mode); int __init init_rmdir(const char *pathname); int __init init_utimes(char *filename, struct timespec64 *ts); +int __init init_dup(struct file *file); diff --git a/init/main.c b/init/main.c index 1c710d3e1d461a..089e21504b1fc1 100644 --- a/init/main.c +++ b/init/main.c @@ -1467,10 +1467,9 @@ void __init console_on_rootfs(void) pr_err("Warning: unable to open an initial console.\n"); return; } - get_file_rcu_many(file, 2); - fd_install(get_unused_fd_flags(0), file); - fd_install(get_unused_fd_flags(0), file); - fd_install(get_unused_fd_flags(0), file); + init_dup(file); + init_dup(file); + init_dup(file); } static noinline void __init kernel_init_freeable(void) -- 2.27.0