[PATCH v5 12/18] nfsd: reduce range of directory lock in nfsd4_create_file()
NeilBrown <[email protected]> Fri, 17 Jul 2026 19:28:00 +1000
| Newsgroups | gmane.linux.nfs |
|---|---|
| Message-ID | <[email protected]> |
From: NeilBrown <neil-+NVA1uvv1dVBDLzU/[email protected]> We only need to hold the lock taken by start_creating() until the create has been attempted. Holding for longer can serve no purpose. The lock is currently held across the setattr call. This might be the intent but it serves no purpose. Holding the lock prevents the name from being removed or renamed, but it doesn't prevent a GETATTR or a racing SETATTR or an OPEN. Calling end_creating() puts the reference to 'child', but we can still use the reference that was stored in open->op_filp. Signed-off-by: NeilBrown <neil-+NVA1uvv1dVBDLzU/[email protected]> --- fs/nfsd/nfs4proc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 0b3b358679f3..c04a021d9719 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -366,7 +366,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, if (d_really_is_positive(child)) { /* * open the file so that we consistently have a valid - * op_filp. + * op_filp and consequently a valid ->f_path.dentry. */ struct path path = {.mnt = fhp->fh_export->ex_path.mnt, .dentry = child, @@ -400,9 +400,12 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, if (status == nfs_ok) open->op_created = open->op_filp->f_mode & FMODE_CREATED; } + end_creating(child); if (status != nfs_ok) goto out; + child = open->op_filp->f_path.dentry; + status = fh_compose(resfhp, fhp->fh_export, child, fhp); if (status != nfs_ok) goto out; @@ -452,7 +455,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: - end_creating(child); if (!want_write_err) fh_drop_write(fhp); nfsd_attrs_free(&attrs); -- 2.50.0.107.gf914562f5916.dirty