nfs_localio: always hold nfsd net ref with nfsd_file ref
authorNeilBrown <neil@brown.name>
Fri, 9 May 2025 00:46:39 +0000 (10:46 +1000)
committerAnna Schumaker <anna.schumaker@oracle.com>
Wed, 28 May 2025 21:17:14 +0000 (17:17 -0400)
commit77e82fb2c6c27c122e785f543ae0062f7783c886
treec68dcd4fba293036f3df28694059f59161b6045e
parented9be317330c7390df7db9e1d046698c02001bd2
nfs_localio: always hold nfsd net ref with nfsd_file ref

Having separate nfsd_file_put and nfsd_file_put_local in struct
nfsd_localio_operations doesn't make much sense.  The difference is that
nfsd_file_put doesn't drop a reference to the nfs_net which is what
keeps nfsd from shutting down.

Currently, if nfsd tries to shutdown it will invalidate the files stored
in the list from the nfs_uuid and this will drop all references to the
nfsd net that the client holds.  But the client could still hold some
references to nfsd_files for active IO.  So nfsd might think is has
completely shut down local IO, but hasn't and has no way to wait for
those active IO requests to complete.

So this patch changes nfsd_file_get to nfsd_file_get_local and has it
increase the ref count on the nfsd net and it replaces all calls to
->nfsd_put_file to ->nfsd_put_file_local.

It also changes ->nfsd_open_local_fh to return with the refcount on the
net elevated precisely when a valid nfsd_file is returned.

This means that whenever the client holds a valid nfsd_file, there will
be an associated count on the nfsd net, and so the count can only reach
zero when all nfsd_files have been returned.

nfs_local_file_put() is changed to call nfs_to_nfsd_file_put_local()
instead of replacing calls to one with calls to the other because this
will help a later patch which changes nfs_to_nfsd_file_put_local() to
take an __rcu pointer while nfs_local_file_put() doesn't.

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
fs/nfsd/filecache.c
fs/nfsd/filecache.h
fs/nfsd/localio.c
include/linux/nfslocalio.h