Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp102677lqs; Thu, 13 Jun 2024 05:20:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV8WzVUBHReHQTK7DvOyMDW0G8+fRS56+j+imyQDEbFjq03MHAPNPpLjY1l9trV9f+2XczJxcg+AC1XvOIzAfhWym9UunJwbdQ7Sf7/Cg== X-Google-Smtp-Source: AGHT+IG1BRtvIZD4APfL9TokTtywdO29ZdMDjATuKVQTAU5LXmV3AT60ITnxH8lxe56fIX/LOjuF X-Received: by 2002:a25:6b12:0:b0:dfb:5e8:66c4 with SMTP id 3f1490d57ef6-dfe66e69292mr4683251276.29.1718281205875; Thu, 13 Jun 2024 05:20:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718281205; cv=pass; d=google.com; s=arc-20160816; b=out9ryKH7XV6m5dcPBSrBMTzZ9Z+6du0z3JJ7x0dk5kUPVdxTl//pwoDgkBQ52Y7XG +MWW3Bwjq3AKiXXso0ztVIqwDHxakpF5gnJDv7QBXXqYHNwsp8Vao6u84tks5LUO88+v 7fyERTRZEDEWiLFokSod5/UeaBq91JD534mjKYmAF/gZoxvOP9irbi0wYnbVMkh/tWTy WI+R/kUnB3M3Z6nurOO4FfmbwV6ZFnxEkVSCL12joigDzoBGbVDEGtb1Ta/QV2gMs2s9 2XEiHU+fSVnOnLaLnbvwibixL/Et8sDaXBe/EwpcQBZT/TU1WYLuVfIs5Ya6cnEqcOLb hWyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=e+xsEXYVCzIRrn+RzFwa5qtBhX9ikksO2ZQ6oFYCgvU=; fh=1/3lXFVz69UqpVG6hQDZ/Hd9qKfdx/7X5bNqh2kvdjo=; b=vuOeNHKYXTEnmb35RPiIFG8iira8e3Gr5uViLl4wkhwWwEaDNo12aFOuNhVO/lppIp bYjtuIqVCZLjnVuAbJBtmjSSxsvTOBR0ZmrQuHEyHQ31UaRthO1ki4tHL+5FO/DJfj+o Hst4lL1gaQei9g/Ha3Y8JB/kkO9iDkfDo+DYMufkSGcqnbPYPwpdYWCiqbip8J+ut3lT yVdm7ARvTLZMS1a1xcwH3tFytt/0/2RWe/r2Jcqjjnts1a6NeZIxZuGRvuxnYh9PVhPT YsKU5+AXBNWes8M6kOynDRLhSEhvKhfFYZ4oNfKsJDBXrfLC5dFx+m9GbGpCWgQGvWGJ SvCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JXqmqhmT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-213185-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213185-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-441f2eab46dsi14177111cf.287.2024.06.13.05.20.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 05:20:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213185-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JXqmqhmT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-213185-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213185-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6D8EF1C20404 for ; Thu, 13 Jun 2024 12:20:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81F31146D6B; Thu, 13 Jun 2024 12:17:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JXqmqhmT" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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; -- 2.45.2