Skip to content

Commit 18e4cf9

Browse files
neilbrownchucklever
authored andcommitted
nfsd: Simplify code around svc_exit_thread() call in nfsd()
Previously a thread could exit asynchronously (due to a signal) so some care was needed to hold nfsd_mutex over the last svc_put() call. Now a thread can only exit when svc_set_num_threads() is called, and this is always called under nfsd_mutex. So no care is needed. Not only is the mutex held when a thread exits now, but the svc refcount is elevated, so the svc_put() in svc_exit_thread() will never be a final put, so the mutex isn't even needed at this point in the code. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 3903902 commit 18e4cf9

File tree

2 files changed

+0
-36
lines changed

2 files changed

+0
-36
lines changed

fs/nfsd/nfssvc.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -992,31 +992,8 @@ nfsd(void *vrqstp)
992992
atomic_dec(&nfsdstats.th_cnt);
993993

994994
out:
995-
/* Take an extra ref so that the svc_put in svc_exit_thread()
996-
* doesn't call svc_destroy()
997-
*/
998-
svc_get(nn->nfsd_serv);
999-
1000995
/* Release the thread */
1001996
svc_exit_thread(rqstp);
1002-
1003-
/* We need to drop a ref, but may not drop the last reference
1004-
* without holding nfsd_mutex, and we cannot wait for nfsd_mutex as that
1005-
* could deadlock with nfsd_shutdown_threads() waiting for us.
1006-
* So three options are:
1007-
* - drop a non-final reference,
1008-
* - get the mutex without waiting
1009-
* - sleep briefly andd try the above again
1010-
*/
1011-
while (!svc_put_not_last(nn->nfsd_serv)) {
1012-
if (mutex_trylock(&nfsd_mutex)) {
1013-
nfsd_put(net);
1014-
mutex_unlock(&nfsd_mutex);
1015-
break;
1016-
}
1017-
msleep(20);
1018-
}
1019-
1020997
return 0;
1021998
}
1022999

include/linux/sunrpc/svc.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,6 @@ static inline void svc_put(struct svc_serv *serv)
120120
kref_put(&serv->sv_refcnt, svc_destroy);
121121
}
122122

123-
/**
124-
* svc_put_not_last - decrement non-final reference count on SUNRPC serv
125-
* @serv: the svc_serv to have count decremented
126-
*
127-
* Returns: %true is refcount was decremented.
128-
*
129-
* If the refcount is 1, it is not decremented and instead failure is reported.
130-
*/
131-
static inline bool svc_put_not_last(struct svc_serv *serv)
132-
{
133-
return refcount_dec_not_one(&serv->sv_refcnt.refcount);
134-
}
135-
136123
/*
137124
* Maximum payload size supported by a kernel RPC server.
138125
* This is use to determine the max number of pages nfsd is

0 commit comments

Comments
 (0)