From patchwork Thu Jun 13 12:16:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13696735 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 E993B14658B; Thu, 13 Jun 2024 12:16:57 +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=1718281018; cv=none; b=nACl+CbWNVv6zcVBkcUrDGU8P01dSJnV4qpXLbeOJspwy4i6A+3w39WCNEivCPbp8aE/29ZzNhhhuUjqLKLvPKcXcg4VZmMJkJwKwv6Jmw7wKzO0pOdv3Iv7jXXXOYikVPjtgcQMWinomJamwldroQxCpLWdfHIhTcAGtrSYVHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718281018; c=relaxed/simple; bh=ghg88iAsp3/i9GvYH8AftKpHuXPhVhmUoYTrJpEipyU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JInMr4BmY7pUMNC2LEq5fvny/7GgX2a/3Oyi7H9k4g3IWyYnHxxein8/NfNN7XMLxPRBPnoXnnpyyFUjOQ2DdSYFp/5dz2ID2PwH9DV8TSQV+Z8juDG+KsS99R8YTkkP42GUSa/wD9ztHXqo+8L1qONiW6GDHRCZcWNLfk4Pdp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=faRrTFjv; 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="faRrTFjv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25514C4AF52; Thu, 13 Jun 2024 12:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718281017; bh=ghg88iAsp3/i9GvYH8AftKpHuXPhVhmUoYTrJpEipyU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=faRrTFjvWA0Gx+Tgveq9/6Y6fhwNHY4nIjN3BzpSX+VFhXDrksHCmPwbfXUbVNS/6 OyunNm68wmgIlZrgNER8CL6ZEnqiIZQdFJSdBYOdvHNk9CGtAYp6h4UAKx/XO0U8ND /ps2kXyUGNI3LqHyrecNUaNICw2TJTVo5Ew9OOwoXNu+EUAY2prHFwmjZkDYaFT/Lz tvK/uz8c0bROEBAnVXpPi+yS9otKrR6PLIG6jiW3JWEUhp8/x63vwN+ymJ13SknL3B yOvtyl7PCe1mNyJ/1FjK/Mn81n/w9gqpWqji97q1OnsOQPlffAUpv/p/3OY4Jy/Y8l ibaHfvqlYmqxg== From: Jeff Layton Date: Thu, 13 Jun 2024 08:16:38 -0400 Subject: [PATCH v2 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-v2-1-20bf690d65fb@kernel.org> References: <20240613-nfsd-next-v2-0-20bf690d65fb@kernel.org> In-Reply-To: <20240613-nfsd-next-v2-0-20bf690d65fb@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=3747; i=jlayton@kernel.org; h=from:subject:message-id; bh=ghg88iAsp3/i9GvYH8AftKpHuXPhVhmUoYTrJpEipyU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmauM1I+D7beomyTrYtILfYwqORRq83F8h9MZxV g8g/N+oUHGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZmrjNQAKCRAADmhBGVaC FYUIEACMtZL5vSZIl70OP2BUH9/+TZv2zJ+WcmE4PkNq0gQqiR9blN9sZOpGNK9B5Ux0UZnBIlc U6qrjqQ8CjxANOy9Ra0t+LWeo0tY/0TDhFamm0MbhMaqJ/RKLxTts8tiHDtAbE1eiE/crUXxRm7 1mU1v0YRXkTujqLDfLtHVXxAraBHZPa+cglDnWDqGazEJzvopV48LUy1c9b1HtOC5A/JwQmIixN 1OfvFRQDDOVrFcWpRUASKjSaJ1YfIfzwJwmayJBkkuiaTo3E28f8EVf0YUt2SnJCPzuQvWkVI0w /cSoqn5mppeDpwrDNJgJZVFOwS97BEZ4PuVCfyBWOKrLc8DmxFg1v0aeWaJTQWMwtIgH9sHxmjG 0on2EniQcotanZLShHl6wQJa97Jfe1lJCnSjAzWYqSsaarMNAI2p7spmxYnJUhmh14opst1FzTz Z5uthQBdvzTnTz1ogD4s87lXRQoVEUxgKHyXsINj5gmoNbpZVSkBnPy1WUmpFkca9CnoKBzeLlx OLtz1hVSDKFIqT1MW0DbS8++rq+cj0KiUPlYfN0vd+inTE8yBNk0O8e4Crtjft1c2+7ouQfP+4U etRWYzC+3q0ANd2K4wHJu9V+p9yWv/980L0pZwq62MpEh4Pp6Fdp5GKbCukiS5eiG1kRmyfQwJh mhCedEMvzlMp0UQ== 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 Thu Jun 13 12:16:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13696736 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 88D78145FF6; Thu, 13 Jun 2024 12:16:59 +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=1718281019; cv=none; b=DiaTUfQDggro4749f9OXB2hovlzaHxxFYP9JUqDEqRLlyKHR+HBpASrcoF+M/aOb14isT0QeFFF2PI7E8nTwRmcJvaqv/Z7lMyQeGSOKl27qpqw004IfFo18X0Jrh55JwTv3X0iMLZs3x/KnXZGqS7+WrWFsDstI2ztdDpTR0yo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718281019; c=relaxed/simple; bh=BO3b54uN5KBEeup6eygbfA/ktVZYSlBfJA/gQCCFXIU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FlStLFP56Aku3X5QxqRroIiTa+RJdwhgjYVUuSef1eURn/cYkBJKC6By/efjS0o+rzmWXsk/x7R9lb6HKOYMEzxSWyQPec77KCi3uIyS6SquCstG35eBeCmi1nKcgJQRWUb51Ia3T6IwJGs0VoNAS8NTvAb1CmExFgt4m/iiWps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JXqmqhmT; 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="JXqmqhmT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD2A6C2BBFC; Thu, 13 Jun 2024 12:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718281019; bh=BO3b54uN5KBEeup6eygbfA/ktVZYSlBfJA/gQCCFXIU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JXqmqhmTL4mBJzxad+GpL2XBxTlVIlOCxUU/+baH/tNWpDK6KpfcEmLnED4EKODps t/36g2PmN6Re4bmpEj0/LpOoVZLSJKq8x+u4scpe8/imKbbSC7zxa2OVRX/bBFZnKw 5CHwQudKgDzxwr7WvgU0GYIaDPyOrDXH5mDzrRXz1xKViUUPS6S7Kd9jCQ9wCzWt07 0x5xAPWIcUh+Cp5Cf6UaDy5OQchSlO/K5YwQwGU9ccQMZoquirdjLXBX+anPpkIt/2 KPkUuwZ85ZsmMoPEd8SPGxycoQnXNvR/uXGuoP7LkaeZFXw82ZsT4js32xBli0V7/S 5QsA4w57sP+FA== From: Jeff Layton Date: Thu, 13 Jun 2024 08:16:39 -0400 Subject: [PATCH v2 2/5] 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: <20240613-nfsd-next-v2-2-20bf690d65fb@kernel.org> References: <20240613-nfsd-next-v2-0-20bf690d65fb@kernel.org> In-Reply-To: <20240613-nfsd-next-v2-0-20bf690d65fb@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=3981; i=jlayton@kernel.org; h=from:subject:message-id; bh=BO3b54uN5KBEeup6eygbfA/ktVZYSlBfJA/gQCCFXIU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmauM1I0gM0Komuwlqjvrf4FN/BtFDUO9MjPQHk QSDQLefH1CJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZmrjNQAKCRAADmhBGVaC FZ5lD/9tAkikSuEKG9EEc3J4Rg9sQtA7E+ZD+IvlLdaLoOKZ2QG19ZRa2huovMo4Bg016KcwssT 4EzBmbFzjsvP0S9bCs4RQRO3TA63tyk7wC+Wk+d3AhWUh7UrPGEIKGY7PyEBM7C3WhAwW1vpWuC 7SJ7BCuw45R6vRh/C3D0OKQPUPw27+3RxqySBxL4zkHRliM3ACzLttyRJ9EcKbrGt7p3DKgNw70 M1hVnRTLc5mafJkpwGhgLtJLV59Msqzcqg/v76PoITvlpQxKiZDHszc0O2RgguOU3uHz5iP5iG0 y0fzUO7KJc3Umh19mzASIQ0yMlOG9BQpgSxmAyIHFPhrWsmal3yJx4BPUsr2pwedRXTWoxxYgHC WeNR3J8aAX13D9icdRVBPWCdNTvoWvQH0DeEByRMpqYCwX3W30jyF5QnoECLpJEvkdCvHua1k0P EnQkf3opGSkcXZXPhvlMwI4lTvoc1xF1O53b0G3oLYNatS45+RIpFIjtf5+zf7jStj8MLgUivJa XII7uq1edUPcdnJLmNOIvurZ9ZJZODPGP6Xk+YAjtezisRP2GMNQ9Hs8vIO17Tb/dUeHRiY+dpo 1a3qAdO1DOVyQKPcEQsgej+g9dvdEYL5rRfyJOleNHJRovwRHMsSL12UXVw/6Riwy8DyNko1WaN 6tZHkoir5yqGO3w== 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 Thu Jun 13 12:16:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13696737 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 0193F146D7E; Thu, 13 Jun 2024 12:17:00 +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=1718281021; cv=none; b=W34s5ws0RcpNQinnsC+ghHLOdeBuj1Jq3JphjLbYRXYjHoRVQeOmhn88/DrNX/eXbtFc8uRDF12jSxiiuAJ1/38Ptl0NS6l53ONhfencs0+tYgjwoJvYARFyUWdsRRpjQkywpSJ8TP1XZ9Wd03zB6Viv+edXm2j6ezKwthsDxqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718281021; c=relaxed/simple; bh=F4yQVNCqHoax6TyvivF3/cRELpDg4rafpz6ZL4viPj8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ioEIQbzpn/Odq8NiRBacgjrY8CYaVHanRu0mIydM3ubqfr1xzpV4rfe5+dNhGoHhhWBLqw/zBnVAwnz3+L5jP2iKYNpyzFvcGgrflXltgw66k2C85GRcpFpGmtNCi6TWgBAD0osjoqlwoh3JdOnB8swHv/qK3Yl9soLQ4oU6g/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mDEFkK5X; 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="mDEFkK5X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D96FC4AF1D; Thu, 13 Jun 2024 12:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718281020; bh=F4yQVNCqHoax6TyvivF3/cRELpDg4rafpz6ZL4viPj8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mDEFkK5X8REFmA+XJdwQPtixQ6krj6SLc/CT1z8Bv/jq5W1pbFEpnlPfrssSLnOAv 7sNYIeVLfLUEtiO2E5qJzUAHwaPbm2iBF3AV/P/WZagfAHRnlF4byH220rs0ALPJdO +ZHnF366sGdNfDzys7DtydIL8VjiyNZH8zsykDiZW6eJS+5emzKfa92lQrBTjTxS1q BVV+fqxRRHOzEZHsSSLbU0VIy5alDwq9PvrfWF4c/7SdqGuvFtM49GI7lflu5+sOFr wEIo0NtDorR7KQJh27gqdBpNiKxzCmzD8UC3l3mYLqDycvXroxyoslkesR7PedVcTN GcipNaY8JhScQ== From: Jeff Layton Date: Thu, 13 Jun 2024 08:16:40 -0400 Subject: [PATCH v2 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-v2-3-20bf690d65fb@kernel.org> References: <20240613-nfsd-next-v2-0-20bf690d65fb@kernel.org> In-Reply-To: <20240613-nfsd-next-v2-0-20bf690d65fb@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=F4yQVNCqHoax6TyvivF3/cRELpDg4rafpz6ZL4viPj8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmauM24ySExYsjOMXyCf5+X98995OYvDizbtzEW 91A3ITsUcWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZmrjNgAKCRAADmhBGVaC FXYFEACRr3tqAwGMcvRz4Iv2j/7wk/K35X6lQFM+XHzOqegPXgY/Q1E7XWAz+uf2n2xDOVz2DgW PU2cI5fqZtvvROlnSla7Y6F7xkZgZtqpjV7hayRFWtelSRL7IcvLmF/AJNC/75JujuOMuc2nEYM N9yVx5S4cJbJMgbcJQJ9kDwSpv1a152x9eSW4yC4uIaP5gYG6yVU1TugGlFV6DmRbI+ry9wExFj wTIjV5q4CFZ0XZOeKEyvwSfgnCNn6uOkBWcbXafEckAeoAHzgOBbLqC9x9l+BTQ68ZfXlIeiy5Q cH0cbvhXaNWBNEVYUnHJ23EhubUvGdvyGIPrZauxikwjmdCrDodNR9lulO2qnT1Tk6a6aWBNugS HEbL9OszHs7eleJRhyG8KsjaW//n6jpiBPhz9iuMAmvpbWUoYvtYHAy/jkiO1R2Or5Lbq+cmuT/ HJZ4cJd/EHzrSSjlw6dkTrOq7r7QK5Xhxf9tiADU188HEdGX8cESM2ikPIyLVG+DF/PWq+bcXoT +YNvgahF2flKHzCpK5O1d60CqvZ8I3lmbT8x/zW0NsP+vDMJjxwme418b/j+czc2Q0KFVzF9RJN 7ov946+/Eap3QsZTX1E9f6cOtJ5ZnsO9d3ZmTGCFTYLy/3asGbDEm9wILiU+6lCf7EjFtrniWJj TTAKHyxRtK9gi0A== 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 121b866125d4..d67057d5b858 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -1673,7 +1673,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; @@ -1690,15 +1690,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]) { @@ -1732,12 +1739,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; } From patchwork Thu Jun 13 12:16:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13696738 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 869D31482E2; Thu, 13 Jun 2024 12:17:02 +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=1718281022; cv=none; b=jxBB0hr73j6MXpd0B8y4k1sU3Me6gc8xbddwoq9VJ3BzpgmTP5yiWPo5xZjJ7XV6WCh8Qax54eiCmtlbgOM1XOLSbzDrZeHuuYMTq9VRU0ZchY5aQy43AttYHCDtJoUTWEbIw/2viosvtouaBCJiM/1nyozTs/cfJ9jDIlulF5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718281022; c=relaxed/simple; bh=oQa4zv0vPWkoBLtVhYd1+5aYyJOZB4t+WY3wqD7rvGo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=P/1bAjd5cxFNi8Bl9U5NihRqqlMHWYbF3FP2loRZZ1HB7g3YtjFEychfZm8N2EebQuJQdils2qMHCgSbPSS1W7BJ+N1+8NHLUFRH59xWbSaoV2w+hGtHSA6CrH+oh8TaUINBg8Xzspq16aKhRfG8FcRYIF/hofE7IOthM2HfmP0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dQ/AS1B3; 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="dQ/AS1B3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2823C4AF1A; Thu, 13 Jun 2024 12:17:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718281022; bh=oQa4zv0vPWkoBLtVhYd1+5aYyJOZB4t+WY3wqD7rvGo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dQ/AS1B3T0oYJ3KT4/+lkG2SMTYgdP/rzkaPl/09ERntfpVebCPDy2Lxd+/ILqYyl GxlbKIzGN8oWxOrcs2UlRub+GbZ0Tmwb46vJlyvzPuPM/N7Z5HR2rvrFESK6Gdqsz2 DW0JRCDah09ld8KpCG/ZvTt1cuhEXwQBmwooCxT3NjDNhSez/4AvZuq78016cGS1l3 5jWfbByDLE80nq3t7kKCtsMRbvB/0/Gdc52pXtN/gGhTl7V+Bt/SXOf302ZDiOxneC 7UBLipUfwlp0N8bbXj1Q/A/4t23ha9jyko5O/z62kqfRXdP3rNhrnSYVAr5wsKeWh9 iEHbjD6fazfFA== From: Jeff Layton Date: Thu, 13 Jun 2024 08:16:41 -0400 Subject: [PATCH v2 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-v2-4-20bf690d65fb@kernel.org> References: <20240613-nfsd-next-v2-0-20bf690d65fb@kernel.org> In-Reply-To: <20240613-nfsd-next-v2-0-20bf690d65fb@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=3838; i=jlayton@kernel.org; h=from:subject:message-id; bh=oQa4zv0vPWkoBLtVhYd1+5aYyJOZB4t+WY3wqD7rvGo=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmauM2y6Zdb8VyU3ELCC4Ia9NVavrCjNWWi0dxP 86W0aTGHFOJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZmrjNgAKCRAADmhBGVaC Fb25EADSvAS1O44JfgV27YDzQzkp8WeJ0jGQALwqrFAsDB6T1Zqz9AtA4tkHbPSz9ZeHPkE0GWe 3JA1pImSMkAdQOtZBjltEyOl0j/mnT5DbtxnTDNGF/TEhJvtVZrc8ereY+JSMumRUFCqEXB0Apx ufQTUeTlRnV+rUh605mIx8F5BYPJ2zqHWXbdCxNb52UAhRGEOBtCcKQS3RUH1sxWNUqwrc9uFUy lC9e0Rm4Zc6n0cOaKl10s13CE5q7csqFtrBngXlqy/i3Ud3RIamAYG7ziAOuMVW1qUNMgmRtqfB J4As8CWwLRoUfAAOQLDrxXmqLY+iScH+g1A6tJzJBThjeP+t/U/1JELChMYjYDMfQNO0u02asal wK65H7OU+v+4tWJ8YUnIa6LnJeQ6BWKhEmCuMdYi6l5MeSZ4Pz2uYuLVKi1v1mN3RdZ9/DwTq43 EBAuzqyvrJIyyYDRwVpUpmiauvNqmKbVwRflwdncpQVUtCMNTUTncpnMdYs0KFdlppva+NB7NEn ngeijMNoZmdPlPjX1S3UWhp9n3PyHVYUW5Dlb67KQFgbwj3ki4QgkfEJJsKNjVaJxpSdhc2Zf00 iwfxY0vGlxmRLZDhYnBG7c4yzjdH76PDT4M76kHgJtCF9Wiled4V6WQ1OuW+j+9clDmFM3sklvn pB/8EYhdaYC1ATw== 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. Signed-off-by: Jeff Layton --- include/linux/sunrpc/svc.h | 2 ++ net/sunrpc/svc.c | 76 +++++++++++++++++++++++++++++++++------------- 2 files changed, 57 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..6806868b3129 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -72,57 +72,91 @@ 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) { - int *ip = (int *)kp->arg; + struct svc_pool_map *m = kp->arg; - switch (*ip) + 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); + +int +sunrpc_get_pool_mode(char *buf, size_t size) +{ + struct svc_pool_map *m = &svc_pool_map; + + 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 12:16:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13696739 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 2B2E0148318; Thu, 13 Jun 2024 12:17:03 +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=1718281024; cv=none; b=BTDPyziI/zAbxiwz2zB/SQhmB99ekrZ48jBZuijN8/1kvPCjPV7tQmVojVfBA9eIHMxNFB8tyUK0Bj/uXf2w5NvkgHmNhtb/xXaMdSMlv9Cd6/u7cxwcRVwG9fJvbBjS64BBxYcJucu6dF9iuvob7uOBMJ1Vd1huxumkR1B0LzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718281024; c=relaxed/simple; bh=wmcx3oXaU444v+p37VryHlW4ppPECsBHmL+iWyEyyfA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TdoxD2DC2rY1mh9D+Oa/RnPMYPD0DiLz+8wchaANpd5A1TN4UvIbB4JwDknSKLbdb+rWU9i7lcDp8zr6zWUMyYz+vFUDERWhQtppz97PHW/4JObzLj/sdiwXq1Z03C719HR8WMFLFjs/WbVj+YuLaVl1FeEaIQ2zks0HpfExy9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PjHe56Np; 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="PjHe56Np" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5286FC4AF50; Thu, 13 Jun 2024 12:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718281023; bh=wmcx3oXaU444v+p37VryHlW4ppPECsBHmL+iWyEyyfA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PjHe56Npb0tBZYkEmOu1QtTTANyDlB0ZARBUcf/3wWovjEr5ECk4FNYTFIB+epF+e 00sRzWzUrhxIRDTN/gllnw0+5rY76XTCiM/pOHtY2A1ywHYDuE1Qnjm47rFU9nyDvO uPd7znBABIJoL2giwH7SNI/urhhE1KWFRleZti9QW9Z33abuSHCBrKB+ZAaX5ZazbZ EgpcmZG3Cy76EUYeZ0x+k6Bkonv5GARoN+ylCVxF6TeOiVU2l1pQ8hqBFHOWSE/L+P F1AccR//KgZeeZJ0LStjqaausnSt53qOxPv961R9vGk4sv0QbTQby6MzbxTJCfQOw1 cXIhMwbe9Qulw== From: Jeff Layton Date: Thu, 13 Jun 2024 08:16:42 -0400 Subject: [PATCH v2 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-v2-5-20bf690d65fb@kernel.org> References: <20240613-nfsd-next-v2-0-20bf690d65fb@kernel.org> In-Reply-To: <20240613-nfsd-next-v2-0-20bf690d65fb@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=wmcx3oXaU444v+p37VryHlW4ppPECsBHmL+iWyEyyfA=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmauM2Fw1p4dKRbbedGTTpGwUDG3Im44USlA1eW vxTFE6HhUKJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZmrjNgAKCRAADmhBGVaC FddID/9QM6Dcp38GscQgkKGmcMKGPIJPyl8WnnfBb+QJhqDBvqJgsTVAukKfeyjiVfV6wF8JVVz YbNUhiHQxQHfPHLCvrUtLPZlxm2lBp45EIP/rwX5YI9rjb0RBgLwY52u2e/F+mTCJtK2h2x0jWL tNUd5ZvL8x4tDEEJVbW2BeapdCT7QTd2e+B/mznNwU0zQ41QLpbFreBBS9azHOFuGkKXdJYmSRT nzjfRB2qrZgmwlsANQ7pR3Cy+bJbb6LDGadr5l9xhmhFdbZCnh92GAZu1xJdW0SvHqdJlT9ydhB M2lBp+W0jt8l1nOCcFltccFppzvugzjiJE3FJlWGC48lfE65C3kWBwO2JlSGL+V2x4DFZenLyEE kdWt3tlR8363/q5/zF+Y3jLFDsfV8MVKCAahGA7rDj8H0q5E7N+zH448e+zFtDIEKkPqqb6/2nC HRo9FOX6Z52ZZvHJYUslzFe2Pu+Wgd97FJA8MFP3r0SGo4YKG8mifIvmOERZGPT4M7aPbg6865J yqV0j1m3CMQPUaspYAm5YauArXWtSAR0gOTMoXeYCHwxIE8LB1RQ4NNLe9MiiCBmbgusknOF9Fc rXW/sBDkwsSLElrboq2RDCFhYEXAnKXlL+/+Sa1k2VOGkBTfxGNchLGV+ardCpjR0bCobajON26 WYyhd+ozC66kHkg== 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 d67057d5b858..d019d4b06f2a 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -2184,6 +2184,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)