From patchwork Thu Mar 31 14:55:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 8713961 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 627EC9F38C for ; Thu, 31 Mar 2016 14:55:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8693C2028D for ; Thu, 31 Mar 2016 14:55:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7CAE120279 for ; Thu, 31 Mar 2016 14:55:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756974AbcCaOzX (ORCPT ); Thu, 31 Mar 2016 10:55:23 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:55040 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754666AbcCaOzW (ORCPT ); Thu, 31 Mar 2016 10:55:22 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 2E22B8EE341; Thu, 31 Mar 2016 07:55:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1459436122; bh=DB3mg9TB5H72IAoCXl4nS+LLTfm5wIcZT7q3bsKXNEo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=RJ/JEV9PRPVd3cSzj71xebaSmSbM4M7xldaENBRpjDefv0hg+WT6q9IIJEmNHowkS VnhjhU1rG3gF7DLNL0748DFaVma1PkkLuZWl0L9kN9yqHV3EX5mErgSe3d+0bqg1ID BnCXmiMmeCqk8flp2l1RyO0t8v6BvX5fgDnXWKd8= Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id n45AV4i1zUxN; Thu, 31 Mar 2016 07:55:22 -0700 (PDT) Received: from [10.0.6.30] (unknown [12.139.153.2]) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id CF8A48EE0CD; Thu, 31 Mar 2016 07:55:21 -0700 (PDT) Message-ID: <1459436121.2958.22.camel@HansenPartnership.com> Subject: [Patch v3 1/3] fs: add filp_clone_open API From: James Bottomley To: containers@lists.linux-foundation.org, linux-fsdevel Cc: Al Viro , Jan Kara Date: Thu, 31 Mar 2016 07:55:21 -0700 In-Reply-To: <1459436046.2958.21.camel@HansenPartnership.com> References: <1459436046.2958.21.camel@HansenPartnership.com> X-Mailer: Evolution 3.16.5 Mime-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I need an API that allows me to obtain a clone of the current file pointer to pass in to an exec handler. I've labelled this as an internal API because I can't see how it would be useful outside of the fs subsystem. The use case will be a persistent binfmt_misc handler. Signed-off-by: James Bottomley Acked-by: Serge Hallyn Acked-by: Jan Kara --- fs/internal.h | 1 + fs/open.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/fs/internal.h b/fs/internal.h index b71deee..c8ca0c9 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -108,6 +108,7 @@ extern long do_handle_open(int mountdirfd, struct file_handle __user *ufh, int open_flag); extern int open_check_o_direct(struct file *f); extern int vfs_open(const struct path *, struct file *, const struct cred *); +extern struct file *filp_clone_open(struct file *); /* * inode.c diff --git a/fs/open.c b/fs/open.c index 17cb6b1..bfe6f2b 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1002,6 +1002,26 @@ struct file *file_open_root(struct dentry *dentry, struct vfsmount *mnt, } EXPORT_SYMBOL(file_open_root); +struct file *filp_clone_open(struct file *oldfile) +{ + struct file *file; + int retval; + + file = get_empty_filp(); + if (IS_ERR(file)) + return file; + + file->f_flags = oldfile->f_flags; + retval = vfs_open(&oldfile->f_path, file, oldfile->f_cred); + if (retval) { + put_filp(file); + return ERR_PTR(retval); + } + + return file; +} +EXPORT_SYMBOL(filp_clone_open); + long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode) { struct open_flags op;