Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2364702imm; Tue, 10 Jul 2018 19:23:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcDZBBItXRLEzI0szh1Z9ZyQT42BbEH9881bwLX1+3YNbUp6TOVul32jLvUioK+hf0v+mtN X-Received: by 2002:a63:214f:: with SMTP id s15-v6mr22857777pgm.267.1531275809236; Tue, 10 Jul 2018 19:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531275809; cv=none; d=google.com; s=arc-20160816; b=KPB8cpf3mRAf+u3+n8P1LkONcfnAq3NOyL1LQ8t7ux5mHfZF+D2ZrkjZkamu0OvXMp 9HlUWksnvwCBtUk4Dg6FgN4Hvj7901eEAtIDTg3/dEMjB4AvMbVIc6uEiRrtYL7jDXvf eFxMnQEis9+nzfcalSQTBYXLbQWN5Z8pKc7AWyIlEDD+pYMAL3b34F0orKCs1IWCWVuA cn92n3sEWqOXrV6nwIRZtfMmaAzWqoGyv+RvP7BO+J9lB+3DU9+6/JzCEfBwa7WbuzaJ xjLjbCSUIIB8FVRnA6z6hey4AfkCDAVEd6t43FGMpOCQanUiBe4tCxFP1RCH6dJ31l3x a8ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=9wun2GaRT8N4RY2bCTbGdWfg0WH/YOqH5LzHN6yVgUk=; b=mT94KxJp8EvA7SavugD+JittQPVPP9UnpwuFlM4qqwrJMV8UZlANxWTBIszC4Rz1ZR gaHYFj5lFDsVWlzsKHAhmKjoR2rUlnQyuhBw9LKVYZKKTp79fYT4JOOYWHsCfyxR4X9c y059vI1vnkGnI5/BQPzBPzBq6qwahCwTB/AkGj6swmnU0yr9RctrDLR2H1q97rHiQ9h9 kQb3dYDeJlwYNOhQTTpED84sJ7KidSW/gYYhxa4kD3Mgm66+/lhKcpZFEt2hVKDnOHOJ 7cigXjQ4wTXS09K377Wmf35/TT78x3Bwcbg6Axp0f4n+RzTBi/jWM/08RIWOvJ0e1HUD nZTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y7-v6si17802119plk.391.2018.07.10.19.23.14; Tue, 10 Jul 2018 19:23:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732666AbeGKCYJ (ORCPT + 99 others); Tue, 10 Jul 2018 22:24:09 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:45706 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732567AbeGKCYI (ORCPT ); Tue, 10 Jul 2018 22:24:08 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fd4le-0003LV-QG; Wed, 11 Jul 2018 02:22:10 +0000 From: Al Viro To: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Miklos Szeredi Subject: [RFC][PATCH 36/42] new helper: alloc_file_clone() Date: Wed, 11 Jul 2018 03:22:00 +0100 Message-Id: <20180711022206.12571-36-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180711022206.12571-1-viro@ZenIV.linux.org.uk> References: <20180711021136.GN30522@ZenIV.linux.org.uk> <20180711022206.12571-1-viro@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro alloc_file_clone(old_file, mode, ops): create a new struct file with ->f_path equal to that of old_file. pipe converted. Signed-off-by: Al Viro --- fs/file_table.c | 11 +++++++++++ fs/pipe.c | 4 +--- include/linux/file.h | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/fs/file_table.c b/fs/file_table.c index 23bc46ea5f4b..9097a6fb5a2f 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -209,6 +209,17 @@ struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt, } EXPORT_SYMBOL(alloc_file_pseudo); +struct file *alloc_file_clone(struct file *base, fmode_t mode, + const struct file_operations *fops) +{ + struct file *f = alloc_file(&base->f_path, mode, fops); + if (!IS_ERR(f)) { + path_get(&f->f_path); + f->f_mapping = base->f_mapping; + } + return f; +} + /* the real guts of fput() - releasing the last reference to file */ static void __fput(struct file *file) diff --git a/fs/pipe.c b/fs/pipe.c index c8c4265bf87b..94323a1d7c92 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -760,14 +760,12 @@ int create_pipe_files(struct file **res, int flags) f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT)); f->private_data = inode->i_pipe; - res[0] = alloc_file(&f->f_path, FMODE_READ, &pipefifo_fops); + res[0] = alloc_file_clone(f, FMODE_READ, &pipefifo_fops); if (IS_ERR(res[0])) { put_pipe_info(inode, inode->i_pipe); fput(f); return PTR_ERR(res[0]); } - - path_get(&f->f_path); res[0]->private_data = inode->i_pipe; res[0]->f_flags = O_RDONLY | (flags & O_NONBLOCK); res[1] = f; diff --git a/include/linux/file.h b/include/linux/file.h index 0a4ef2315f75..22becbfd4cec 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -23,6 +23,8 @@ extern struct file *alloc_file(const struct path *, fmode_t mode, const struct file_operations *fop); extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *, const char *, fmode_t, const struct file_operations *); +extern struct file *alloc_file_clone(struct file *, fmode_t, + const struct file_operations *); static inline void fput_light(struct file *file, int fput_needed) { -- 2.11.0