Skip to content

Commit 7f5c330

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: allow passing in array of thread counts via netlink
Now that nfsd_svc can handle an array of thread counts, fix up the netlink threads interface to construct one from the netlink call and pass it through so we can start a pooled server the same way we would start a normal one. Note that any unspecified values in the array are considered zeroes, so it's possible to shut down a pooled server by passing in a short array that has only zeros, or even an empty array. Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent b4d8f22 commit 7f5c330

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

fs/nfsd/nfsctl.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ int nfsd_nl_rpc_status_get_dumpit(struct sk_buff *skb,
16451645
*/
16461646
int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info)
16471647
{
1648-
int nthreads = 0, count = 0, nrpools, ret = -EOPNOTSUPP, rem;
1648+
int *nthreads, count = 0, nrpools, i, ret = -EOPNOTSUPP, rem;
16491649
struct net *net = genl_info_net(info);
16501650
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
16511651
const struct nlattr *attr;
@@ -1662,15 +1662,22 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info)
16621662

16631663
mutex_lock(&nfsd_mutex);
16641664

1665-
nrpools = nfsd_nrpools(net);
1666-
if (nrpools && count > nrpools)
1667-
count = nrpools;
1668-
1669-
/* XXX: make this handle non-global pool-modes */
1670-
if (count > 1)
1665+
nrpools = max(count, nfsd_nrpools(net));
1666+
nthreads = kcalloc(nrpools, sizeof(int), GFP_KERNEL);
1667+
if (!nthreads) {
1668+
ret = -ENOMEM;
16711669
goto out_unlock;
1670+
}
1671+
1672+
i = 0;
1673+
nlmsg_for_each_attr(attr, info->nlhdr, GENL_HDRLEN, rem) {
1674+
if (nla_type(attr) == NFSD_A_SERVER_THREADS) {
1675+
nthreads[i++] = nla_get_u32(attr);
1676+
if (i >= nrpools)
1677+
break;
1678+
}
1679+
}
16721680

1673-
nthreads = nla_get_u32(info->attrs[NFSD_A_SERVER_THREADS]);
16741681
if (info->attrs[NFSD_A_SERVER_GRACETIME] ||
16751682
info->attrs[NFSD_A_SERVER_LEASETIME] ||
16761683
info->attrs[NFSD_A_SERVER_SCOPE]) {
@@ -1704,12 +1711,13 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info)
17041711
scope = nla_data(attr);
17051712
}
17061713

1707-
ret = nfsd_svc(1, &nthreads, net, get_current_cred(), scope);
1708-
1714+
ret = nfsd_svc(nrpools, nthreads, net, get_current_cred(), scope);
1715+
if (ret > 0)
1716+
ret = 0;
17091717
out_unlock:
17101718
mutex_unlock(&nfsd_mutex);
1711-
1712-
return ret == nthreads ? 0 : ret;
1719+
kfree(nthreads);
1720+
return ret;
17131721
}
17141722

17151723
/**

fs/nfsd/nfssvc.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,18 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)
769769
&nn->nfsd_serv->sv_pools[i],
770770
nthreads[i]);
771771
if (err)
772-
break;
772+
goto out;
773773
}
774+
775+
/* Anything undefined in array is considered to be 0 */
776+
for (i = n; i < nn->nfsd_serv->sv_nrpools; ++i) {
777+
err = svc_set_num_threads(nn->nfsd_serv,
778+
&nn->nfsd_serv->sv_pools[i],
779+
0);
780+
if (err)
781+
goto out;
782+
}
783+
out:
774784
return err;
775785
}
776786

0 commit comments

Comments
 (0)