Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (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 8907B3491D0; Mon, 1 Jun 2026 07:02:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780297343; cv=none; b=BDBWXtsF4UxU1i0vm++GuTmzDj9ldrZ1nsZ/NohFpABT85TrOztWC5/cmojsBDy6SUwqLfx3+PTVl+MXtmrwsUdm/PEGPRT2tRMHWNzDIikEeYgCYnha0K2XO964BSM5Tzf10blOCHe8RN5jUbSbMYHLj/lNUUrkOSZ6TRhZBvg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780297343; c=relaxed/simple; bh=P4KwkPt0fMoERo61EV1t//1o0ysqzdLyWxGs7RW9dNU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WHy95P6+0ZojhOj9RRcWhesbNAsG6tjMiZ8KFZupE4PCQNfblAe5oeFj8Bw8bmhYBAbinRfHh/u708S50GrqSqbG+ABWvzq/w7/NYIO1CjNJb1GbaLedyjvtfZJ1thoIAPgsHHxrlsGeG+XjlJIn04CySoveOYkzcmfuzEZ6Nbo= 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=m9E5Brxw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Dp9oN9dY; arc=none smtp.client-ip=103.168.172.156 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="m9E5Brxw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Dp9oN9dY" Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id EE79C1400094; Mon, 1 Jun 2026 03:02:21 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Mon, 01 Jun 2026 03:02:21 -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=1780297341; x=1780383741; bh=ukA0waQZgFpOMFmIchLsDRcKXGnCYiu8mnELMKajGXg=; b= m9E5BrxwLfUhwWGUpvdnnB8COjK+vUQxBrBvVhAPnThz8TtU6CbuqzsZL9uMdffa On7og9wZFbMvJ3QuedWEQsvS1CHZblpVZGF3C7I4dejJ/jDcnk/irKc2huxVzVAW jqz9vVKY4GJ1JHT7vFu2euW7V1hnOn0iDrpGcRSIrb+i34BHVyWnuH6/JKGmM1v+ bBPnno5NaRB+JSPSOUpNmFFafv9PKRYH2UftlwuBdtGrmdwI/UYm6ll0U2IN8hjr OMWQPSw8b0kFppZtlCrtro09z3+eXYYRUYYo4c2gGyvsD7iylcXRY6BAlJ54bvjF ZF3/KGpx2XdGtNwHazhegA== 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=1780297341; x=1780383741; bh=u kA0waQZgFpOMFmIchLsDRcK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7btYw X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 1 Jun 2026 03:02:18 -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 16/18] nfsd: switch nfsd4_create_file() to use vfs_lookup_open() Date: Mon, 1 Jun 2026 16:38:04 +1000 Message-ID: <20260601070042.249432-17-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 Currently nfsd4_create_file() performs a lookup via start_creating() and then if that reports a negative dentry it uses dentry_create() to create the file. dentry_create() will use ->atomic_open if available. Part of the point of supporting atomic_open is to avoid needing a separate lookup. ->atomic_open can do lookup, create, open all in one operation. So doing a lookup before dentry_create() is not optimal. So change to use vfs_lookup_open() which combines lookup, create, and open, either by using atomic_open or by calling the individual functions (but not both). This means that we don't need to lock that parent (start_creating/end_creating). We also don't need to get write-access (fh_want_write/fh_drop_write) except in the unusual case of a read-only creating open. Also we only set O_EXCL in the NFS4_CREATE_GUARDED case. This the an NFS protocol option which requests the server to take full responsibility for atomic-create. For NFS4_CREATE_EXCLUSIVE and NFS4_CREATE_EXCLUSIVE4_1 the NFS protocol takes responsibilty for exclusive create by providing a verifier to store with the file, and using O_EXCL would interfere with this. Signed-off-by: NeilBrown --- fs/nfsd/nfs4proc.c | 59 ++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 5bd19e5d9e34..61ecd4123817 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -219,14 +219,13 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, .na_seclabel = &open->op_label, }; int oflags = O_CREAT | O_LARGEFILE; - struct dentry *parent, *child = ERR_PTR(-EINVAL); - struct path path = { + struct dentry *child = ERR_PTR(-EINVAL); + struct path parent = { .mnt = fhp->fh_export->ex_path.mnt, + .dentry = fhp->fh_dentry, }; __u32 v_mtime, v_atime; - struct inode *inode; __be32 status; - int host_err; if (isdotent(open->op_fname, open->op_fnamelen)) return nfserr_exist; @@ -236,10 +235,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_EXEC); if (status != nfs_ok) return status; - parent = fhp->fh_dentry; - inode = d_inode(parent); - if (!IS_POSIXACL(inode)) + if (!IS_POSIXACL(d_inode(parent.dentry))) iap->ia_mode &= ~current_umask(); if (!is_create_with_attrs(open)) { @@ -287,9 +284,12 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, iap->ia_atime.tv_sec = v_atime; iap->ia_mtime.tv_nsec = 0; iap->ia_atime.tv_nsec = 0; - - oflags |= O_EXCL; } + /* Only ask the fs to provide exclusive-create if we aren't using + * the NFS verifier to do it outselves. + */ + if (open->op_createmode == NFS4_CREATE_GUARDED) + oflags |= O_EXCL; switch (open->op_share_access & NFS4_SHARE_ACCESS_BOTH) { case NFS4_SHARE_ACCESS_WRITE: @@ -302,33 +302,18 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, oflags |= O_RDONLY; } - host_err = fh_want_write(fhp); - if (host_err) - return nfserrno(host_err); - - child = start_creating(&nop_mnt_idmap, parent, - &QSTR_LEN(open->op_fname, open->op_fnamelen)); - if (IS_ERR(child)) { - status = nfserrno(PTR_ERR(child)); - goto out_write; - } - path.dentry = child; - - if (d_really_is_negative(child)) { - open->op_filp = dentry_create(&path, oflags, open->op_iattr.ia_mode, - current_cred()); - child = path.dentry; - - if (IS_ERR(open->op_filp)) { - end_creating(child); - status = nfserrno(PTR_ERR(open->op_filp)); - open->op_filp = NULL; - goto out_write; - } - - open->op_created = open->op_filp->f_mode & FMODE_CREATED; + open->op_filp = vfs_lookup_open(&parent, + &QSTR_LEN(open->op_fname, + open->op_fnamelen), + oflags, + open->op_iattr.ia_mode); + if (IS_ERR(open->op_filp)) { + status = nfserrno(PTR_ERR(open->op_filp)); + open->op_filp = NULL; + goto out; } - end_creating(child); + child = open->op_filp->f_path.dentry; + open->op_created = open->op_filp->f_mode & FMODE_CREATED; fh_drop_write(fhp); status = fh_compose(resfhp, fhp->fh_export, child, fhp); @@ -397,10 +382,6 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, out: nfsd_attrs_free(&attrs); return status; - -out_write: - fh_drop_write(fhp); - goto out; } /** -- 2.50.0.107.gf914562f5916.dirty