nfs_localio: use cmpxchg() to install new nfs_file_localio
authorNeilBrown <neil@brown.name>
Fri, 9 May 2025 00:46:38 +0000 (10:46 +1000)
committerAnna Schumaker <anna.schumaker@oracle.com>
Wed, 28 May 2025 21:17:14 +0000 (17:17 -0400)
commited9be317330c7390df7db9e1d046698c02001bd2
tree547c2ed7eed5776c7f8f43ac74802a7327efc041
parent111f9e4b0dcdd493094dad98ecbed490887710c0
nfs_localio: use cmpxchg() to install new nfs_file_localio

Rather than using nfs_uuid.lock to protect installing
a new ro_file or rw_file, change to use cmpxchg().
Removing the file already uses xchg() so this improves symmetry
and also makes the code a little simpler.

Also remove the optimisation of not taking the lock, and not removing
the nfs_file_localio from the linked list, when both ->ro_file and
->rw_file are already NULL.  Given that ->nfs_uuid was not NULL, it is
extremely unlikely that neither ->ro_file or ->rw_file is NULL so
this optimisation can be of little value and it complicates
understanding of the code - why can the list_del_init() be skipped?

Finally, move the assignment of NULL to ->nfs_uuid until after
the last action on the nfs_file_localio (the list_del_init).  As soon as
this is NULL a racing nfs_close_local_fh() can bypass all the locking
and go on to free the nfs_file_localio, so we must be certain to be
finished with it first.

Fixes: 86e00412254a ("nfs: cache all open LOCALIO nfsd_file(s) in client")
Signed-off-by: NeilBrown <neil@brown.name>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
fs/nfs/localio.c
fs/nfs_common/nfslocalio.c