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 6AAE435F165 for ; Mon, 13 Jul 2026 06:23:59 +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=1783923840; cv=none; b=Birz+7yKaYZD/NmgM2O8D9MbyptVaWP7AkBYgp9FKT5vskSBeTYTne8Rcik4QhwlA0OHyUm7mwRYjeLlc4YAXYQiIAa0IbldMxfxofGpg7S6+epPGiskPa7UVMo6/5eEsPLMFINY0MFqwqHkG98+84QMfvX7p9HpDpXFYICL8EQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783923840; c=relaxed/simple; bh=LstOm4/B2kI3R8ObauUhUIUqz1L2iXyPxiaTAK6vfzk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jGMSKxraIN8Goa68U6F1Fuze9eDiBX0eYTGe956cRga8UZciNqXq0QupfPqyMKlzLalvi7aJamzZebvRvvS+Byrx5N3lkpFItxWr6uKjfpopSViL4KxFEh2GhWi2Z6Fulgz83FK/h/aZLKSrUBj1WE2ShJp682EGyKQ5QtF3YGQ= 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=JDf1R+XK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=X24J8oSc; 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="JDf1R+XK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="X24J8oSc" Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id B829E7A005D; Mon, 13 Jul 2026 02:23:58 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Mon, 13 Jul 2026 02:23:58 -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=1783923838; x=1784010238; bh=upWLU7VcM20azzQF70lPvVKbJSD3/Tuh+GEXuyoIZOI=; b= JDf1R+XKsuGJT0CAHARxe3OkwCP63j/OVgU7AR+uW4G7euyFACEdkWPnAeYnvVUv gFJ/otLik/S556XEhtQO0z9LPH+eE3d1DpUq83QCNGl5CN8Q/ASjHVvZjGOjvClL sQNzeBxbn93CEutp/628SMDX2KNcS5R4b7P0Nfjfcv7JItk/L/4e2b2EkdGYOhtS YW6aSYsPR04NcWJvkM1skDWGn9J4DOoILKdWklnuw1K78GTjJ5qyoxysFLsvQLMW AmpbUtDTPdQHZyvJFSF+glKX9fQvY+0ozpJNE2QQWQj7Hd9G8043JtQUY0cffypt 2A0/wZlfcV3G8Chg4OcVYA== 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=1783923838; x=1784010238; bh=u pWLU7VcM20azzQF70lPvVKbJSD3/Tuh+GE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IeC4snA X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 Jul 2026 02:23:56 -0400 (EDT) From: NeilBrown To: Chuck Lever , Jeff Layton Cc: Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH v3 17/17] nfsd: use do_lookup_open() for non-creating open requests too. Date: Mon, 13 Jul 2026 16:15:40 +1000 Message-ID: <20260713062219.6399-18-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 Now that we have do_lookup_open() for creating open requests, we can use it for non-creating too as do_lookup_open() is already able to do that. This prepares for switching to vfs_lookup_open() once the VFS provides that. This will ensure consistent code and fs-interaction with VFS open(). The resulting simplification allows fh_fill_pre_attrs_unlocked() to be moved into nfsd4_open_file() (renamed from nfsd4_create_file()) so it is closer to fh_full_post_attrs and fh_fill_post_noop calls. As ->op_create_mode isn't defined when op_create is zero, we need a local create_mode which is -1 (illegal value) when op_create is zero. The non-create path now doesn't use nfsd_lookup(). As mount-point crossing including nfsd_check_access() is already included for existing names, this does not lose us anything. Signed-off-by: NeilBrown --- fs/nfsd/nfs4proc.c | 108 ++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 6a4bddfc92cc..68fa3c7c987f 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -241,29 +241,30 @@ static struct file *do_lookup_open(struct path *parent, } /* - * Implement NFSv4's unchecked, guarded, and exclusive create - * semantics for regular files. Open state for this new file is - * subsequently fabricated in nfsd4_process_open2(). - * + * Implement NFSv4's open semantics for regular files. + * Both create (unchecked, guarded, and exclusive) and non-create. + * Open state for this new file is subsequently fabricated in + * nfsd4_process_open2(). * Upon return, caller must release @fhp and @resfhp. */ static __be32 -nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, - struct svc_fh *resfhp, struct nfsd4_open *open) +nfsd4_open_file(struct svc_rqst *rqstp, struct svc_fh *fhp, + struct svc_fh *resfhp, struct nfsd4_open *open) { struct iattr *iap = &open->op_iattr; struct nfsd_attrs attrs = { .na_iattr = iap, .na_seclabel = &open->op_label, }; - int oflags = O_CREAT | O_LARGEFILE; + int oflags = O_LARGEFILE; 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; - __be32 status, create_status; + int createmode = -1; + __be32 status, create_status = 0; int want_write_err; if (name_is_dot_dotdot(open->op_fname, open->op_fnamelen)) @@ -275,6 +276,10 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, if (status != nfs_ok) return status; + status = fh_fill_pre_attrs_unlocked(fhp); + if (status) + return status; + if (open->op_createmode == NFS4_CREATE_UNCHECKED) { /* * If name is already in dcache we need to check for mountpoints @@ -307,11 +312,15 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, if (!IS_POSIXACL(d_inode(parent.dentry))) iap->ia_mode &= ~current_umask(); + if (open->op_create) { + createmode = open->op_createmode; + oflags |= O_CREAT; + } /* * For the EXCLUSIVE modes we do our own uniqueness tests * so don't want O_EXCL. */ - if (open->op_createmode == NFS4_CREATE_GUARDED) + if (createmode == NFS4_CREATE_GUARDED) oflags |= O_EXCL; switch (open->op_share_access & NFS4_SHARE_ACCESS_BOTH) { @@ -346,7 +355,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, v_mtime = 0; v_atime = 0; - if (nfsd4_create_is_exclusive(open->op_createmode)) { + if (nfsd4_create_is_exclusive(createmode)) { u32 *verifier = (u32 *)open->op_verf.data; /* @@ -368,11 +377,11 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, iap->ia_atime.tv_nsec = 0; } - create_status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE); - if (create_status) - /* Might still succeed if no create is needed */ - oflags &= ~O_CREAT; - + if (oflags & O_CREAT) { + create_status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE); + if (create_status) + oflags &= ~O_CREAT; + } open->op_filp = do_lookup_open(&parent, &QSTR_LEN(open->op_fname, open->op_fnamelen), @@ -394,14 +403,15 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, goto out; if (!open->op_created && - nfsd4_create_is_exclusive(open->op_createmode) && + nfsd4_create_is_exclusive(createmode) && inode_get_mtime_sec(d_inode(child)) == v_mtime && inode_get_atime_sec(d_inode(child)) == v_atime && d_inode(child)->i_size == 0) open->op_created = true; if (!open->op_created) { - if (open->op_createmode == NFS4_CREATE_UNCHECKED) { + if (open->op_create == NFS4_OPEN_NOCREATE || + createmode == NFS4_CREATE_UNCHECKED) { /* NFSv4 protocol requires change attributes * even though no change happened. */ @@ -496,46 +506,34 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru fh_init(*resfh, NFS4_FHSIZE); open->op_truncate = false; - status = fh_fill_pre_attrs_unlocked(current_fh); - if (status) - goto out; - if (open->op_create) { - /* FIXME: check session persistence and pnfs flags. - * The nfsv4.1 spec requires the following semantics: - * - * Persistent | pNFS | Server REQUIRED | Client Allowed - * Reply Cache | server | | - * -------------+--------+-----------------+-------------------- - * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 - * | | | (SHOULD) - * | | and EXCLUSIVE4 | or EXCLUSIVE4 - * | | | (SHOULD NOT) - * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 - * yes | no | GUARDED4 | GUARDED4 - * yes | yes | GUARDED4 | GUARDED4 - */ + /* FIXME: check session persistence and pnfs flags. + * The nfsv4.1 spec requires the following semantics: + * + * Persistent | pNFS | Server REQUIRED | Client Allowed + * Reply Cache | server | | + * -------------+--------+-----------------+-------------------- + * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 + * | | | (SHOULD) + * | | and EXCLUSIVE4 | or EXCLUSIVE4 + * | | | (SHOULD NOT) + * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 + * yes | no | GUARDED4 | GUARDED4 + * yes | yes | GUARDED4 | GUARDED4 + */ - current->fs->umask = open->op_umask; - status = nfsd4_create_file(rqstp, current_fh, *resfh, open); - current->fs->umask = 0; + current->fs->umask = open->op_umask; + status = nfsd4_open_file(rqstp, current_fh, *resfh, open); + current->fs->umask = 0; - /* - * Following rfc 3530 14.2.16, and rfc 5661 18.16.4 - * use the returned bitmask to indicate which attributes - * we used to store the verifier: - */ - if (nfsd4_create_is_exclusive(open->op_createmode) && status == 0) - open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS | - FATTR4_WORD1_TIME_MODIFY); - } else { - status = nfsd_lookup(rqstp, current_fh, - open->op_fname, open->op_fnamelen, *resfh); - /* - * NFSv4 protocol requires change attributes even though - * no change happened. - */ - fh_fill_post_noop(current_fh); - } + /* + * Following rfc 3530 14.2.16, and rfc 5661 18.16.4 + * use the returned bitmask to indicate which attributes + * we used to store the verifier: + */ + if (open->op_create && + nfsd4_create_is_exclusive(open->op_createmode) && status == 0) + open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS | + FATTR4_WORD1_TIME_MODIFY); if (status) goto out; status = nfserrno(nfsd_check_obj_isreg((*resfh)->fh_dentry)); -- 2.50.0.107.gf914562f5916.dirty