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=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 F23BFC3F2CD for ; Wed, 4 Mar 2020 14:53:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C36F220732 for ; Wed, 4 Mar 2020 14:53:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726275AbgCDOxz (ORCPT ); Wed, 4 Mar 2020 09:53:55 -0500 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:59953 "EHLO relay2-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725795AbgCDOxz (ORCPT ); Wed, 4 Mar 2020 09:53:55 -0500 X-Originating-IP: 50.39.173.182 Received: from localhost (50-39-173-182.bvtn.or.frontiernet.net [50.39.173.182]) (Authenticated sender: josh@joshtriplett.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 0D47240011; Wed, 4 Mar 2020 14:53:52 +0000 (UTC) Date: Wed, 4 Mar 2020 06:53:51 -0800 From: Josh Triplett To: Jens Axboe , io-uring@vger.kernel.org Subject: [PATCH WIP 3/3] fs: pipe2: Support O_SPECIFIC_FD Message-ID: <402a713780960758480361b707056a57d8d7a1c6.1583333579.git.josh@joshtriplett.org> References: <20200304143548.GA407676@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200304143548.GA407676@localhost> Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This allows the caller of pipe2 to specify one or both file descriptors rather than having them automatically use the lowest available file descriptor. The caller can specify either file descriptor as -1 to allow that file descriptor to use the lowest available. Signed-off-by: Josh Triplett --- fs/pipe.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 2144507447c5..7bc576836ec0 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -936,19 +936,19 @@ static int __do_pipe_flags(int *fd, struct file **files, int flags) int error; int fdw, fdr; - if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT)) + if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT | O_SPECIFIC_FD)) return -EINVAL; error = create_pipe_files(files, flags); if (error) return error; - error = get_unused_fd_flags(flags); + error = get_specific_unused_fd_flags(fd[0], flags); if (error < 0) goto err_read_pipe; fdr = error; - error = get_unused_fd_flags(flags); + error = get_specific_unused_fd_flags(fd[1], flags); if (error < 0) goto err_fdr; fdw = error; @@ -969,7 +969,10 @@ static int __do_pipe_flags(int *fd, struct file **files, int flags) int do_pipe_flags(int *fd, int flags) { struct file *files[2]; - int error = __do_pipe_flags(fd, files, flags); + int error; + if (flags & O_SPECIFIC_FD) + return -EINVAL; + error = __do_pipe_flags(fd, files, flags); if (!error) { fd_install(fd[0], files[0]); fd_install(fd[1], files[1]); @@ -987,6 +990,10 @@ static int do_pipe2(int __user *fildes, int flags) int fd[2]; int error; + if (flags & O_SPECIFIC_FD) + if (copy_from_user(fd, fildes, sizeof(fd))) + return -EFAULT; + error = __do_pipe_flags(fd, files, flags); if (!error) { if (unlikely(copy_to_user(fildes, fd, sizeof(fd)))) { -- 2.25.1