Skip to content

Commit b4d8f22

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: make nfsd_svc take an array of thread counts
Now that the refcounting is fixed, rework nfsd_svc to use the same thread setup as the pool_threads interface. Have it take an array of thread counts instead of just a single value, and pass that from the netlink threads set interface. Since the new netlink interface doesn't have the same restriction as pool_threads, move the guard against shutting down all threads to write_pool_threads. Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 8e0c8d2 commit b4d8f22

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

fs/nfsd/nfsctl.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ static ssize_t write_threads(struct file *file, char *buf, size_t size)
406406
return -EINVAL;
407407
trace_nfsd_ctl_threads(net, newthreads);
408408
mutex_lock(&nfsd_mutex);
409-
rv = nfsd_svc(newthreads, net, file->f_cred, NULL);
409+
rv = nfsd_svc(1, &newthreads, net, file->f_cred, NULL);
410410
mutex_unlock(&nfsd_mutex);
411411
if (rv < 0)
412412
return rv;
@@ -481,6 +481,14 @@ static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
481481
goto out_free;
482482
trace_nfsd_ctl_pool_threads(net, i, nthreads[i]);
483483
}
484+
485+
/*
486+
* There must always be a thread in pool 0; the admin
487+
* can't shut down NFS completely using pool_threads.
488+
*/
489+
if (nthreads[0] == 0)
490+
nthreads[0] = 1;
491+
484492
rv = nfsd_set_nrthreads(i, nthreads, net);
485493
if (rv)
486494
goto out_free;
@@ -1696,7 +1704,7 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info)
16961704
scope = nla_data(attr);
16971705
}
16981706

1699-
ret = nfsd_svc(nthreads, net, get_current_cred(), scope);
1707+
ret = nfsd_svc(1, &nthreads, net, get_current_cred(), scope);
17001708

17011709
out_unlock:
17021710
mutex_unlock(&nfsd_mutex);

fs/nfsd/nfsd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ bool nfssvc_encode_voidres(struct svc_rqst *rqstp,
103103
/*
104104
* Function prototypes.
105105
*/
106-
int nfsd_svc(int nrservs, struct net *net, const struct cred *cred, const char *scope);
106+
int nfsd_svc(int n, int *nservers, struct net *net,
107+
const struct cred *cred, const char *scope);
107108
int nfsd_dispatch(struct svc_rqst *rqstp);
108109

109110
int nfsd_nrthreads(struct net *);

fs/nfsd/nfssvc.c

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -709,18 +709,38 @@ int nfsd_get_nrthreads(int n, int *nthreads, struct net *net)
709709
return 0;
710710
}
711711

712+
/**
713+
* nfsd_set_nrthreads - set the number of running threads in the net's service
714+
* @n: number of array members in @nthreads
715+
* @nthreads: array of thread counts for each pool
716+
* @net: network namespace to operate within
717+
*
718+
* This function alters the number of running threads for the given network
719+
* namespace in each pool. If passed an array longer then the number of pools
720+
* the extra pool settings are ignored. If passed an array shorter than the
721+
* number of pools, the missing values are interpreted as 0's.
722+
*
723+
* Returns 0 on success or a negative errno on error.
724+
*/
712725
int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)
713726
{
714727
int i = 0;
715728
int tot = 0;
716729
int err = 0;
717730
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
718731

719-
WARN_ON(!mutex_is_locked(&nfsd_mutex));
732+
lockdep_assert_held(&nfsd_mutex);
720733

721734
if (nn->nfsd_serv == NULL || n <= 0)
722735
return 0;
723736

737+
/*
738+
* Special case: When n == 1, pass in NULL for the pool, so that the
739+
* change is distributed equally among them.
740+
*/
741+
if (n == 1)
742+
return svc_set_num_threads(nn->nfsd_serv, NULL, nthreads[0]);
743+
724744
if (n > nn->nfsd_serv->sv_nrpools)
725745
n = nn->nfsd_serv->sv_nrpools;
726746

@@ -743,13 +763,6 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)
743763
}
744764
}
745765

746-
/*
747-
* There must always be a thread in pool 0; the admin
748-
* can't shut down NFS completely using pool_threads.
749-
*/
750-
if (nthreads[0] == 0)
751-
nthreads[0] = 1;
752-
753766
/* apply the new numbers */
754767
for (i = 0; i < n; i++) {
755768
err = svc_set_num_threads(nn->nfsd_serv,
@@ -761,13 +774,19 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)
761774
return err;
762775
}
763776

764-
/*
765-
* Adjust the number of threads and return the new number of threads.
766-
* This is also the function that starts the server if necessary, if
767-
* this is the first time nrservs is nonzero.
777+
/**
778+
* nfsd_svc: start up or shut down the nfsd server
779+
* @n: number of array members in @nthreads
780+
* @nthreads: array of thread counts for each pool
781+
* @net: network namespace to operate within
782+
* @cred: credentials to use for xprt creation
783+
* @scope: server scope value (defaults to nodename)
784+
*
785+
* Adjust the number of threads in each pool and return the new
786+
* total number of threads in the service.
768787
*/
769788
int
770-
nfsd_svc(int nrservs, struct net *net, const struct cred *cred, const char *scope)
789+
nfsd_svc(int n, int *nthreads, struct net *net, const struct cred *cred, const char *scope)
771790
{
772791
int error;
773792
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
@@ -777,13 +796,6 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred, const char *scop
777796

778797
dprintk("nfsd: creating service\n");
779798

780-
nrservs = max(nrservs, 0);
781-
nrservs = min(nrservs, NFSD_MAXSERVS);
782-
error = 0;
783-
784-
if (nrservs == 0 && nn->nfsd_serv == NULL)
785-
goto out;
786-
787799
strscpy(nn->nfsd_name, scope ? scope : utsname()->nodename,
788800
sizeof(nn->nfsd_name));
789801

@@ -795,7 +807,7 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred, const char *scop
795807
error = nfsd_startup_net(net, cred);
796808
if (error)
797809
goto out_put;
798-
error = svc_set_num_threads(serv, NULL, nrservs);
810+
error = nfsd_set_nrthreads(n, nthreads, net);
799811
if (error)
800812
goto out_put;
801813
error = serv->sv_nrthreads;

0 commit comments

Comments
 (0)