Subject: Re: [PATCH 3/3] nfsd: allow passing in array of thread counts via netlink

From: Simon Horman <[email-masked]>
Date: Wed, 5 Jun 2024 20:34:46 +0100

On Tue, Jun 04, 2024 at 05:07:56PM -0400, Jeff Layton wrote:
> 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 <[email-masked]>

...

> @@ -1690,15 +1691,22 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info)
>  
>  	mutex_lock(&nfsd_mutex);
>  
> -	nrpools = nfsd_nrpools(net);
> -	if (nrpools && count > nrpools)
> -		count = nrpools;
> -
> -	/* XXX: make this handle non-global pool-modes */
> -	if (count > 1)
> +	nrpools = max(count, nfsd_nrpools(net));
> +	nthreads = kcalloc(nrpools, sizeof(int), GFP_KERNEL);
> +	if (!nthreads) {
> +		ret = -ENOMEM;
>  		goto out_unlock;
> +	}
> +
> +	i = 0;
> +	nlmsg_for_each_attr(attr, info->nlhdr, GENL_HDRLEN, rem) {
> +		if (nla_type(attr) == NFSD_A_SERVER_THREADS) {
> +			total += nthreads[i++] = nla_get_u32(attr);

Hi Jeff,

A minor nit from my side.

Total is set by otherwise unused in this function.

Flagged by clang-18 W=1 allmodconfig builds.

> +			if (i >= count)
> +				break;
> +		}
> +	}
>  
> -	nthreads = nla_get_u32(info->attrs[NFSD_A_SERVER_THREADS]);
>  	if (info->attrs[NFSD_A_SERVER_GRACETIME] ||
>  	    info->attrs[NFSD_A_SERVER_LEASETIME] ||
>  	    info->attrs[NFSD_A_SERVER_SCOPE]) {

...