Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp121307lqj; Thu, 11 Apr 2024 11:32:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUSHGkQ/AOjm9mqY20fTXLR0mOKoFG2A0A+xKOA263KPjodRVeFuClHfP/w19HgKDfsZTjKHtlhnPeGmFPgCELsw/HwPTXuh3uAGUBSWw== X-Google-Smtp-Source: AGHT+IHlIJQBfCtNiYmTcNIkCqO/aOEEo3+kAMfsd2v54zlcVhdDbQUwXOs9DptzV5kF3hV2Xikw X-Received: by 2002:a05:6a00:198f:b0:6ed:8aa9:4783 with SMTP id d15-20020a056a00198f00b006ed8aa94783mr577285pfl.13.1712860325380; Thu, 11 Apr 2024 11:32:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712860325; cv=pass; d=google.com; s=arc-20160816; b=OCYVVUDEsBs4VEQym6K4Eand8QepNOckSMFFC9wR7W4bppf3/pgEoRMKf044Hpw/TU IoTLRBKL16+tKlX4Cfwyg3mTKK7sU5CLd3Un+kj/0cyYh6NZFPhk3jtPJ1f2GjsF3LnA OUZWY9fL55myK2lC/5vaE+zlFNaxntrOYM7qFN5klBAFNwhJrfaNdzpPVH3b+/rtU+O+ RAwT4Zfpz22E5t3PikIrMSwiQ6JXsHp/+qno6PswJDb9NKFFMig4RAJnOtJB6gJ5sA7v t9Fly0EZf6SOk+shvUsmuNwlQRO7qcb1Aiq1vMKfNToh24xfH6zC7ZFEqPtajOHO7iVl K/aQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=domdAzRrYHfR8kT7doIwr8jZrt1zBl74yQN4XCxGm5g=; fh=lwzJGo5ag1FZ5hWsz+EW0lAo0lCl26zLhhd6ZvjTbuo=; b=NR9exzFS34eURPpTQDvtEQG3EKAI9ViejEiVef22tCpCs9z2nbaRaDGg2NpQRgG6gs M89vdQGOOcQlnQ7JounIC+K551AtRjYHObcb3EkVbgZHl2xPBxx4trvzv3IoqvWcQ0nt hwMw1OuhxeZUupv6Oo1Cn78mRsJhjyxO0kssipSzzi4w2EzodvmE8PTscyoQySh9uK9k n14V8MtovXpvC19zhIOTEpYNYF5g7TGWUg75yeRuVHnZ+v2sNK7kdT+e1/OupajgswHr FabfZWvhX8ZE0DT+BZeK+rvu1o4GsmpVcF1z2gHeARBTtwiBUhcBhvsEO+ZMITknNNWc 0GhQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E6Oekipw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-2761-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2761-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c15-20020aa7880f000000b006ed5a0555f1si1744734pfo.315.2024.04.11.11.32.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 11:32:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-2761-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E6Oekipw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-2761-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2761-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6A72DB3794B for ; Thu, 11 Apr 2024 18:03:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2202B1C9EAC; Thu, 11 Apr 2024 16:47:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E6Oekipw" 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 EE7694776A; Thu, 11 Apr 2024 16:47:54 +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=1712854075; cv=none; b=U99zKRhzBrZ5TE+QAR4nA++Y01WCB+6Vm338r+NAthyFawggoFKf3kBSpcTVMq+pQpgv5dfhTBeU2/RJkaMbqJgAzxcum+iLit8PczuXmXpsGw0qWPJ9A3QUMlV3C7vJl9TbHnJ6llI8EgYyZ57wC1IgEM1giBlC3v7uR34PTKY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712854075; c=relaxed/simple; bh=maYb65/7SVX/4s9qjDYiJ8xqmtthQ1vPpO9pqDNHpts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r7lt0cAot5nNNegDiD8HOeagZOojMrEykH/1mrDgU7fXDyuRW2rIeQ+6p5bcn9aNvBzZ/6wkz0isazAYAG94ZjN7IefwpzQvDDQS5QK+9Le+pUthvUiz7uUDbgJUsQab2mM0U8tnRRR5QTIBMD2GyZpVq64GidB4U72N9GfNoWI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E6Oekipw; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77B05C072AA; Thu, 11 Apr 2024 16:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712854074; bh=maYb65/7SVX/4s9qjDYiJ8xqmtthQ1vPpO9pqDNHpts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E6OekipwGq/GLFxhCdJ2J2ogwQ2+c/iZ0wyNa3WGVNObEvlPTNIeUJ54xD4BRVoOb NmLImo/xuKBmWb4zOwEj/kMG2uRfeAi3DqHzXkLtU/scB/uq0XmHQ6av8WqHA19X7J j0uydGh+6ntBHJrwxKorq2LUzNB3VWDeElN/vGz3aBl1dhFAtUzM2KyY1N2+Z5qtBj OmgbSuoOFRMhMXQs0ABijB8gVnf6oijT7lxjApERP31BXYeTKZZTWBHj/bZTR3M0Dr nznpmdsQLGfq23k9uYjqvwBx59tty75Mt77GX8XCIegukBVIpTzT2er1bwf5M4MWwU 1ELyQ/qSgA/Kw== From: Lorenzo Bianconi To: linux-nfs@vger.kernel.org Cc: lorenzo.bianconi@redhat.com, chuck.lever@oracle.com, jlayton@kernel.org, neilb@suse.de, netdev@vger.kernel.org, kuba@kernel.org Subject: [PATCH v7 1/5] NFSD: convert write_threads to netlink command Date: Thu, 11 Apr 2024 18:47:24 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Introduce write_threads netlink command similar to the one available through the procfs. Tested-by: Jeff Layton Reviewed-by: Jeff Layton Signed-off-by: Lorenzo Bianconi --- Documentation/netlink/specs/nfsd.yaml | 23 ++++++++++ fs/nfsd/netlink.c | 17 ++++++++ fs/nfsd/netlink.h | 2 + fs/nfsd/nfsctl.c | 60 +++++++++++++++++++++++++++ include/uapi/linux/nfsd_netlink.h | 9 ++++ 5 files changed, 111 insertions(+) diff --git a/Documentation/netlink/specs/nfsd.yaml b/Documentation/netlink/specs/nfsd.yaml index 05acc73e2e33..c92e1425d316 100644 --- a/Documentation/netlink/specs/nfsd.yaml +++ b/Documentation/netlink/specs/nfsd.yaml @@ -62,6 +62,12 @@ attribute-sets: name: compound-ops type: u32 multi-attr: true + - + name: server-worker + attributes: + - + name: threads + type: u32 operations: list: @@ -87,3 +93,20 @@ operations: - sport - dport - compound-ops + - + name: threads-set + doc: set the number of running threads + attribute-set: server-worker + flags: [ admin-perm ] + do: + request: + attributes: + - threads + - + name: threads-get + doc: get the number of running threads + attribute-set: server-worker + do: + reply: + attributes: + - threads diff --git a/fs/nfsd/netlink.c b/fs/nfsd/netlink.c index 0e1d635ec5f9..1a59a8e6c7e2 100644 --- a/fs/nfsd/netlink.c +++ b/fs/nfsd/netlink.c @@ -10,6 +10,11 @@ #include +/* NFSD_CMD_THREADS_SET - do */ +static const struct nla_policy nfsd_threads_set_nl_policy[NFSD_A_SERVER_WORKER_THREADS + 1] = { + [NFSD_A_SERVER_WORKER_THREADS] = { .type = NLA_U32, }, +}; + /* Ops table for nfsd */ static const struct genl_split_ops nfsd_nl_ops[] = { { @@ -19,6 +24,18 @@ static const struct genl_split_ops nfsd_nl_ops[] = { .done = nfsd_nl_rpc_status_get_done, .flags = GENL_CMD_CAP_DUMP, }, + { + .cmd = NFSD_CMD_THREADS_SET, + .doit = nfsd_nl_threads_set_doit, + .policy = nfsd_threads_set_nl_policy, + .maxattr = NFSD_A_SERVER_WORKER_THREADS, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd = NFSD_CMD_THREADS_GET, + .doit = nfsd_nl_threads_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 d83dd6bdee92..4137fac477e4 100644 --- a/fs/nfsd/netlink.h +++ b/fs/nfsd/netlink.h @@ -16,6 +16,8 @@ int nfsd_nl_rpc_status_get_done(struct netlink_callback *cb); int nfsd_nl_rpc_status_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); +int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info); +int nfsd_nl_threads_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 93c87587e646..71608744e67f 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -1651,6 +1651,66 @@ int nfsd_nl_rpc_status_get_done(struct netlink_callback *cb) return 0; } +/** + * nfsd_nl_threads_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_threads_set_doit(struct sk_buff *skb, struct genl_info *info) +{ + u32 nthreads; + int ret; + + if (GENL_REQ_ATTR_CHECK(info, NFSD_A_SERVER_WORKER_THREADS)) + return -EINVAL; + + nthreads = nla_get_u32(info->attrs[NFSD_A_SERVER_WORKER_THREADS]); + ret = nfsd_svc(nthreads, + genl_info_net(info), get_current_cred()); + + return ret == nthreads ? 0 : -EINVAL; +} + +/** + * nfsd_nl_threads_get_doit - get 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_threads_get_doit(struct sk_buff *skb, struct genl_info *info) +{ + void *hdr; + int err; + + skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) + return -ENOMEM; + + hdr = genlmsg_iput(skb, info); + if (!hdr) { + err = -EMSGSIZE; + goto err_free_msg; + } + + if (nla_put_u32(skb, NFSD_A_SERVER_WORKER_THREADS, + nfsd_nrthreads(genl_info_net(info)))) { + err = -EINVAL; + 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 3cd044edee5d..1b6fe1f9ed0e 100644 --- a/include/uapi/linux/nfsd_netlink.h +++ b/include/uapi/linux/nfsd_netlink.h @@ -29,8 +29,17 @@ enum { NFSD_A_RPC_STATUS_MAX = (__NFSD_A_RPC_STATUS_MAX - 1) }; +enum { + NFSD_A_SERVER_WORKER_THREADS = 1, + + __NFSD_A_SERVER_WORKER_MAX, + NFSD_A_SERVER_WORKER_MAX = (__NFSD_A_SERVER_WORKER_MAX - 1) +}; + enum { NFSD_CMD_RPC_STATUS_GET = 1, + NFSD_CMD_THREADS_SET, + NFSD_CMD_THREADS_GET, __NFSD_CMD_MAX, NFSD_CMD_MAX = (__NFSD_CMD_MAX - 1) -- 2.44.0