From patchwork Thu Jun 13 18:34:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13697297 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA81A14D420; Thu, 13 Jun 2024 18:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718303682; cv=none; b=Hmvk2PoopljImCwhU4SCeSN35kjjmbHp9+TO41BlQ4vbEsjgBmdp+FTULnWRLZ/Ocn40e0DMpj0qT3Xqx5ODdkBeAhEPorkzCCh/lqJfPFu8fXl4gWWUw4D5XrOA/Y2KbdPCKaW9Pq3QOQivWzAZnfFVpzJDfgugKoRqzlyhIRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718303682; c=relaxed/simple; bh=P0z7CPlefmV2nykZZ/K60TZR1AJ3MxzaUNXJ+hqBQ6M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gNQLfPEBcslpiDJmYGVOYfyH9ibhJm8n3X3LBmdUfE4Vv4+wYHF0CQoeCwKjNC8MzYUUY8y+jvaT/xYIXRx+TBy7EAhwTRvDq7bwAKBsOxJfJnpZsVjV/+fUBsutvHXUeUcmPrFw6icuDC2+24oSi9z3j4f5W9J4UW8y9hXikXM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PrfWbtnx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PrfWbtnx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38B7AC32786; Thu, 13 Jun 2024 18:34:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718303682; bh=P0z7CPlefmV2nykZZ/K60TZR1AJ3MxzaUNXJ+hqBQ6M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PrfWbtnxSLaOj/jShzfV/Zz8Er0gv11B1Wu2660ohd8gzPkLR1DlwFpvntr7fDqW6 zG5ukM6RxqlPJMf1Gl1zhUJ9Q+opfVYOgMvSx0ZKeNX/5FYXsOfaGsE7NKQvqColpt MwHTMqGzdbJfhIUreMvEgesASjJVbmN+sN6bVno8/z9Z7Cqf2xPchh2tOoTDAnS+Bt 19SsAxex+Kgjv/KbO0eKyA/e72Gmas5mShuthQn7e0OavN3zzubDHqSyA6n0PRZQNX xZ+ilhgtm4CjYCnFpvGth5zWRyC0WcRBpkVbQ9KvYDyE8mc0Wk5/PmAVkXOgigVZwt xwwZQjyj8WnHg== From: Jeff Layton Date: Thu, 13 Jun 2024 14:34:30 -0400 Subject: [PATCH v3 1/5] sunrpc: fix up the special handling of sv_nrpools == 1 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240613-nfsd-next-v3-1-3b51c3c2fc59@kernel.org> References: <20240613-nfsd-next-v3-0-3b51c3c2fc59@kernel.org> In-Reply-To: <20240613-nfsd-next-v3-0-3b51c3c2fc59@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lorenzo Bianconi Cc: Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4030; i=jlayton@kernel.org; h=from:subject:message-id; bh=P0z7CPlefmV2nykZZ/K60TZR1AJ3MxzaUNXJ+hqBQ6M=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmazu+tAFgD3CcatPdHqafaoo+CrTqYJ/+lmSBE f4mbUzukHiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZms7vgAKCRAADmhBGVaC FdUUEAC91/Mbies3cnsrpyhHq380clmNMWy+ebmriaiOiQdMwguLWI/SJCX1E9+flCl+vDl0odg R70l6M0PTsC68QYe9zhx3svjA+yUoQfv2ann2+sj2wkASKxsfBVCx4JE7QALOpdaU7YqyyrDpO2 nMkxblsauPl1xbGiyAMmaEnD9P+3lVwszF1fRl3fte6ZA6KxFdPrnzCiPG0Xoj8a4X/XAVPk4ja zZ7RsgApB+sZ1PKwSERvlFBxY00o1xQ+cxf2V40sxfC2JAlt3jnmqMXeApsOuEala779p3r6LhP 3DAsD7Gir9868aLKrgwv139lcdSb9xbjQXFl3V9oFPMQ1H2PB6WKy+8vyhMcuZ8zwRqNknMdeVb 0yqBgl2YeabjZC7CF6SSbEq3VflDBRbUuRfzajhjXKHdH5OwzmGtWpUCSLCAffj2JYedU1skDKa lKHTSJizQ8P75MveB3VI1hF9QO2LxNkIQXTZtwmDNg7cDHuwF5aIxazRN6i4JM0ouKQNI1fFuhQ XrCU74He6bUGh07vM73irKe3ShZQrC32OiL4X/pOfKSKCOaN+mrjTYixeJYqQZiXQMWgwW8fVnv seZvn6ZHI1bniszYpAqdkoikx5Ob/V4JZnD5xAKylp+8E3V8E1cw/WkhZwZYuGVHHjSE3lPcpd1 qaiXpnR6WwgFitQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Only pooled services take a reference to the svc_pool_map. The sunrpc code has always used the sv_nrpools value to detect whether the service is pooled. The problem there is that nfsd is a pooled service, but when it's running in "global" pool_mode, it doesn't take a reference to the pool map because it has a sv_nrpools value of 1. This means that we have two separate codepaths for starting the server, depending on whether it's pooled or not. Fix this by adding a new flag to the svc_serv, that indicates whether the serv is pooled. With this we can have the nfsd service unconditionally take a reference, regardless of pool_mode. Note that this is a behavior change for /sys/module/sunrpc/parameters/pool_mode. Usually this file does not allow you to change the pool-mode while there are nfsd threads running, but if the pool-mode is "global" it's allowed. My assumption is that this is a bug, since it probably should never have worked this way. This patch changes the behavior such that you get back EBUSY even when nfsd is running in global mode. I think this is more reasonable behavior, and given that most people set this today using the module parameter, it's doubtful anyone will notice. Signed-off-by: Jeff Layton --- include/linux/sunrpc/svc.h | 1 + net/sunrpc/svc.c | 26 +++++++------------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index 23617da0e565..d0433e1642b3 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h @@ -85,6 +85,7 @@ struct svc_serv { char * sv_name; /* service name */ unsigned int sv_nrpools; /* number of thread pools */ + bool sv_is_pooled; /* is this a pooled service? */ struct svc_pool * sv_pools; /* array of thread pools */ int (*sv_threadfn)(void *data); diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 2b4b1276d4e8..f80d94cbb8b1 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -250,10 +250,8 @@ svc_pool_map_get(void) int npools = -1; mutex_lock(&svc_pool_map_mutex); - if (m->count++) { mutex_unlock(&svc_pool_map_mutex); - WARN_ON_ONCE(m->npools <= 1); return m->npools; } @@ -275,32 +273,21 @@ svc_pool_map_get(void) m->mode = SVC_POOL_GLOBAL; } m->npools = npools; - - if (npools == 1) - /* service is unpooled, so doesn't hold a reference */ - m->count--; - mutex_unlock(&svc_pool_map_mutex); return npools; } /* - * Drop a reference to the global map of cpus to pools, if - * pools were in use, i.e. if npools > 1. + * Drop a reference to the global map of cpus to pools. * When the last reference is dropped, the map data is - * freed; this allows the sysadmin to change the pool - * mode using the pool_mode module option without - * rebooting or re-loading sunrpc.ko. + * freed; this allows the sysadmin to change the pool. */ static void -svc_pool_map_put(int npools) +svc_pool_map_put(void) { struct svc_pool_map *m = &svc_pool_map; - if (npools <= 1) - return; mutex_lock(&svc_pool_map_mutex); - if (!--m->count) { kfree(m->to_pool); m->to_pool = NULL; @@ -308,7 +295,6 @@ svc_pool_map_put(int npools) m->pool_to = NULL; m->npools = 0; } - mutex_unlock(&svc_pool_map_mutex); } @@ -553,9 +539,10 @@ struct svc_serv *svc_create_pooled(struct svc_program *prog, serv = __svc_create(prog, stats, bufsize, npools, threadfn); if (!serv) goto out_err; + serv->sv_is_pooled = true; return serv; out_err: - svc_pool_map_put(npools); + svc_pool_map_put(); return NULL; } EXPORT_SYMBOL_GPL(svc_create_pooled); @@ -585,7 +572,8 @@ svc_destroy(struct svc_serv **servp) cache_clean_deferred(serv); - svc_pool_map_put(serv->sv_nrpools); + if (serv->sv_is_pooled) + svc_pool_map_put(); for (i = 0; i < serv->sv_nrpools; i++) { struct svc_pool *pool = &serv->sv_pools[i]; From patchwork Thu Jun 13 18:34:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13697298 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C41A14F10C; Thu, 13 Jun 2024 18:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718303684; cv=none; b=A19mjH8hrXp6rNl2ATYMMJAru//ptubcRc3wTx5ERuzbalsIFAO69Zm/JjMIrXK7/0ujer7ug3MMBvZdrJgo8qQinS3SmQ0TRkCqN6BVI9BpCHI30cu8b/QUAQXNiagKQbgFziqNSq7PxbXEZee6dOe1ZMibvmMHUFOe3EsoATg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718303684; c=relaxed/simple; bh=dne48/WuerJI5cDYxx4gUTpls8+CI/TolliuHR/okWM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E/ce1CpUjB1K+gblnd5T37w5bbPGQ8mIz1jjGNLA/WrwVx+1kAnd+2NHJz5Y4NHyfGi2ps17P/2M/nnN9oaGsWKrN52SwtBklnz5nIMFuHp9I6ewxxHk4C0rYY01oznYip5I1uOXRpGRqw66OvIeG3OKMeD0ZYlmOhC7x12gMKs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m5jFvDJg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m5jFvDJg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBE42C2BBFC; Thu, 13 Jun 2024 18:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718303684; bh=dne48/WuerJI5cDYxx4gUTpls8+CI/TolliuHR/okWM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m5jFvDJg4ITfm6OlfyZL6K/YPjxAwqmONtVbz/QTXsIO/yEAK3OdvbrUQXWbNEcz0 G0GtEs92Do0lge4ZjEGxMsYB0e5qRZNvhn152feVreJH0hW+nO1y4YbtFH7xlW499t 8/DAXVtf0yoZfkl5tpAuiUWlIyZYjTm5dL6NIMO2gqEivkItszcDd7sLfObdKDY9xD BCbFYQPk677YUpDTmZpXvP+2MvUBcZ6BR/7ZvUuT8zLTFcttsnN+3SFO1xGebEFEjx Rf8iuzeauknQOh5CLh/+RQPZB+TisI/LpCcocohj6NSVfp/TrdrHYrRFFYaSu+KZvW UccR24746swcg== From: Jeff Layton Date: Thu, 13 Jun 2024 14:34:31 -0400 Subject: [PATCH v3 2/5] nfsd: make nfsd_svc take an array of thread counts Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240613-nfsd-next-v3-2-3b51c3c2fc59@kernel.org> References: <20240613-nfsd-next-v3-0-3b51c3c2fc59@kernel.org> In-Reply-To: <20240613-nfsd-next-v3-0-3b51c3c2fc59@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lorenzo Bianconi Cc: Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5775; i=jlayton@kernel.org; h=from:subject:message-id; bh=dne48/WuerJI5cDYxx4gUTpls8+CI/TolliuHR/okWM=; b=kA0DAAgBAA5oQRlWghUByyZiAGZrO7+iKmCHhCe4pRptwsD6IdAndP4Llz62DqD10ToMQcSsG IkCMwQAAQgAHRYhBEvA17JEcbKhhOr10wAOaEEZVoIVBQJmazu/AAoJEAAOaEEZVoIV/5sQAKpX xHN5rsuERKUtlC9prSnDu2qMSixqkjskquUtCnoRUY8GOcrWENJbl7LviBi2PPE1hyFfH/ENUrM vuvicTl4WYrrzlBwPU3WiprOcABDXnAzULC7M57Hy8EXvZXmjKODEE4fd9n1j44qRMO9MD9IiZZ Urhet9TXfsmma04W5vAs6A04cuqyuKrbHT3WbYVi7UsmfnglGEcWsRAxtWLLB9dFoYls6DD4eGg ncFNnAGnPVRA25Je58xDfJlQXLn0x/DKLUX43x8xDGPVYVkyM7Z8GyBHvNaEqk0X37TNMPkyIVS E//Tmoznlr34b21Fx6Oi4TUX2VsM0JeITWdwvurwfEjahebQvmqBOgHLrVuE/KZX4l5Rf7Z2for fmRQ3NvVMn+5sGTKjhwiWv7b1bLC9E0KC5SET1dGYgvuh7G5BXco1ApsY35Ncr/849JoygxfWIb oJ+jJnsEwvq/+Z6lhgSfCKvRQyMucf68wit7tLySQZT9ZGWR6gTm1SaA7ELU36nkS9HJFJp7I6f uaTSumMMJtcTWTIoyu86h4OAOWojzA4+24Z0RnXfhBmwUFGE1fs/LG4/7SDHfi0alIcO7rMAlEO 00bwZUz0ZoYbCa7H8JAUtv5uQ+uKdN8B8vd7NlonYdpw1Ryw3VSzLK/zyp545LhmHgLCU0f0Izz 97XdW X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 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 --- fs/nfsd/nfsctl.c | 12 ++++++++++-- fs/nfsd/nfsd.h | 3 ++- fs/nfsd/nfssvc.c | 47 ++++++++++++++++++++++++++--------------------- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 202140df8f82..c0d84a6e5416 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -406,7 +406,7 @@ static ssize_t write_threads(struct file *file, char *buf, size_t size) return -EINVAL; trace_nfsd_ctl_threads(net, newthreads); mutex_lock(&nfsd_mutex); - rv = nfsd_svc(newthreads, net, file->f_cred, NULL); + rv = nfsd_svc(1, &newthreads, net, file->f_cred, NULL); mutex_unlock(&nfsd_mutex); if (rv < 0) return rv; @@ -481,6 +481,14 @@ static ssize_t write_pool_threads(struct file *file, char *buf, size_t size) goto out_free; trace_nfsd_ctl_pool_threads(net, i, nthreads[i]); } + + /* + * There must always be a thread in pool 0; the admin + * can't shut down NFS completely using pool_threads. + */ + if (nthreads[0] == 0) + nthreads[0] = 1; + rv = nfsd_set_nrthreads(i, nthreads, net); if (rv) goto out_free; @@ -1722,7 +1730,7 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info) scope = nla_data(attr); } - ret = nfsd_svc(nthreads, net, get_current_cred(), scope); + ret = nfsd_svc(1, &nthreads, net, get_current_cred(), scope); out_unlock: mutex_unlock(&nfsd_mutex); diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h index 8f4f239d9f8a..cec8697b1cd6 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -103,7 +103,8 @@ bool nfssvc_encode_voidres(struct svc_rqst *rqstp, /* * Function prototypes. */ -int nfsd_svc(int nrservs, struct net *net, const struct cred *cred, const char *scope); +int nfsd_svc(int n, int *nservers, struct net *net, + const struct cred *cred, const char *scope); int nfsd_dispatch(struct svc_rqst *rqstp); int nfsd_nrthreads(struct net *); diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index cd9a6a1a9fc8..2e47fd26c9b4 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -710,6 +710,19 @@ int nfsd_get_nrthreads(int n, int *nthreads, struct net *net) return 0; } +/** + * nfsd_set_nrthreads - set the number of running threads in the net's service + * @n: number of array members in @nthreads + * @nthreads: array of thread counts for each pool + * @net: network namespace to operate within + * + * This function alters the number of running threads for the given network + * namespace in each pool. If passed an array longer then the number of pools + * the extra pool settings are ignored. If passed an array shorter than the + * number of pools, the missing values are interpreted as 0's. + * + * Returns 0 on success or a negative errno on error. + */ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net) { int i = 0; @@ -717,7 +730,7 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net) int err = 0; struct nfsd_net *nn = net_generic(net, nfsd_net_id); - WARN_ON(!mutex_is_locked(&nfsd_mutex)); + lockdep_assert_held(&nfsd_mutex); if (nn->nfsd_serv == NULL || n <= 0) return 0; @@ -744,13 +757,6 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net) } } - /* - * There must always be a thread in pool 0; the admin - * can't shut down NFS completely using pool_threads. - */ - if (nthreads[0] == 0) - nthreads[0] = 1; - /* apply the new numbers */ for (i = 0; i < n; i++) { err = svc_set_num_threads(nn->nfsd_serv, @@ -762,13 +768,19 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net) return err; } -/* - * Adjust the number of threads and return the new number of threads. - * This is also the function that starts the server if necessary, if - * this is the first time nrservs is nonzero. +/** + * nfsd_svc: start up or shut down the nfsd server + * @n: number of array members in @nthreads + * @nthreads: array of thread counts for each pool + * @net: network namespace to operate within + * @cred: credentials to use for xprt creation + * @scope: server scope value (defaults to nodename) + * + * Adjust the number of threads in each pool and return the new + * total number of threads in the service. */ int -nfsd_svc(int nrservs, struct net *net, const struct cred *cred, const char *scope) +nfsd_svc(int n, int *nthreads, struct net *net, const struct cred *cred, const char *scope) { int error; struct nfsd_net *nn = net_generic(net, nfsd_net_id); @@ -778,13 +790,6 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred, const char *scop dprintk("nfsd: creating service\n"); - nrservs = max(nrservs, 0); - nrservs = min(nrservs, NFSD_MAXSERVS); - error = 0; - - if (nrservs == 0 && nn->nfsd_serv == NULL) - goto out; - strscpy(nn->nfsd_name, scope ? scope : utsname()->nodename, sizeof(nn->nfsd_name)); @@ -796,7 +801,7 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred, const char *scop error = nfsd_startup_net(net, cred); if (error) goto out_put; - error = svc_set_num_threads(serv, NULL, nrservs); + error = nfsd_set_nrthreads(n, nthreads, net); if (error) goto out_put; error = serv->sv_nrthreads; From patchwork Thu Jun 13 18:34:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13697299 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03D8015534F; Thu, 13 Jun 2024 18:34:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718303686; cv=none; b=fl8lNegfFZDzK36EHnVTmqDWntBqQVPqDoe/6SbMWD7Y8rEXHb6si/3hpoYT+xnY402gjTNtdpnWjXTVYP3AZn6SYGIBd7TbXDANXFlmk7e0z94AtHl/5GNHugb1LXEOf9v2WqXAnrfdYvaRe1BlDsSGw+oGZR3P9UynVYGM7Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718303686; c=relaxed/simple; bh=YDURFbnijazgcN8VD4DI4iq+yEb5LyI+bfN3po4d1eE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tawwfGlNrA/MU1tBnjFxffUuMDBpzU93Cr9KCiKPsJ4Nq/u19HFadFMLdFNQ6FSAzw5vI9fExtDqJsotOb5H3IBCPGZ4hezL0VMFMyO+sIoZN8tvEcdCPAohJzbM30Q3mJMd2p5Bx5tLL54Zp5qWeu3iyhkmJ7wmWiMGo90C2DY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EtL/XjB2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EtL/XjB2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B1B1C4AF1C; Thu, 13 Jun 2024 18:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718303685; bh=YDURFbnijazgcN8VD4DI4iq+yEb5LyI+bfN3po4d1eE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EtL/XjB2M/cKBZbVDuDraemb7CL8vJfRqmoJAmE8pstG2+6pACZaPzHVU5jpLwJzw 7Wpc5LjBHJ5TE1aRToVHnEhdbMTKJ4GJ7GRZoIf7s2F+IPtFUst45guIWqdv4oC0ki TKx+ZJrBM15H9CzBqSh7H87OhkbtBlBW3Sa1fomvWjvcBAnKA/hPzZv606dEye+T8f 8Glc38zq9DVLteyHyMdnnXLBalc+5HLuC4j5wX0xVzsr64PfT5TNtWCIpv9qYGRCZT 34Y3TXw+MIdwkErUkFP/Rml2kJN+CgYYCuxUvUHiLH9ANamnV19t1hU0ui2hpnGeFH QmxglpV1mbmTQ== From: Jeff Layton Date: Thu, 13 Jun 2024 14:34:32 -0400 Subject: [PATCH v3 3/5] nfsd: allow passing in array of thread counts via netlink Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240613-nfsd-next-v3-3-3b51c3c2fc59@kernel.org> References: <20240613-nfsd-next-v3-0-3b51c3c2fc59@kernel.org> In-Reply-To: <20240613-nfsd-next-v3-0-3b51c3c2fc59@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lorenzo Bianconi Cc: Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3124; i=jlayton@kernel.org; h=from:subject:message-id; bh=YDURFbnijazgcN8VD4DI4iq+yEb5LyI+bfN3po4d1eE=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmazu/0gFtlyoRt8a0xgZFOVewMJyPR1pCaPpBK VLuEIq4Jd2JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZms7vwAKCRAADmhBGVaC FYQwEAC68zu5Hf7AlKKPLWD6Ey5g198JeeKVFRnVu5NhRzlkU7NH6NUICRE6pkBtTq9ReHy4JoO 4HXtgux11rYseX3xtaFpNR43zUof2DhlzEO8yj1f8W4+fZjWk0ggJaizFl5Wud+byYUikhpEyRl T8DNvGtxr6T8xIB+xe8aQrQJK+jmdV/z2kOFMBZI8ZT9eIhRjap9DEd+z9hZ1s9dP4Uo1xcASbV cqTITAviXwWpoNeCoVH29qBVFk5M3a5id9pFOjuG12c4U5OPs6jSa8Wh1Y3Jez9kEvnmEj2TJBA /iks/T011QYCtvXZhflZTWo81y3OthIzJUbxV7YGryyWZ5AyKCAbGLHbPW9seaVb7fcImbxObZ+ nq5AQguYhWIyP4n6qJYIOgh2YmfvJ7CwmXrXiuoF9HzNwpguoYFRV9lwd4wNV1ey6d0V7cgRvLx oRw7UKOLSNMKXGzwZWEb4NBRHkw8TEqQ2dPS20rPMIgyy60bOc+xTpHg3BXbxdIDdIdpjXpgkE5 ji2YKeF+hdGKjCJ6vY1/FVChXiW3Awr2yxcYZ9MnXSJcniVkrnkYcHqyZQtuMiBMVwMhpzjr4GU iD3CKnGhEiUUOkbGQMSQWhAHl1qp5UbqhFfa4WR4DphJzX5vdrtGNPp6o2CfOR5gHfxj4q+jSjA goVa0lir2woZq9A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 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 --- fs/nfsd/nfsctl.c | 32 ++++++++++++++++++++------------ fs/nfsd/nfssvc.c | 12 +++++++++++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index c0d84a6e5416..dde42aad5582 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -1671,7 +1671,7 @@ int nfsd_nl_rpc_status_get_done(struct netlink_callback *cb) */ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info) { - int nthreads = 0, count = 0, nrpools, ret = -EOPNOTSUPP, rem; + int *nthreads, count = 0, nrpools, i, ret = -EOPNOTSUPP, rem; struct net *net = genl_info_net(info); struct nfsd_net *nn = net_generic(net, nfsd_net_id); const struct nlattr *attr; @@ -1688,15 +1688,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) { + nthreads[i++] = nla_get_u32(attr); + if (i >= nrpools) + 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]) { @@ -1730,12 +1737,13 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info) scope = nla_data(attr); } - ret = nfsd_svc(1, &nthreads, net, get_current_cred(), scope); - + ret = nfsd_svc(nrpools, nthreads, net, get_current_cred(), scope); + if (ret > 0) + ret = 0; out_unlock: mutex_unlock(&nfsd_mutex); - - return ret == nthreads ? 0 : ret; + kfree(nthreads); + return ret; } /** diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index 2e47fd26c9b4..9edb4f7c4cc2 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -763,8 +763,18 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net) &nn->nfsd_serv->sv_pools[i], nthreads[i]); if (err) - break; + goto out; } + + /* Anything undefined in array is considered to be 0 */ + for (i = n; i < nn->nfsd_serv->sv_nrpools; ++i) { + err = svc_set_num_threads(nn->nfsd_serv, + &nn->nfsd_serv->sv_pools[i], + 0); + if (err) + goto out; + } +out: return err; } From patchwork Thu Jun 13 18:34:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13697300 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A1CC156257; Thu, 13 Jun 2024 18:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718303687; cv=none; b=QBSCXyg1bod6I5g+hdYDh3LKjzp5+XxqmRHLmbjN6vPVYOp7OuXD3p2xzwWh63bJ4vke8yNx33x3XcAzba43QmZ+ECYdfLYKknrTNcQsawfR4qa4RAzhITd6iYVH1O7rUrnI2iY1JkAIhI0EG3ING2DCvF52Y/wFS6G5lPl0ENQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718303687; c=relaxed/simple; bh=5pnQH8utNOC4XYM7FgM/OzSZhJOaeE1L632BBMj8Y9Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BkAC0pNMLLPaXwIKzfCzEUa+AXfdXZa+w5F67EnI+vx4H2nks8HGT7UaBWHH0A4UBFwwNPZP0NNTwM2aHz6K3BoYvVxPCm13cUa1b8ehvgcr/Y+6iVC6aZRb4Cm2xPJQ0uOBxLHQlaagJR1oKiDgG2sDaQA30rT/6clmvNV7hsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eBOa39lV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eBOa39lV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF76FC32789; Thu, 13 Jun 2024 18:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718303687; bh=5pnQH8utNOC4XYM7FgM/OzSZhJOaeE1L632BBMj8Y9Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eBOa39lVdgUa1cQ7sZ+ROgH7j7VE+zuCEXWegFvkOMnIXutOQlVvAv6jFXy/2OKcs HBubddH8RZi+Ftww0EtGDAGulx+EwHY6WErxxzYcRi7WkV3eUO1M/pkEom6x4SbghL ZiF/S+Iyn8Dw/TKFMWaOF/ehQczpuvVsnsjzgOYOjdPChUGXHvhQELWF2XLIW79DaP Sa7gAAdkyeNm41OG3vTY14wxhjDBnH4p/7jNKck/cwqsN6CGRoxwywvKjAXHBbRLiN 94fchKHfoXuL0GLuh98SzasKhXmLfkiH23fK/yy6Mpaksc1xJIbu0tQvjBBYF5j4Bt uWX16Sd16XuGQ== From: Jeff Layton Date: Thu, 13 Jun 2024 14:34:33 -0400 Subject: [PATCH v3 4/5] sunrpc: refactor pool_mode setting code Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240613-nfsd-next-v3-4-3b51c3c2fc59@kernel.org> References: <20240613-nfsd-next-v3-0-3b51c3c2fc59@kernel.org> In-Reply-To: <20240613-nfsd-next-v3-0-3b51c3c2fc59@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lorenzo Bianconi Cc: Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4325; i=jlayton@kernel.org; h=from:subject:message-id; bh=5pnQH8utNOC4XYM7FgM/OzSZhJOaeE1L632BBMj8Y9Y=; b=kA0DAAgBAA5oQRlWghUByyZiAGZrO7+iP03g8DDP7hiyAZXpIdDiLq6l1pv4z2DknHbV+ANk4 4kCMwQAAQgAHRYhBEvA17JEcbKhhOr10wAOaEEZVoIVBQJmazu/AAoJEAAOaEEZVoIVjKcP/0xj ewFA+3+/wAwzj7GPhOAaeoOgoGDuAE8eqZjCqFU8ty8JfMhHY5Z28tAuEycUUqa+lZPD5F1rvWs LuGdg41b9+RNU3v7BKGTPAKVOvMh2d+D6rU3ebSzztEgTT7HEpel+2LkKektZphau4zihsEkZ8b 4gXFmnWHeCJQ76rs7Le/QeXGVEdZr5hjcHRa1rMe86VQ/2W9PmuVJyqsc4Raqwk6jaLG7r3IKMy BgmemVZlkdxNTp1bsfiNV1eziem6nBZbHFs8ha8LT4IWmfVgTQECIMqlF10cfPDc/V87OHrAymK 1ypWh/TKPmLiN8Y2k2dw6tOzUMozC9sm5snVSxA0L1STr2l4NWSv06vy6sIEDoYgmhrLmFWeSJ6 Ck7RamGdB9t5zmJdMsffuL+VcCIY13UaYw9NGuOU+NDx7vERNlgImI6GOOkPqeGWKESjABDzZJN GLSpfO62CZgZDeF+7X691FH4+r/Zar2eoZGBcriBuUM+kLO2SZ3aabKco36ZOF/MqKyu4knztkK WdbTFwNoX3UugK9DS/EInSue0ufE2/J/b/xjrPWUzXJXmx23fWLj4UdvgKkvk5sWT0gp+BJuReh 2uNln7DlJGAzTxDUaeZbQt4zMyfKYNAGiTiEwlc7CIhjkHGLrj00IVVYc3UF2eQ3ibyXjzKIydq h9p2Q X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Allow the pool_mode setting code to be called from internal callers so we can call it from a new netlink op. Add a new svc_pool_map_get function to return the current setting. Change the existing module parameter handling to use the new interfaces under the hood. Signed-off-by: Jeff Layton --- include/linux/sunrpc/svc.h | 2 ++ net/sunrpc/svc.c | 85 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 66 insertions(+), 21 deletions(-) diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index d0433e1642b3..a7d0406b9ef5 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h @@ -399,6 +399,8 @@ struct svc_procedure { /* * Function prototypes. */ +int sunrpc_set_pool_mode(const char *val); +int sunrpc_get_pool_mode(char *val, size_t size); int svc_rpcb_setup(struct svc_serv *serv, struct net *net); void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net); int svc_bind(struct svc_serv *serv, struct net *net); diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index f80d94cbb8b1..965a27806bfd 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -72,57 +72,100 @@ static struct svc_pool_map svc_pool_map = { static DEFINE_MUTEX(svc_pool_map_mutex);/* protects svc_pool_map.count only */ static int -param_set_pool_mode(const char *val, const struct kernel_param *kp) +__param_set_pool_mode(const char *val, struct svc_pool_map *m) { - int *ip = (int *)kp->arg; - struct svc_pool_map *m = &svc_pool_map; - int err; + int err, mode; mutex_lock(&svc_pool_map_mutex); - err = -EBUSY; - if (m->count) - goto out; - err = 0; if (!strncmp(val, "auto", 4)) - *ip = SVC_POOL_AUTO; + mode = SVC_POOL_AUTO; else if (!strncmp(val, "global", 6)) - *ip = SVC_POOL_GLOBAL; + mode = SVC_POOL_GLOBAL; else if (!strncmp(val, "percpu", 6)) - *ip = SVC_POOL_PERCPU; + mode = SVC_POOL_PERCPU; else if (!strncmp(val, "pernode", 7)) - *ip = SVC_POOL_PERNODE; + mode = SVC_POOL_PERNODE; else err = -EINVAL; + if (err) + goto out; + + if (m->count == 0) + m->mode = mode; + else if (mode != m->mode) + err = -EBUSY; out: mutex_unlock(&svc_pool_map_mutex); return err; } static int -param_get_pool_mode(char *buf, const struct kernel_param *kp) +param_set_pool_mode(const char *val, const struct kernel_param *kp) +{ + struct svc_pool_map *m = kp->arg; + + return __param_set_pool_mode(val, m); +} + +int sunrpc_set_pool_mode(const char *val) +{ + return __param_set_pool_mode(val, &svc_pool_map); +} +EXPORT_SYMBOL(sunrpc_set_pool_mode); + +/** + * sunrpc_get_pool_mode - get the current pool_mode for the host + * @buf: where to write the current pool_mode + * @size: size of @buf + * + * Grab the current pool_mode from the svc_pool_map and write + * the resulting string to @buf. Returns the number of characters + * written to @buf (a'la snprintf()). + */ +int +sunrpc_get_pool_mode(char *buf, size_t size) { - int *ip = (int *)kp->arg; + struct svc_pool_map *m = &svc_pool_map; - switch (*ip) + switch (m->mode) { case SVC_POOL_AUTO: - return sysfs_emit(buf, "auto\n"); + return snprintf(buf, size, "auto"); case SVC_POOL_GLOBAL: - return sysfs_emit(buf, "global\n"); + return snprintf(buf, size, "global"); case SVC_POOL_PERCPU: - return sysfs_emit(buf, "percpu\n"); + return snprintf(buf, size, "percpu"); case SVC_POOL_PERNODE: - return sysfs_emit(buf, "pernode\n"); + return snprintf(buf, size, "pernode"); default: - return sysfs_emit(buf, "%d\n", *ip); + return snprintf(buf, size, "%d", m->mode); } } +EXPORT_SYMBOL(sunrpc_get_pool_mode); + +static int +param_get_pool_mode(char *buf, const struct kernel_param *kp) +{ + char str[16]; + int len; + + len = sunrpc_get_pool_mode(str, ARRAY_SIZE(str)); + + /* Ensure we have room for newline and NUL */ + len = min_t(int, len, ARRAY_SIZE(str) - 2); + + /* tack on the newline */ + str[len] = '\n'; + str[len + 1] = '\0'; + + return sysfs_emit(buf, str); +} module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode, - &svc_pool_map.mode, 0644); + &svc_pool_map, 0644); /* * Detect best pool mapping mode heuristically, From patchwork Thu Jun 13 18:34:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13697301 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21C5B157A67; Thu, 13 Jun 2024 18:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718303689; cv=none; b=tSgEHs7jWnoLcoqy6lbSsHt/Dy62vvCLTl3PhOGga82bMFYR7xpofMNbYLTUGppKaOFeIPSmAvYligBnzjg1LXyv3NddUVwEDce1X1godHZdB2jJLfSm4jTrjhXl/96NFljybCnDvhGEi2xsVKgv+4qVyiKGK76pqGts9jaOEvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718303689; c=relaxed/simple; bh=oX0aSIaCfteVOGpAmr3SzPKXQ5QA4Z30qQIYP9WNXxc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bi/euwN1CdSgBaoz70o83o2fx5zruw7UKAZcFer8tfkqO8KWFJXeUzUenNEhl2EgMN8dWRmxe3sxJWYY7DNcYoYl/RPbkCkeev4JyCRdT4RQUWX2FCH7Zf3s3pvlzoUu5KoKfMYsxMSfYsGB4TmUOxtQdPQ+ezJ9C5lNZD2AygM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uTVcaRah; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uTVcaRah" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DB0EC32786; Thu, 13 Jun 2024 18:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718303688; bh=oX0aSIaCfteVOGpAmr3SzPKXQ5QA4Z30qQIYP9WNXxc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uTVcaRahEg2tE9VBEHrzfwpmILUjcrDidXqhkiJkGfCCnyxFPbGdRo/s7Jp+31dCw Wv5K691gHOhrWTv9VGJBuqIXgU324AqTndTtg/DNoPIIjAWKvXh7Gb6cif1JPDew+y I5x8yzfNaH8hpdb/kBHJjIJYwQcXWoU+UtxbftFFSbAfRChbly4apvnXn9nNiLv7om noFEIT5Z54pTtthRB6kFXODiDFh5xQH4agM+1Fh792WlbjU/+ittFzT91+6AvyMofX vh4cK69SSGQaHLHP6CoMV4aAsptxpcEhhjsTI0Zt1+ww/opE/STQFYkwLpLY9Yeizi xmt8TBheSABVA== From: Jeff Layton Date: Thu, 13 Jun 2024 14:34:34 -0400 Subject: [PATCH v3 5/5] nfsd: new netlink ops to get/set server pool_mode Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240613-nfsd-next-v3-5-3b51c3c2fc59@kernel.org> References: <20240613-nfsd-next-v3-0-3b51c3c2fc59@kernel.org> In-Reply-To: <20240613-nfsd-next-v3-0-3b51c3c2fc59@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lorenzo Bianconi Cc: Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5880; i=jlayton@kernel.org; h=from:subject:message-id; bh=oX0aSIaCfteVOGpAmr3SzPKXQ5QA4Z30qQIYP9WNXxc=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmazu/MC2tOxfyvdCSWTHgtLgWwt3ZXJAKwPWiu fh/wg6t3qqJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZms7vwAKCRAADmhBGVaC FSrTEACH81IKDS1zk4sOr9sRw+nvBJg55vz8c/7lQ71MBOLBWhU3zIfM/Ih9OQvV3u+HhtOxg/u gx5i8DhbD8Gz6PEWCvOM7SGpMcHEtxCEZXdsocD1RxryA1BkbCvWiYZEIfMvmDtB2suS28NCEfA WHPLwNiB7zRTuJdlAED4RCHvwMCOJEUzrVjS5g/JWhjsjaVHaiPTc8yAbGalM877viqWsn6/lH8 SX1YuDBMo+Xm7MTrf+T3l0Sb1X0ra2408pVaS4LWNiGXZAVhCIsa6jPkHG7VXq83+Y0MMLINN/y 9TrP6nbNymqS9tI7SvypJUBOea6AoG1cOesKr8Lr+zJi/92vecm+W/cIbTYDcMfN046cKI3mVqO bpp7cfs/Tl9tRaUcK3BtNtOlv2pGM6FMYn7TjtSmtDuziLu5VC7MwlCbC3/3iFI+Srye7wgfrG0 JdHQrpWMFqLX/w0KIWzYgIMZXf7nV68rPWwDSSdijuKecmwVkgdryYWpPgKMnplS6QoQsIIy7vj ra8KUuWE+y3AO/czKwFWDh+obuejsQCQjAVEml/tRhwUae9P01lZcfx9JZ16OFDOLiT8jO6tURI EjOP5knWdcSVi13+oVCDU9Laa7z+6pD2tC8bHXBeB3AiPFPvtQu5/w710/flfQAPpAFr10Tekww VVfP6AvUpWzoMRQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Signed-off-by: Jeff Layton --- Documentation/netlink/specs/nfsd.yaml | 27 ++++++++++++++++ fs/nfsd/netlink.c | 17 ++++++++++ fs/nfsd/netlink.h | 2 ++ fs/nfsd/nfsctl.c | 58 +++++++++++++++++++++++++++++++++++ include/uapi/linux/nfsd_netlink.h | 10 ++++++ 5 files changed, 114 insertions(+) diff --git a/Documentation/netlink/specs/nfsd.yaml b/Documentation/netlink/specs/nfsd.yaml index d21234097167..5a98e5a06c68 100644 --- a/Documentation/netlink/specs/nfsd.yaml +++ b/Documentation/netlink/specs/nfsd.yaml @@ -115,6 +115,15 @@ attribute-sets: type: nest nested-attributes: sock multi-attr: true + - + name: pool-mode + attributes: + - + name: mode + type: string + - + name: npools + type: u32 operations: list: @@ -197,3 +206,21 @@ operations: reply: attributes: - addr + - + name: pool-mode-set + doc: set the current server pool-mode + attribute-set: pool-mode + flags: [ admin-perm ] + do: + request: + attributes: + - mode + - + name: pool-mode-get + doc: get info about server pool-mode + attribute-set: pool-mode + do: + reply: + attributes: + - mode + - npools diff --git a/fs/nfsd/netlink.c b/fs/nfsd/netlink.c index 62d2586d9902..137701153c9e 100644 --- a/fs/nfsd/netlink.c +++ b/fs/nfsd/netlink.c @@ -40,6 +40,11 @@ static const struct nla_policy nfsd_listener_set_nl_policy[NFSD_A_SERVER_SOCK_AD [NFSD_A_SERVER_SOCK_ADDR] = NLA_POLICY_NESTED(nfsd_sock_nl_policy), }; +/* NFSD_CMD_POOL_MODE_SET - do */ +static const struct nla_policy nfsd_pool_mode_set_nl_policy[NFSD_A_POOL_MODE_MODE + 1] = { + [NFSD_A_POOL_MODE_MODE] = { .type = NLA_NUL_STRING, }, +}; + /* Ops table for nfsd */ static const struct genl_split_ops nfsd_nl_ops[] = { { @@ -85,6 +90,18 @@ static const struct genl_split_ops nfsd_nl_ops[] = { .doit = nfsd_nl_listener_get_doit, .flags = GENL_CMD_CAP_DO, }, + { + .cmd = NFSD_CMD_POOL_MODE_SET, + .doit = nfsd_nl_pool_mode_set_doit, + .policy = nfsd_pool_mode_set_nl_policy, + .maxattr = NFSD_A_POOL_MODE_MODE, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd = NFSD_CMD_POOL_MODE_GET, + .doit = nfsd_nl_pool_mode_get_doit, + .flags = GENL_CMD_CAP_DO, + }, }; struct genl_family nfsd_nl_family __ro_after_init = { diff --git a/fs/nfsd/netlink.h b/fs/nfsd/netlink.h index e3724637d64d..9459547de04e 100644 --- a/fs/nfsd/netlink.h +++ b/fs/nfsd/netlink.h @@ -26,6 +26,8 @@ int nfsd_nl_version_set_doit(struct sk_buff *skb, struct genl_info *info); int nfsd_nl_version_get_doit(struct sk_buff *skb, struct genl_info *info); int nfsd_nl_listener_set_doit(struct sk_buff *skb, struct genl_info *info); int nfsd_nl_listener_get_doit(struct sk_buff *skb, struct genl_info *info); +int nfsd_nl_pool_mode_set_doit(struct sk_buff *skb, struct genl_info *info); +int nfsd_nl_pool_mode_get_doit(struct sk_buff *skb, struct genl_info *info); extern struct genl_family nfsd_nl_family; diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index dde42aad5582..187e9be77b78 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -2182,6 +2182,64 @@ int nfsd_nl_listener_get_doit(struct sk_buff *skb, struct genl_info *info) return err; } +/** + * nfsd_nl_pool_mode_set_doit - set the number of running threads + * @skb: reply buffer + * @info: netlink metadata and command arguments + * + * Return 0 on success or a negative errno. + */ +int nfsd_nl_pool_mode_set_doit(struct sk_buff *skb, struct genl_info *info) +{ + const struct nlattr *attr; + + if (GENL_REQ_ATTR_CHECK(info, NFSD_A_POOL_MODE_MODE)) + return -EINVAL; + + attr = info->attrs[NFSD_A_POOL_MODE_MODE]; + return sunrpc_set_pool_mode(nla_data(attr)); +} + +/** + * nfsd_nl_pool_mode_get_doit - get info about pool_mode + * @skb: reply buffer + * @info: netlink metadata and command arguments + * + * Return 0 on success or a negative errno. + */ +int nfsd_nl_pool_mode_get_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct net *net = genl_info_net(info); + char buf[16]; + void *hdr; + int err; + + skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) + return -ENOMEM; + + err = -EMSGSIZE; + hdr = genlmsg_iput(skb, info); + if (!hdr) + goto err_free_msg; + + err = -ERANGE; + if (sunrpc_get_pool_mode(buf, ARRAY_SIZE(buf)) >= ARRAY_SIZE(buf)) + goto err_free_msg; + + err = nla_put_string(skb, NFSD_A_POOL_MODE_MODE, buf) || + nla_put_u32(skb, NFSD_A_POOL_MODE_NPOOLS, nfsd_nrpools(net)); + if (err) + goto err_free_msg; + + genlmsg_end(skb, hdr); + return genlmsg_reply(skb, info); + +err_free_msg: + nlmsg_free(skb); + return err; +} + /** * nfsd_net_init - Prepare the nfsd_net portion of a new net namespace * @net: a freshly-created network namespace diff --git a/include/uapi/linux/nfsd_netlink.h b/include/uapi/linux/nfsd_netlink.h index 24c86dbc7ed5..887cbd12b695 100644 --- a/include/uapi/linux/nfsd_netlink.h +++ b/include/uapi/linux/nfsd_netlink.h @@ -70,6 +70,14 @@ enum { NFSD_A_SERVER_SOCK_MAX = (__NFSD_A_SERVER_SOCK_MAX - 1) }; +enum { + NFSD_A_POOL_MODE_MODE = 1, + NFSD_A_POOL_MODE_NPOOLS, + + __NFSD_A_POOL_MODE_MAX, + NFSD_A_POOL_MODE_MAX = (__NFSD_A_POOL_MODE_MAX - 1) +}; + enum { NFSD_CMD_RPC_STATUS_GET = 1, NFSD_CMD_THREADS_SET, @@ -78,6 +86,8 @@ enum { NFSD_CMD_VERSION_GET, NFSD_CMD_LISTENER_SET, NFSD_CMD_LISTENER_GET, + NFSD_CMD_POOL_MODE_SET, + NFSD_CMD_POOL_MODE_GET, __NFSD_CMD_MAX, NFSD_CMD_MAX = (__NFSD_CMD_MAX - 1)