Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1426B3803FD; Mon, 1 Jun 2026 07:01:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780297281; cv=none; b=Ghy8tjzVqJ5kfKJ0ssMrU5bn8BUoOQRecpCdSjkW+KD+yRtq4Yz86tjl1rpCuNFv/KjytPH3fSuLxcBuSCDrPGIJ+yrUlnFfY1HYk/lTqA5JQBw6y4Ki+6ScUcXogJ+CqFyHbXXmzDzjI5iBtdp0ydDLuUQRO1snVvcSHTWDBjw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780297281; c=relaxed/simple; bh=vzAnzmkf9RRzUI/3s7X84NSAL5vbKM8mRBmLGsk13x8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i66Jh4wXjdhRCCpZ/PsINnZAsYRI/lDZxUO4upOnOcAlIkED+ciYeOPxR+W+JiAnYXm1XOjy0XjfMVrLIkVuJ9BxNx4ORzOypzMuW312bqqWA33PGRETI3LbDmp4TOnDN2noaj0/B712BH48PwM39TjytftyWOOK3FhX1rjABeE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net; spf=pass smtp.mailfrom=ownmail.net; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b=Iy+oubfW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kBkNDf0g; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ownmail.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b="Iy+oubfW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kBkNDf0g" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id 5F0D8EC020D; Mon, 1 Jun 2026 03:01:19 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Mon, 01 Jun 2026 03:01:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to; s=fm1; t=1780297279; x=1780383679; bh=RldziyTR8Ox6+Sc1JrCA7D+WNb7qt/CM7rHJFkwpNSw=; b= Iy+oubfWSi2fk2KckEy5wUFV1wnlcgGan1nqoE2Cu+mtAXlAzJnFL9soFUQAwm+z JijhJU2VDSDDUinQawgPGK4K+HiLoKSNIvD/+Gj65ZH2kJHjw270s0wcxYXFxljG dD293Bl/R4VL24hkAn8UZJOjgXU58GfwmtbtqicuSg7dLs79e5mN7jUs9kxdc9Mk 0dj7mzmvg8TB5ppsEXjBK1dLXSPSwRaSCu7A5bv67SglDLUR7T3lE6tezIsHvRnU Y+AdiknOvgpAVurJESwmxOB4ApNZEb/WlXU73PXvVc4HNtXe99uhVW8NUbN3FITm fMuXcoacc3MnmupqH8Fy/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1780297279; x=1780383679; bh=R ldziyTR8Ox6+Sc1JrCA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7Q X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 1 Jun 2026 03:01:16 -0400 (EDT) From: NeilBrown To: Christian Brauner , Alexander Viro , Chuck Lever , Jeff Layton Cc: Jan Kara , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, "Jori Koolstra" , Benjamin Coddington , "Mateusz Guzik" Subject: [PATCH 04/18] VFS: add vfs_lookup_open() Date: Mon, 1 Jun 2026 16:37:52 +1000 Message-ID: <20260601070042.249432-5-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260601070042.249432-1-neilb@ownmail.net> References: <20260601070042.249432-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: NeilBrown vfs_lookup_open() is a limited version of lookup_open() which is exported for nfsd to use - to replace dentry_create(). It is limited in that no filename is given (thus no auditing) and no LOOKUP_ flags are passed. A few "intent" LOOKUP flags are deduced from the open flags. Signed-off-by: NeilBrown --- fs/namei.c | 54 +++++++++++++++++++++++++++++++++++++++++++ include/linux/namei.h | 3 +++ 2 files changed, 57 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index 18a43c24d7f1..db3fddbccd21 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4571,6 +4571,60 @@ static struct dentry *lookup_open(const struct path *path, struct file *file, goto out; } +/** + * vfs_lookup_open - open and possibly create a regular file + * @parent: directory to contain file + * @last: final component of file name + * @open_flag: O_flags + * @mode: initial permissions for file + * + * Open a file after lookup and/or create. This provides similar + * functionality open_last_lookups() for in-kernel users, particularly + * nfsd. + * It uses ->atomic_open or ->lookup / ->create / ->open as appropriate. + * + * Returns: the opened struct file, or an error. + */ +struct file *vfs_lookup_open(struct path *parent, struct qstr *last, + int open_flag, umode_t mode) +{ + struct file *file __free(fput) = NULL; + unsigned int lookup_flags = LOOKUP_OPEN; + struct dentry *dentry; + int error = 0; + + error = lookup_noperm_common(last, parent->dentry); + if (error) + return ERR_PTR(error); + + file = alloc_empty_file(open_flag, current_cred()); + if (IS_ERR(file)) + return file; + + if (open_flag & O_CREAT) { + lookup_flags |= LOOKUP_CREATE; + if (open_flag & O_EXCL) + lookup_flags |= LOOKUP_EXCL; + } + dentry = lookup_open(parent, file, last, lookup_flags, NULL, + open_flag, S_IFREG | mode); + if (IS_ERR(dentry)) + return ERR_CAST(dentry); + + if (d_really_is_negative(dentry)) { + error = -ENOENT; + } else if (!(file->f_mode & FMODE_OPENED)) { + struct path path = {.mnt = parent->mnt, .dentry = dentry }; + + error = vfs_open(&path, file); + } + dput(dentry); + + if (error) + return ERR_PTR(error); + return no_free_ptr(file); +} + static inline bool trailing_slashes(struct nameidata *nd) { return (bool)nd->last.name[nd->last.len]; diff --git a/include/linux/namei.h b/include/linux/namei.h index 2ad6dd9987b9..8c048c97a7f7 100644 --- a/include/linux/namei.h +++ b/include/linux/namei.h @@ -103,6 +103,9 @@ struct dentry *start_creating_dentry(struct dentry *parent, struct dentry *start_removing_dentry(struct dentry *parent, struct dentry *child); +struct file *vfs_lookup_open(struct path *parent, struct qstr *last, + int open_flag, umode_t mode); + /* end_creating - finish action started with start_creating * @child: dentry returned by start_creating() or vfs_mkdir() * -- 2.50.0.107.gf914562f5916.dirty