From: Jeff Layton <jlayton@kernel.org>
To: NeilBrown <neil@brown.name>, Chuck Lever <chuck.lever@oracle.com>
Cc: Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
linux-nfs@vger.kernel.org
Subject: Re: [PATCH v3 14/17] nfsd: reduce want-write range in nfsd4_create_file()
Date: Thu, 16 Jul 2026 08:29:28 -0400 [thread overview]
Message-ID: <b8af8636b7268933395dae83b6088c5d7b602435.camel@kernel.org> (raw)
In-Reply-To: <20260713062219.6399-15-neilb@ownmail.net>
On Mon, 2026-07-13 at 16:15 +1000, NeilBrown wrote:
> From: NeilBrown <neil@brown.name>
>
> nfsd4_create_file() needs write access to the mount for two purposes:
>
> 1/ to create/open the file.
> 2/ to set attributes on the newly created (or pre-existing) file.
>
> Currently this is all handled by holding the write access across the
> open and the setattr. A subsequent patch will necessarily change how
> write access is gained for the open. So we reduce the range for the
> first want_write, and add another one to cover setattr. If we failed to
> get write access, it is only fatal if there were attrs to set.
>
> We call nfsd_create_setattr() if at all possible, even when no attrs, as
> it also calls commit_metadata and we need to be certain that the file
> creation has been synced. If the mount became read-only since the
> creation happened, we can safely assume that the sync happened as part
> of that.
>
> Signed-off-by: NeilBrown <neil@brown.name>
> ---
> fs/nfsd/nfs4proc.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> index adfc1f5ccd98..0d1bcb12ecbc 100644
> --- a/fs/nfsd/nfs4proc.c
> +++ b/fs/nfsd/nfs4proc.c
> @@ -344,6 +344,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
> &QSTR_LEN(open->op_fname, open->op_fnamelen));
> if (IS_ERR(child)) {
> status = nfserrno(PTR_ERR(child));
> + if (!want_write_err)
> + fh_drop_write(fhp);
> goto out;
> }
> path.dentry = child;
> @@ -378,6 +380,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
> }
> }
> end_creating(child);
> + if (!want_write_err)
> + fh_drop_write(fhp);
> if (status != nfs_ok)
> goto out;
>
> @@ -421,7 +425,16 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
> if ((iap->ia_valid & ATTR_SIZE) && (iap->ia_size == 0))
> iap->ia_valid &= ~ATTR_SIZE;
>
> - status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs);
> + /* We will need write access to set the attrs */
> + want_write_err = fh_want_write(fhp);
> + if (!want_write_err) {
> + status = nfsd_create_setattr(rqstp, fhp,
> + resfhp, &attrs);
> + fh_drop_write(fhp);
> + } else if (nfsd_attrs_valid(&attrs)) {
> + /* Needed write access */
> + status = nfserrno(want_write_err);
> + }
>
> if (attrs.na_labelerr)
> open->op_bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
> @@ -432,8 +445,6 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
> if (attrs.na_paclerr)
> open->op_bmval[2] &= ~FATTR4_WORD2_POSIX_ACCESS_ACL;
> out:
> - if (!want_write_err)
> - fh_drop_write(fhp);
> nfsd_attrs_free(&attrs);
> return status;
> }
It sucks that file creation is so fraught with peril and places that
things can go wrong and leave stuff sitting out on the fs. I wonder if
we ought to be using O_TMPFILE where possible to do all of this setup
and only later link it into the namespace. That's a much bigger change
though of course.
Reviewed-by: Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2026-07-16 12:29 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 6:15 [PATCH v3 00/17] nfsd: refactor nfs4_create_file() NeilBrown
2026-07-13 6:15 ` [PATCH v3 01/17] nfsd: honour client-provided attributes for NFS4_CREATE_EXCLUSIVE4_1 NeilBrown
2026-07-13 6:15 ` [PATCH v3 02/17] nfsd: correctly handle CREATE of mounted-on files NeilBrown
2026-07-13 13:38 ` Chuck Lever
2026-07-13 21:46 ` NeilBrown
2026-07-13 6:15 ` [PATCH v3 03/17] nfsd: replace fh_fill_both_attrs() with fh_fill_post_noop() NeilBrown
2026-07-13 6:15 ` [PATCH v3 04/17] nfsd: move fh_want_write() after preamble in nfsd4_create_file() NeilBrown
2026-07-13 6:15 ` [PATCH v3 05/17] nfsd: move more nfs-specific code into preamble of nfsd4_create_file() NeilBrown
2026-07-13 6:15 ` [PATCH v3 06/17] nfsd: remove subtlety from nfsd4_create_file() NeilBrown
2026-07-13 6:15 ` [PATCH v3 07/17] nfsd: in nfsd4_create_file() let VFS report if file was created NeilBrown
2026-07-13 6:15 ` [PATCH v3 08/17] nfsd: nfsd4_create_file(): Move NFSD_MAY_CREATE check earlier NeilBrown
2026-07-13 6:15 ` [PATCH v3 09/17] nfsd: fh_want_write) failure need not be immediately fatal for nfsd4_create_file() NeilBrown
2026-07-13 6:15 ` [PATCH v3 10/17] nfsd: (almost) always open file in nfsd4_create_file() NeilBrown
2026-07-13 6:15 ` [PATCH v3 11/17] nfsd: reduce range of directory lock " NeilBrown
2026-07-13 6:15 ` [PATCH v3 12/17] nfsd: open-code nfsd4_vfs_create() into nfsd4_create_file() NeilBrown
2026-07-13 6:15 ` [PATCH v3 13/17] nfsd: move some code out of the d_really_is_negative() branch in nfsd4_create_file() NeilBrown
2026-07-13 6:15 ` [PATCH v3 14/17] nfsd: reduce want-write range " NeilBrown
2026-07-16 12:29 ` Jeff Layton [this message]
2026-07-13 6:15 ` [PATCH v3 15/17] nfsd: move v0 checking out of nfsd_check_obj_isreg() NeilBrown
2026-07-16 12:31 ` Jeff Layton
2026-07-13 6:15 ` [PATCH v3 16/17] nfsd: separate out VFS-specific code from nfsd4_create_file() NeilBrown
2026-07-13 6:15 ` [PATCH v3 17/17] nfsd: use do_lookup_open() for non-creating open requests too NeilBrown
2026-07-16 13:29 ` [PATCH v3 00/17] nfsd: refactor nfs4_create_file() Jeff Layton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b8af8636b7268933395dae83b6088c5d7b602435.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox