From patchwork Tue Jun 4 21:07:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13685855 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 DD14714C58E; Tue, 4 Jun 2024 21:08:13 +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=1717535294; cv=none; b=t3L4McsEjFfiSDot1iL95NS2XS7bjJs19IQo7+u06zYeLHHfG/Y0uUTh4e24aZdnNiSJ2HdOGaBUNXkBkJZyhRzLyyztn55GMfRiHQpYczNd5qQv+AuFauPKS2Q0PjYeOSCNvm1anOR1MPkBkhfHp7n+XVWe2RvXfQwDrhCtqqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717535294; c=relaxed/simple; bh=sFrRqAc+3keBolPqurYuDWuBor53GoaZSW/eQu5WwRQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IPnvyWsXbLtEO/8e6pILEHbLiDPMmKkyXKxaj3nc1v+0LL7rXMjtufU7sLVHD+pzy3VRsOu/e/hQ4enpQVZle3vbAG50gf8riq1e5NZGkp2fp5O+K0HqKo3dzR6fjoCBvfnuyKktWD4Y1QO8Iv/QA2E7ozch8wiCgINUFZDktoU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZBhzzjru; 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="ZBhzzjru" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71C37C4AF07; Tue, 4 Jun 2024 21:08:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717535293; bh=sFrRqAc+3keBolPqurYuDWuBor53GoaZSW/eQu5WwRQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZBhzzjruoMgvJ82bI1B2F3/lkMLVyjHevGZQzQNnA5ExMhoR+wssj/jlbR6BMGVdc jpFiy826tbFvudlMOLfC/0tHCMQXamJ3HnDVEaagNm6a2RzBfIfobNaurSEKfmnCtg wwCkWTDoZewBcYPJ9Cq7nWhvz6Qkzj+fQs/Kma3+nGh2Ies+VyWFm3DXA+GOssh4+r 1K4jWTML0WYDpXaEJUgXqlH36YPQs8xwTOy+oFRqUoRpSV3U7+5hJcQ5g6arVboXzA jEOwG7NePdIcMj7AtuwXDFPqkw3EiCU0ecDv5na7vLEWTPdDyEEUmKmxT6KcWmx4w8 +9uElpDBUTHvw== From: Jeff Layton Date: Tue, 04 Jun 2024 17:07:54 -0400 Subject: [PATCH 1/3] 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: <20240604-nfsd-next-v1-1-8df686ae61de@kernel.org> References: <20240604-nfsd-next-v1-0-8df686ae61de@kernel.org> In-Reply-To: <20240604-nfsd-next-v1-0-8df686ae61de@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni 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=3747; i=jlayton@kernel.org; h=from:subject:message-id; bh=sFrRqAc+3keBolPqurYuDWuBor53GoaZSW/eQu5WwRQ=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmX4I6jGBaHiLed47Nq4OTkhX5mdQ8z72L2PUIa fZsEN1KbLCJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZl+COgAKCRAADmhBGVaC Fc4RD/4gPmQVG9OjaHk8b7mAHgH/dSJ0XPclzIWo2jRBvH9P11pNTdu5PXHWlndYkS9ojbkqUaW mP58LTMIDJad/AO6zA95OE9p440Q3f/RzxlEKzLfObCMtWj9jwz8l93m50xCJP7zQbUjMRPFw1v 0Ss9MeyX+UY7syphYUChk8cgWfI3pzzK9leQVi7hdx0AwYPeepfvwLCRRQSq/xsxlTDfSZr7bKp Gksnfw0bkkiyW8kegNWmlpNrpgv1ggYWPe48qQxccTzfXJwJHsfjXO3qnkxQLdXe8ZigvcYO6tB Af5CSoKemRPSBPMdIzyL/3AnZcIsZ0p/hwkqxPKqrsSP9likD9wcv69puuh0Nj4XJtcfrD0LSPd NhwWc3yG5vFsbTS5hIv/IK0w9UJQscrEnreAt8dfbiSvlz3yWqyflql5LhVJkWlUsdxyRJxUiwJ zHUQ/45GwpoKOVLg91fDNwMYnS5XKf9kodIUZQeq2907wWOaTOT+XyRQFOBiEHOh9jNMcOY/3f6 t6PDebi0nqYswaY/ZsZ46+LrO85Dw85lRx7SuMjxgQImbJxtMBdOrRNPbSJXQP6o8hI821S+j7l mgU/nTfHaLdpiIM7rrPcxX+9j5t1A2St3z30QMT2M1QvaGBFnraxAujoJzOlS+T6k4MQniIXCRx QAMHR3syI1o0GyA== 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. Ideally we should prevent anyone from changing the pool mode while the server is running, and nfsd does this if the server is in percpu or pernode mode. Previously, you could change the pool_mode even if there were nfsd's already running in "global" mode. This fixes that problem as well. 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 Tue Jun 4 21:07:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13685856 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 5AA0514D2A7; Tue, 4 Jun 2024 21:08:15 +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=1717535295; cv=none; b=JcanZryhfmWmlWLcsKgUDPKmgvAV7SdgT5VvFoS1ktT9lYCCu69aj9xDQ+UfLRN4szydlXrnmg3M8HAxKr8W8xBKM+VQUozv/8wiRegyCkQNmkLgfuo9OJ9ErPvPd3ydLyo/+NB/IreH7dDtWg0EuaEmNrigUqqviOQM3pFQsKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717535295; c=relaxed/simple; bh=4ejWVCwRkJi2nJTPzl+iwDP9GaQR2cMB6eHw2ik9W8c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lBbpTrJMIkiWZhS9iBTN6XjL77YnF+zjR2PKqQkebsAhV/2A/Gakm9Wp7Wd478/9VtOT2S1T8Vqnmv+HAbI/MvNoF5nAGKutmgA1U2gLWdhN6jv/d7A5Iwiq5t6Hygul8jRtdtdGO3flFAurIWexyTQUdMTHv60oceXn+YN3d6k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ObK8qDcr; 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="ObK8qDcr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9A87C4AF14; Tue, 4 Jun 2024 21:08:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717535295; bh=4ejWVCwRkJi2nJTPzl+iwDP9GaQR2cMB6eHw2ik9W8c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ObK8qDcrWdyXVn6H3oK6tqOa3iKG3SQ6Iy+merZdT4LVnpna2cb2yphlQItPgaRcl sin+oLuYF0/U9j+yOMZOLzYianzT/a1nzJqVqq9FZqx/hb274ZZEoj5RFxvfWEprYC 5/JMpCA6JaOTLcSYxnOt3SzmQJA4Vn9TXwIyNxAsuDvXQOPGYNdcGEV9JXAL2Zm+9D 4lWJBDbz2jRsR9xU5HxL7VTKEvCg2/pRWBlSvbiOXu1W3JeXGQwZVFIBK2fO+kjpiJ 2niETsenodZKSUZXEp0rW5XTVgpQZYdwM95rmQSJJFWr2gymRCChq4TyCWQW8+3lhQ vIHJfmWDyr42A== From: Jeff Layton Date: Tue, 04 Jun 2024 17:07:55 -0400 Subject: [PATCH 2/3] nfsd: make nfsd_svc call nfsd_set_nrthreads Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240604-nfsd-next-v1-2-8df686ae61de@kernel.org> References: <20240604-nfsd-next-v1-0-8df686ae61de@kernel.org> In-Reply-To: <20240604-nfsd-next-v1-0-8df686ae61de@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni 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=3981; i=jlayton@kernel.org; h=from:subject:message-id; bh=4ejWVCwRkJi2nJTPzl+iwDP9GaQR2cMB6eHw2ik9W8c=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmX4I6DuBsDDSECRq+rIbwsbYBIBMU8RWrtUpva Hwu9Eb17f2JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZl+COgAKCRAADmhBGVaC FeBKD/4nxsChtoKGX3jR2KqlJXXG9o6Vc5J7ISr9kzag2cZTifpZ7EVZi3MJmNhi0SjoIwgpEVu 79KmyYrFKOo/KPrt6XZtdHrKDrUy9nasrqSQnkMv8VZU3fxhQJZ8RzFoBL69t3ppfYIjYZpDM24 8qCLfIWV04JoT1fMioz7Tad3VMDND8kfkSvC+ilUtQ9/FJjWaCi0nzMv6bBFcsI2Tx0P8hV5u7Q shn+dO2wcYjMkllV/tWSN5j99Wl5B6u6dOCkc7KEILT67CCxvI4EKMf/H+0w1XHSv7WVuj2tWEY 4SXLB02YgocTR8xTgdlt87ooM16TiHJjG3HgT6DM4Vpv6zBgzSvYqXi9hTD0qSGX+ni7Bcp3nfC a9nh+37v2bkMB2bPUS+usBNsXLbnmwr5ny/oq/zYFd70xIqh8IfxbGvRulJZCjEwqtirMmePS+8 Gfj8yu5rmZCaIfNqk7qvYtsEuTgLA9kdeCCypIAbNo4AlZnbwn2E99yLXouZ5h3LctDMt7pflna QTeyJbx/MmIg6xqDKArXPq7r/+pCb8h/MhXGxR6nb6Y2XxUzPrx5GMsFMFTO3gmGQwIGsSLD4hw z6M4i5SPJ3kg8mFtNQjRhPD5GXiiuq3F5gWhxiLkBP3zU+8VbNa+VRYngzD+cXUozvZm0pPIur6 eJXkhino9kXjMhw== 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. 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 | 14 ++++++++++++-- fs/nfsd/nfsd.h | 3 ++- fs/nfsd/nfssvc.c | 18 ++---------------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 202140df8f82..121b866125d4 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,16 @@ 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. + * + * FIXME: do we really need this? + */ + if (nthreads[0] == 0) + nthreads[0] = 1; + rv = nfsd_set_nrthreads(i, nthreads, net); if (rv) goto out_free; @@ -1722,7 +1732,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..076f35dc17e4 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -744,13 +744,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, @@ -768,7 +761,7 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net) * this is the first time nrservs is nonzero. */ 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 +771,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 +782,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 Tue Jun 4 21:07:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13685857 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 1F9FF14D457; Tue, 4 Jun 2024 21:08:16 +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=1717535297; cv=none; b=VgrQcsecanSRfvpXQSU6aY+XVH6ntB9MN/zdEpvvtachPsS6A1vSFDpYlrpQ9OHhU1XQIt/BNrkC5risHTeTNJpRmdAoQ1CXqAmUbg0BAaIaF+AqqanBUHH/dSB6ygN6r7chUIaXtLTPfBkDElWTN6x8Pxx9SvLpiXSbGvPfwpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717535297; c=relaxed/simple; bh=smICcs3nQ7Qjl4GeQETN5FWVfli3hNNvlp5QgM1lB1A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZVkxXILQYtH3jRnnvGfvlDZ3YR6nHVAzYEv01e5yFRAF2O9ZX86W6b+OsHglBBNUfK8bzQdGHqWmfrJWs4oMlCWszjoCwd+gVohtHZIaDF3QNNiU+noZ33i8c0K6e3kkwdlpfdcbvVS9lqvpT3t0Jz8oGxzosbVn8U/EpOIZTzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LXPFarra; 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="LXPFarra" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C8DAC2BBFC; Tue, 4 Jun 2024 21:08:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717535296; bh=smICcs3nQ7Qjl4GeQETN5FWVfli3hNNvlp5QgM1lB1A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LXPFarras8Z3AlcK9p6oJotHBi1MZkG7naQLeFlzubekjqVg8+kcKA5rTEFAd73jE 2dKnVwXy60xIQHVvHkm9sn6QpzgO4B2d0UDc90Jz6cnU18V88dcCJmcIhaG4pFR1LM CU01I15s1T3LpjpccayLEAXzA6YGVcMQDl9yUR/mfU7iPA4faEX1MIXcCcB7IG8bUy fqD52Mtg6EmIJzAkln9y9TQn2L30qo8vEXinIfOPnzbIkKhZGuh8UFmvWABHL78C7+ /AIl0SwOZ+L8AgHGqYQfJg3WhNCMpiNDCGCeUUr0diFpjospggQyTTiQJvrEk1VN6e YfS34gqyOADmA== From: Jeff Layton Date: Tue, 04 Jun 2024 17:07:56 -0400 Subject: [PATCH 3/3] 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: <20240604-nfsd-next-v1-3-8df686ae61de@kernel.org> References: <20240604-nfsd-next-v1-0-8df686ae61de@kernel.org> In-Reply-To: <20240604-nfsd-next-v1-0-8df686ae61de@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni 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=3150; i=jlayton@kernel.org; h=from:subject:message-id; bh=smICcs3nQ7Qjl4GeQETN5FWVfli3hNNvlp5QgM1lB1A=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmX4I65iElhkbqt7azyrUZFfxAg2uurCdvxAAYk HShJFRvy2yJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZl+COgAKCRAADmhBGVaC FdbFEACxVJZvjPhMxFD01p7PTrKSX0u7ugzuft5cJ55E/yHNGO51h8I/UD3OyBdUeeY+V6e8v74 IKWcrJi648BKajyHm7wN4jB3VUw2LcNTHj9y2vPSRicZbi021ozxd2gs7OJs11eB/ldNVAkazvS KwlAIDv+x/7fAbDvGO9d4BVsW+YjA/srmfBoSRGfUMjrMKD2kx2PN3eMH/Kepd9Mr0rlJnHXYEh JUc1NpCrO2gXkHkNxkGd54r5IEDArMU4+tkd/E6TNlC5PDM+UtbcalW7E8sdQuzGm7gXb8zcWnh m7kaABXW+VgO1n1ZMSjXvkuVmAHa7NlEtTNtYiMomS1Z9CH5SNRg3vALFUJW5TxKFiIPreoVbw6 DNNiBz59ILY7Zit5GpNgsxTuoXIBYTip8aChvuTW19uKxET9cIslAJJVIblr5Kagg2qxpvqbHv4 HVPKTeUCkwRu8cH6NewWpIb3P4yQ7wJtLovcTvwfh3UETiVRdfq5Atp84MVfuHAp+/U8dmDWa6L DoEAO4NejBOfalYuR0/vPvXzgnnIBeMB419aVVzp+DQVD2u7ayzukYUlbZm3BvvKIsLigPyn8T8 Fmtg/g71GWVWlv3mPhE2+/2RvPzX4iE5mFtQsguS94eKMlnRrTujAt8AmJ8mWexXLzjoMm5kvUH VoMz/xlnP8Dv7Gw== 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 | 33 +++++++++++++++++++++------------ fs/nfsd/nfssvc.c | 12 +++++++++++- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 121b866125d4..54b98e569740 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -1673,7 +1673,8 @@ 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, ret = -EOPNOTSUPP; + int rem, i, total = 0; struct net *net = genl_info_net(info); struct nfsd_net *nn = net_generic(net, nfsd_net_id); const struct nlattr *attr; @@ -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); + 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]) { @@ -1732,12 +1740,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 076f35dc17e4..6754cbc27c71 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -750,8 +750,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; }