Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp103011lqs; Thu, 13 Jun 2024 05:20:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUfugpcGDWvgQCyfK+gcwecKEtRtE8Aoo9mN4EjxAtEbOiPt66pgyHoBuOlza7TbkN4J1alMcmfi+Lj9gQ1ad1gZdzJ9oGGOh4MQYvc4g== X-Google-Smtp-Source: AGHT+IGCHoOa9UTo534q+ToKUyS9v0spJoS663muyuUmqUGi04nwz3DjiAUWDvkPXEHthqJyMetL X-Received: by 2002:a17:906:13d3:b0:a6e:f75f:be04 with SMTP id a640c23a62f3a-a6f47f9b3eemr308843866b.38.1718281236367; Thu, 13 Jun 2024 05:20:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718281236; cv=pass; d=google.com; s=arc-20160816; b=b1ijd50mF3/WlNKGbY4YM5gaSoMKMDiE9lxaWCwuFF5FqPE1JV7uajNFmHyvvwK6Cv jQNDizCoQEzgKx/VZpQlH5m4GYUwKTFlSS4TWYu6lFgVwpCIX78ac+o3ZmWvI1rQbkuD Wzfjpyy1vMoix1OiZIVf0plClbKt1rBLBBCaohyIGzCtSA11GaGSpwbRrCvNAPXhVjMh VsN7QJVG0+MjkdL2cm1lwZMIvVBjK8ZpXg8kFeOsxIADC5wkz5eIIUw2wcp0VtUByYMq 0GOLc67UPXb/JozYwNOtxIPbC7XW54his74i9bW7a7mx8B7Caru+hRqHEmieb6li5VK5 gJ2Q== 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=Uca+jKaCG5xGBJHE+xNk4ad8YPuR4cHmizQb85wT8z0=; fh=1/3lXFVz69UqpVG6hQDZ/Hd9qKfdx/7X5bNqh2kvdjo=; b=WLDvFNbe3WMF/9qVM7TmmzYqqqhvaFaQZi0/JdJK+JZ3VsjQxKB8dAZyHtb6rvCaot tCeB2OoG5CWW66DEzFRTUSJ3deezXdnLcMHpGpDMrVoIkSS362lkGrD9xT5YJFiHfxpY J0eyHLqvZuwlaT2V336/l/HTB5ApuZDmVQpBNtMNPHLUe7bu4vN7AIEDzb0WUMU3Kr2u 5RNJyxhrOfc+wi22OtzR0SlD7JJZuPL+4vBU6OPVHYkU7p24R9rO8OAfv3Cwg9PH629r rY2/ogD5TYv7l/Sv99FbmQKw/hDMs9pAxNtXz3BJmxsoQ8f0DmErzsPByui9boJ8iCw1 1B2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="dQ/AS1B3"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-3757-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3757-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56df7b5bsi62411366b.662.2024.06.13.05.20.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 05:20:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3757-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="dQ/AS1B3"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-3757-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3757-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 am.mirrors.kernel.org (Postfix) with ESMTPS id E45A11F2121E for ; Thu, 13 Jun 2024 12:20:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B10BF1482E6; Thu, 13 Jun 2024 12:17:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dQ/AS1B3" X-Original-To: linux-nfs@vger.kernel.org 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 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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, -- 2.45.2