Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) (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 99075361DC3 for ; Mon, 13 Jul 2026 06:23:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783923807; cv=none; b=aLPKozooKUQpPRopHdsWz95t4oEjniXGk9VjcXWoJs5U65hMCq4SpioyBQ0HBLLOb3Eayc1GUqqrbB7RFdFvSg2gbrUToM+Ha9PJq5201ASjo/4Y4FJ8seSM4pdBmD2UUpbv9KjTe1rGoizQIiP1x4iqzvpzdGeNAdxbJYsrqb4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783923807; c=relaxed/simple; bh=arEh3C7bbOMJ/zOZnuXOmYxcyT+1JhfiNkxxbpil2gA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qcJL3DMydT+WhzAE4NYJvxhWjyhN39fdNXpbBdJQ63JMl0V2fmm8rvqk6A46dfjsnqSlVwjNwaLvTv+cFp/7Cexh10dLHuEVvs6rYMTZOIEobwPGctKLJrMrd5Y8DRjNbTK+shgiI/+S7Hj1tZyGSvqL3NPpjFpEzXY6aPU44iM= 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=RvnDyoRz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NN8B3KLT; arc=none smtp.client-ip=202.12.124.157 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="RvnDyoRz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NN8B3KLT" Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfhigh.stl.internal (Postfix) with ESMTP id DCA307A005D; Mon, 13 Jul 2026 02:23:24 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Mon, 13 Jul 2026 02:23:25 -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=fm2; t=1783923804; x=1784010204; bh=Lq9SASk7pRQDcMh2L8mxigwR7uheNOx6IbE3zJ3Vnd8=; b= RvnDyoRzhXNuBRfzq0JHnKn52JJyRWJd5hf6PLx+N5NPhJpdD7KirjWSOwrWKIJv EpMqj2jr6sNzOkwmSYiMLPiLB08s45Z5gnvHTHF4CTJL3hrwOtgy8w7fScSk2yFK apBhppJFPxqZlOxDJvJrAwZ+19YQvKOdwiKP7kpUJYLrlXun/+CeZNXSD0RIvr8w KCnU4oHo22qnp9yNa7Xfu+bQgQyNmsnnoMQT+S1JhD+HfsTXo5m9walCjk38ARRH 41IYHrFFcAi6t5sZP1azv7fb/VoeZSNrsiDoMTKQ18+pY/HHeLJM3zsguIoIvWzT 5e2i4SHwDZ6TFLw5JPy8aw== 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=fm2; t=1783923804; x=1784010204; bh=L q9SASk7p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VOU3+OpU1LEGFxhuGr37OCcaQKkvXaA4P17j5jRDhxY//ytA X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 Jul 2026 02:23:22 -0400 (EDT) From: NeilBrown To: Chuck Lever , Jeff Layton Cc: Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH v3 10/17] nfsd: (almost) always open file in nfsd4_create_file() Date: Mon, 13 Jul 2026 16:15:33 +1000 Message-ID: <20260713062219.6399-11-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260713062219.6399-1-neilb@ownmail.net> References: <20260713062219.6399-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: NeilBrown If the file is found to already exist, open it anyway. This will normally be needed eventually anyway, and providing a consistently valid op_filp will simplify future changes. To simplify this, change nfsd_check_obj_isreg() to take a dentry. This doesn't apply in the case where the file was found in the dcache to be mounted-on. That takes a different path and doesn't require an early open. Signed-off-by: NeilBrown --- fs/nfsd/nfs4proc.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 7fb63d1836ba..abe27a4841eb 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -168,9 +168,9 @@ do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfs return fh_verify(rqstp, current_fh, S_IFREG, accmode); } -static __be32 nfsd_check_obj_isreg(struct svc_fh *fh, u32 minor_version) +static __be32 nfsd_check_obj_isreg(struct dentry *child, u32 minor_version) { - umode_t mode = d_inode(fh->fh_dentry)->i_mode; + umode_t mode = d_inode(child)->i_mode; if (S_ISREG(mode)) return nfs_ok; @@ -252,6 +252,8 @@ static __be32 nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct svc_fh *resfhp, struct nfsd4_open *open) { + struct nfsd4_compoundres *resp = rqstp->rq_resp; + struct nfsd4_compound_state *cstate = &resp->cstate; struct iattr *iap = &open->op_iattr; struct nfsd_attrs attrs = { .na_iattr = iap, @@ -364,7 +366,35 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, } if (d_really_is_positive(child)) { - /* No creation needed */ + /* + * open the file so that we consistently have a valid + * op_filp. + */ + struct path path = {.mnt = fhp->fh_export->ex_path.mnt, + .dentry = child, + }; + unsigned int oflags = O_LARGEFILE; + + switch (open->op_share_access & NFS4_SHARE_ACCESS_BOTH) { + case NFS4_SHARE_ACCESS_WRITE: + oflags |= O_WRONLY; + break; + case NFS4_SHARE_ACCESS_BOTH: + oflags |= O_RDWR; + break; + default: + oflags |= O_RDONLY; + } + + status = nfsd_check_obj_isreg(child, cstate->minorversion); + if (status == nfs_ok) { + open->op_filp = dentry_open(&path, oflags, + current_cred()); + if (IS_ERR(open->op_filp)) { + status = nfserrno(PTR_ERR(open->op_filp)); + open->op_filp = NULL; + } + } } else if (create_status) { status = create_status; } else { @@ -518,7 +548,8 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru } if (status) goto out; - status = nfsd_check_obj_isreg(*resfh, cstate->minorversion); + status = nfsd_check_obj_isreg((*resfh)->fh_dentry, + cstate->minorversion); if (status) goto out; -- 2.50.0.107.gf914562f5916.dirty