Skip to content

Commit 74fc55a

Browse files
neilbrownAnna Schumaker
authored andcommitted
nfs_localio: duplicate nfs_close_local_fh()
nfs_close_local_fh() is called from two different places for quite different use case. It is called from nfs_uuid_put() when the nfs_uuid is being detached - possibly because the nfs server is not longer serving that filesystem. In this case there will always be an nfs_uuid and so rcu_read_lock() is not needed. It is also called when the nfs_file_localio is no longer needed. In this case there may not be an active nfs_uuid. These two can race, and handling the race properly while avoiding excessive locking will require different handling on each side. This patch prepares the way by opencoding nfs_close_local_fh() into nfs_uuid_put(), then simplifying the code there as befits the context. Fixes: 86e0041 ("nfs: cache all open LOCALIO nfsd_file(s) in client") Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent e6f7e14 commit 74fc55a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

fs/nfs_common/nfslocalio.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,26 @@ static bool nfs_uuid_put(nfs_uuid_t *nfs_uuid)
171171

172172
/* Walk list of files and ensure their last references dropped */
173173
list_for_each_entry_safe(nfl, tmp, &local_files, list) {
174-
nfs_close_local_fh(nfl);
174+
struct nfsd_file *ro_nf;
175+
struct nfsd_file *rw_nf;
176+
177+
ro_nf = unrcu_pointer(xchg(&nfl->ro_file, NULL));
178+
rw_nf = unrcu_pointer(xchg(&nfl->rw_file, NULL));
179+
180+
spin_lock(&nfs_uuid->lock);
181+
/* Remove nfl from nfs_uuid->files list */
182+
list_del_init(&nfl->list);
183+
spin_unlock(&nfs_uuid->lock);
184+
/* Now we can allow racing nfs_close_local_fh() to
185+
* skip the locking.
186+
*/
187+
RCU_INIT_POINTER(nfl->nfs_uuid, NULL);
188+
189+
if (ro_nf)
190+
nfs_to_nfsd_file_put_local(ro_nf);
191+
if (rw_nf)
192+
nfs_to_nfsd_file_put_local(rw_nf);
193+
175194
cond_resched();
176195
}
177196

0 commit comments

Comments
 (0)