nfsd: fix race in nfsd_nrthreads()
authorNeil Brown <neilb@suse.de>
Thu, 12 Jun 2008 03:38:42 +0000 (13:38 +1000)
committerJ. Bruce Fields <bfields@citi.umich.edu>
Mon, 23 Jun 2008 17:02:50 +0000 (13:02 -0400)
We need the nfsd_mutex before accessing nfsd_serv->sv_nrthreads or we
can't even guarantee nfsd_serv will still be there.

Signed-off-by: Neil Brown <neilb@suse.de>
Acked-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
fs/nfsd/nfssvc.c

index 26c8114..96fdbca 100644 (file)
@@ -165,10 +165,12 @@ int nfsd_vers(int vers, enum vers_op change)
 
 int nfsd_nrthreads(void)
 {
-       if (nfsd_serv == NULL)
-               return 0;
-       else
-               return nfsd_serv->sv_nrthreads;
+       int rv = 0;
+       mutex_lock(&nfsd_mutex);
+       if (nfsd_serv)
+               rv = nfsd_serv->sv_nrthreads;
+       mutex_unlock(&nfsd_mutex);
+       return rv;
 }
 
 static void nfsd_last_thread(struct svc_serv *serv)