Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1661124lqp; Mon, 15 Apr 2024 13:01:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX/6C7L8QR16ZPX3xsBkD/hFdpkS5dF5lGT7AFRHGyhtnSw8Wb0EjxovW9EDxFVphDGjjnYE0GmTLj/7fxz0S9Th72Vg62VroVaUMkeUg== X-Google-Smtp-Source: AGHT+IEIJUqJx/mMFBlNka+zxsHbD8Ga7GZ71K7ireUqpayVfcP/xGb26GIIPj2tJHIr03x0Fe/G X-Received: by 2002:a05:6512:3083:b0:518:cfd1:cd4c with SMTP id z3-20020a056512308300b00518cfd1cd4cmr4803291lfd.10.1713211303308; Mon, 15 Apr 2024 13:01:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713211303; cv=pass; d=google.com; s=arc-20160816; b=IapaQqZ6jKYqoSy2GwGiiIA2x0JyqVTZx0ZSZFf4Y6Uvkdp24U/e5OP14d9I3rvFsY PyYRJfvNtpJfKEQdDS8Lk3nxSWxrZgtXOUjVPbYDsiRyt9YSp+2PbqDp+25cn0uMWzHP rcGmDSme23zIQb0hksbi009VDB6jn+SAbKOGRjVtJkU2VJtCA5nSxv52NwJJYDB/pYFn +eg/pqBu3As10YQz6BKtwPLxDa75eqmAz5toC8hutjSiQU5HZq+MUcD1YAo0H4wZ0/58 hMoo8O4kUlhbuBBwp9vqCxQgUft4FUGMlJa7Jwa9rh0OEqpkRjmwfK6wwgj5rgs26EUQ krYQ== 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=vOxjfJd8ABg9kP37RI4IXqyxQf1bYRvPTYzSikj3230=; fh=uaqw4UYaONZI1vwXmlZ+vlVmGAaApYn8V3wDqNrAb2o=; b=uL3Nh5HgmNgQiTVeQTwShhY+NvlkvRO0ZXdY8q9E64ID/cgULPs3MBEF9m9JIzxYuP O9CWf71NF0YxOGWUUqL7/tKAky6djbEi/P/F30sbsGUNfWweMYJIFsDDRcSqWR9uqqaP vIVaDv6ACEfZCs4o/MO5oMA2bNKWFGFTRg8PKxLQaZcSi7h6bJdRj2Pq4rl7n5Ve6DI5 t7rh04/ggVvTXtzljB+x9iCvnI4+b3jRmuUdu7BX0qH5346LG7H5fAPpvGgaQS/NVHc2 0Gt8uRmQNSJcBpSOiwdNQglmR/t4D4lFj0Mu14Jj2rnMa2urethNyOHbhp/ELsoET/ub IgyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WJJq0ioo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-2822-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2822-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x19-20020a170906b09300b00a51e4539384si5020970ejy.773.2024.04.15.13.01.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 13:01:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-2822-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WJJq0ioo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-2822-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2822-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 8C9541F22650 for ; Mon, 15 Apr 2024 19:51:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B419315B579; Mon, 15 Apr 2024 19:45:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WJJq0ioo" 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 8C29C156997; Mon, 15 Apr 2024 19:45:14 +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=1713210314; cv=none; b=FhlgL4s2wG9yy7bAOpSlxpCjTcANugpVMxF1Jx49nprCDlQgFLfBkO6K+eZKO7fFpebZiRcpOlFKeZxFHeZSetw6+wohYNc5xLeReXbQTyEc78MliQEU5e6wkx1AVdvYFXDkIn8fvyynx1+CNLzMVouM6P907iOsEQ/U1iKhyEE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713210314; c=relaxed/simple; bh=c9appUypE9UwFM2sEKyJ8H+OyIHk9lowUrJlHVql6u0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iyqzQsiD9r9LikiMkWIvJ2JHLBq60WNT+wgt52hpPVEC52YqXA6F4Jysd44C/Rm8FqNFlj2sJ05XKWwQnrOaG4LpznnSma9Tp4bVzAskWW1FxXTGPs6OgIl/fvk0CLx7B6Jkj5h+Mgo5yk4PSJqO6OHFpyJk/gUNB2gdUc9XarQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WJJq0ioo; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03CF5C113CC; Mon, 15 Apr 2024 19:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713210314; bh=c9appUypE9UwFM2sEKyJ8H+OyIHk9lowUrJlHVql6u0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WJJq0ioo7RTzKLMwDs6z06bd6imCptNi3cVb2fJVeRvW+PFB1MNIPNuIn57gj6TJI Xvbsk8rhJL/gNNgjDgy0zQXgOl7regZ5tb3BvYjaHFeXkJh/mAUwPNsUNC3ZrPnQpK kmwd9QP1eVgLyYanZ6/j3FDWabyiBkzs5pOWi1vzm36QMFO6VfguparZ3ZMm+odXHG Vn5EMDROfYpiFqDnBk/h0FPxU/kPmgvPnENjYJzEF79EG1JMSGSyGJ/S8LVnLnT7yQ 973cHRx+3AP6g13sDF8x92CtkWMLmQg5qshlv1RTUhW2iitS/cbqzIM8IWwMNmOuI+ mTYDL3EzseC1Q== From: Lorenzo Bianconi To: linux-nfs@vger.kernel.org Cc: lorenzo.bianconi@redhat.com, chuck.lever@oracle.com, neilb@suse.de, netdev@vger.kernel.org, kuba@kernel.org, jlayton@kernel.org Subject: [PATCH v8 2/6] NFSD: convert write_threads to netlink command Date: Mon, 15 Apr 2024 21:44:35 +0200 Message-ID: <4ff777ebb8652e31709bd91c3af50693edf86a26.1713209938.git.lorenzo@kernel.org> 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 Co-developed-by: Jeff Layton Signed-off-by: Jeff Layton Signed-off-by: Lorenzo Bianconi --- Documentation/netlink/specs/nfsd.yaml | 33 ++++++++ fs/nfsd/netlink.c | 19 +++++ fs/nfsd/netlink.h | 2 + fs/nfsd/nfsctl.c | 104 ++++++++++++++++++++++++++ include/uapi/linux/nfsd_netlink.h | 11 +++ 5 files changed, 169 insertions(+) diff --git a/Documentation/netlink/specs/nfsd.yaml b/Documentation/netlink/specs/nfsd.yaml index 05acc73e2e33..cbe6c5fd6c4d 100644 --- a/Documentation/netlink/specs/nfsd.yaml +++ b/Documentation/netlink/specs/nfsd.yaml @@ -62,6 +62,18 @@ attribute-sets: name: compound-ops type: u32 multi-attr: true + - + name: server-worker + attributes: + - + name: threads + type: u32 + - + name: gracetime + type: u32 + - + name: leasetime + type: u32 operations: list: @@ -87,3 +99,24 @@ 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 + - gracetime + - leasetime + - + name: threads-get + doc: get the number of running threads + attribute-set: server-worker + do: + reply: + attributes: + - threads + - gracetime + - leasetime diff --git a/fs/nfsd/netlink.c b/fs/nfsd/netlink.c index 0e1d635ec5f9..20a646af0324 100644 --- a/fs/nfsd/netlink.c +++ b/fs/nfsd/netlink.c @@ -10,6 +10,13 @@ #include +/* NFSD_CMD_THREADS_SET - do */ +static const struct nla_policy nfsd_threads_set_nl_policy[NFSD_A_SERVER_WORKER_LEASETIME + 1] = { + [NFSD_A_SERVER_WORKER_THREADS] = { .type = NLA_U32, }, + [NFSD_A_SERVER_WORKER_GRACETIME] = { .type = NLA_U32, }, + [NFSD_A_SERVER_WORKER_LEASETIME] = { .type = NLA_U32, }, +}; + /* Ops table for nfsd */ static const struct genl_split_ops nfsd_nl_ops[] = { { @@ -19,6 +26,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_LEASETIME, + .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 f2e442d7fe16..38a5df03981b 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -1653,6 +1653,110 @@ 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) +{ + struct net *net = genl_info_net(info); + struct nfsd_net *nn = net_generic(net, nfsd_net_id); + int ret = -EBUSY; + u32 nthreads; + + if (GENL_REQ_ATTR_CHECK(info, NFSD_A_SERVER_WORKER_THREADS)) + return -EINVAL; + + nthreads = nla_get_u32(info->attrs[NFSD_A_SERVER_WORKER_THREADS]); + + mutex_lock(&nfsd_mutex); + if (info->attrs[NFSD_A_SERVER_WORKER_GRACETIME] || + info->attrs[NFSD_A_SERVER_WORKER_LEASETIME]) { + const struct nlattr *attr; + + if (nn->nfsd_serv && nn->nfsd_serv->sv_nrthreads) + goto out_unlock; + + ret = -EINVAL; + attr = info->attrs[NFSD_A_SERVER_WORKER_GRACETIME]; + if (attr) { + u32 gracetime = nla_get_u32(attr); + + if (gracetime < 10 || gracetime > 3600) + goto out_unlock; + + nn->nfsd4_grace = gracetime; + } + + attr = info->attrs[NFSD_A_SERVER_WORKER_LEASETIME]; + if (attr) { + u32 leasetime = nla_get_u32(attr); + + if (leasetime < 10 || leasetime > 3600) + goto out_unlock; + + nn->nfsd4_lease = leasetime; + } + } + + ret = nfsd_svc(nthreads, net, get_current_cred()); +out_unlock: + mutex_unlock(&nfsd_mutex); + + return ret == nthreads ? 0 : ret; +} + +/** + * 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) +{ + struct net *net = genl_info_net(info); + struct nfsd_net *nn = net_generic(net, nfsd_net_id); + 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; + } + + mutex_lock(&nfsd_mutex); + err = nla_put_u32(skb, NFSD_A_SERVER_WORKER_GRACETIME, + nn->nfsd4_grace) || + nla_put_u32(skb, NFSD_A_SERVER_WORKER_LEASETIME, + nn->nfsd4_lease) || + nla_put_u32(skb, NFSD_A_SERVER_WORKER_THREADS, + nn->nfsd_serv ? nn->nfsd_serv->sv_nrthreads : 0); + mutex_unlock(&nfsd_mutex); + + if (err) { + 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..ccc78a5ee650 100644 --- a/include/uapi/linux/nfsd_netlink.h +++ b/include/uapi/linux/nfsd_netlink.h @@ -29,8 +29,19 @@ enum { NFSD_A_RPC_STATUS_MAX = (__NFSD_A_RPC_STATUS_MAX - 1) }; +enum { + NFSD_A_SERVER_WORKER_THREADS = 1, + NFSD_A_SERVER_WORKER_GRACETIME, + NFSD_A_SERVER_WORKER_LEASETIME, + + __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