From patchwork Thu Feb 25 19:36:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 8426251 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 325029FC33 for ; Thu, 25 Feb 2016 19:36:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6569420266 for ; Thu, 25 Feb 2016 19:36:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A5FD20279 for ; Thu, 25 Feb 2016 19:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933637AbcBYTgv (ORCPT ); Thu, 25 Feb 2016 14:36:51 -0500 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:35344 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933286AbcBYTgu (ORCPT ); Thu, 25 Feb 2016 14:36:50 -0500 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id E23218EE171; Thu, 25 Feb 2016 11:36:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1456429009; bh=1RPb4O33v2z7XE3pUv6Jw29RQwkafOhzJyWjZCtOlFY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=gQI4ZpVOViZVzMYJtneUXAp687RueA6DeKQDER1Qe+mbJA71SYh6UlIXUPYOBbvAw aGVquku98oaLZN2YsVqN1qA7qbcEhdM1PWMjNGBMmQ01F8cImYNuDt63bwVWB212jX dQO6RDyODwzbNB5DfwToB5SOdGfJmiHESAA41QwA= 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 oUGUpoL5Y3p0; Thu, 25 Feb 2016 11:36:49 -0800 (PST) Received: from [153.66.254.194] (unknown [184.11.141.41]) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 899538EE07D; Thu, 25 Feb 2016 11:36:49 -0800 (PST) Message-ID: <1456429008.2377.4.camel@HansenPartnership.com> Subject: [Patch v2 1/3] fs: add filp_clone_open API From: James Bottomley To: containers@lists.linux-foundation.org, linux-fsdevel Cc: Al Viro Date: Thu, 25 Feb 2016 11:36:48 -0800 In-Reply-To: <1456428890.2377.2.camel@HansenPartnership.com> References: <1456428890.2377.2.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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, UNPARSEABLE_RELAY autolearn=no 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 --- 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 55bdc75..bb7ffd6 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1004,6 +1004,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) { + fput(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;