NFSD: Instantiate a struct file when creating a regular NFSv4 file
authorChuck Lever <chuck.lever@oracle.com>
Wed, 30 Mar 2022 14:30:54 +0000 (10:30 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 23 May 2022 15:06:29 +0000 (11:06 -0400)
commitfb70bf124b051d4ded4ce57511dfec6d3ebf2b43
treea4e26bdd2866d7671ba7b1a69ca758aba203cd88
parentf4d84c52643ae1d63a8e73e2585464470e7944d1
NFSD: Instantiate a struct file when creating a regular NFSv4 file

There have been reports of races that cause NFSv4 OPEN(CREATE) to
return an error even though the requested file was created. NFSv4
does not provide a status code for this case.

To mitigate some of these problems, reorganize the NFSv4
OPEN(CREATE) logic to allocate resources before the file is actually
created, and open the new file while the parent directory is still
locked.

Two new APIs are added:

+ Add an API that works like nfsd_file_acquire() but does not open
the underlying file. The OPEN(CREATE) path can use this API when it
already has an open file.

+ Add an API that is kin to dentry_open(). NFSD needs to create a
file and grab an open "struct file *" atomically. The
alloc_empty_file() has to be done before the inode create. If it
fails (for example, because the NFS server has exceeded its
max_files limit), we avoid creating the file and can still return
an error to the NFS client.

BugLink: https://bugzilla.linux-nfs.org/show_bug.cgi?id=382
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Tested-by: JianHong Yin <jiyin@redhat.com>
fs/nfsd/filecache.c
fs/nfsd/filecache.h
fs/nfsd/nfs4proc.c
fs/nfsd/nfs4state.c
fs/nfsd/xdr4.h
fs/open.c
include/linux/fs.h