From patchwork Mon Jan 27 21:50:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13951755 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 CB27B1C5F13 for ; Mon, 27 Jan 2025 21:50:21 +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=1738014621; cv=none; b=KazUYR6lu2blkncaiCb25PcIZd/cM2pEADsCkLGpB27DF1VuFJ7n9MdRpJthTm8Q2Rv0JUcDq3NsOdYZMRERhvUeWEMWe5gALGTjlmKeHTzmSQus9Wc8OspYzOEbTBmm4VmpLUF6kMhwxAzQ4NktHu0+bqudnBhSwdSOMWDsqek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738014621; c=relaxed/simple; bh=V2zE9tB1Mo8K52AFDQE2/bkiWId9FRqyOcRK8qOur2s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KkJQMYQKFdLogmgY0/TNmBfXTl+8bJ3JZHdHzT0vCbC4FInhDEGudbomjy0FcIWFGtJ3l34obVS145qAlCxXzCR1dHg3c/E36veu0gDeK45T8xUw/Sih5iykj6bpOWSWy8Y67xDfRMavFPgYo9BlDCGWPvTc9ByfU+IZZanvbQc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=soNqyQNe; 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="soNqyQNe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF7CAC4CEE3; Mon, 27 Jan 2025 21:50:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738014621; bh=V2zE9tB1Mo8K52AFDQE2/bkiWId9FRqyOcRK8qOur2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=soNqyQNenW3eS8g6NfHcAOoLtgCiAcik9S4mIHt+fBbb83W+VUnjoUr7KV3s/qePB yVdu9Z1zXjrQjrR7O9rlCEDdSOMz29/8RmBGIUbChXAAvYazWFn8oIZiImlgZ5UbQI FO1PGJxBF2jbO1/fnZc4BrM61wDlN+Eo6MO7b9z1GI3oYF0Lc9YoO+yMx17nO9XBUb CNXPbD17KdEsIMhdMd/8pOOvcxT3c5EO7jv6xUVT0v/GF6yJH81DTKO3rSl8/I6ptL Z5eeADZA19kIrKfRASzEepxFuACyXKOfbyfM2p+CQAkcoCQwq5XzZ1UUVGNCTF7kWl QYsNqfgNlaWZg== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH v2 1/5] NFS: Add implid to sysfs Date: Mon, 27 Jan 2025 16:50:15 -0500 Message-ID: <20250127215019.352509-2-anna@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250127215019.352509-1-anna@kernel.org> References: <20250127215019.352509-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Anna Schumaker The Linux NFS server added support for returning this information during an EXCHANGE_ID in Linux v6.13. This is something and admin might want to query, so let's add it to sysfs. Signed-off-by: Anna Schumaker --- v2: * Removed accidentally included (but commented out) code block * Unconditionally display the files (with empty contents) for NFS v4.1, even if the server does not set these values. --- fs/nfs/sysfs.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c index 7b59a40d40c0..b30401b2c939 100644 --- a/fs/nfs/sysfs.c +++ b/fs/nfs/sysfs.c @@ -272,6 +272,38 @@ shutdown_store(struct kobject *kobj, struct kobj_attribute *attr, static struct kobj_attribute nfs_sysfs_attr_shutdown = __ATTR_RW(shutdown); +#if IS_ENABLED(CONFIG_NFS_V4_1) +static ssize_t +implid_domain_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct nfs_server *server = container_of(kobj, struct nfs_server, kobj); + struct nfs41_impl_id *impl_id = server->nfs_client->cl_implid; + + if (!impl_id || strlen(impl_id->domain) == 0) + return 0; //sysfs_emit(buf, ""); + return sysfs_emit(buf, "%s\n", impl_id->domain); +} + +static struct kobj_attribute nfs_sysfs_attr_implid_domain = __ATTR_RO(implid_domain); + + +static ssize_t +implid_name_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct nfs_server *server = container_of(kobj, struct nfs_server, kobj); + struct nfs41_impl_id *impl_id = server->nfs_client->cl_implid; + + if (!impl_id || strlen(impl_id->name) == 0) + return 0; //sysfs_emit(buf, ""); + return sysfs_emit(buf, "%s\n", impl_id->name); +} + +static struct kobj_attribute nfs_sysfs_attr_implid_name = __ATTR_RO(implid_name); + +#endif /* IS_ENABLED(CONFIG_NFS_V4_1) */ + #define RPC_CLIENT_NAME_SIZE 64 void nfs_sysfs_link_rpc_client(struct nfs_server *server, @@ -309,6 +341,32 @@ static struct kobj_type nfs_sb_ktype = { .child_ns_type = nfs_netns_object_child_ns_type, }; +#if IS_ENABLED(CONFIG_NFS_V4_1) +static void nfs_sysfs_add_nfsv41_server(struct nfs_server *server) +{ + int ret; + + if (!server->nfs_client->cl_implid) + return; + + ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_implid_domain.attr, + nfs_netns_server_namespace(&server->kobj)); + if (ret < 0) + pr_warn("NFS: sysfs_create_file_ns for server-%d failed (%d)\n", + server->s_sysfs_id, ret); + + ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_implid_name.attr, + nfs_netns_server_namespace(&server->kobj)); + if (ret < 0) + pr_warn("NFS: sysfs_create_file_ns for server-%d failed (%d)\n", + server->s_sysfs_id, ret); +} +#else /* CONFIG_NFS_V4_1 */ +static inline void nfs_sysfs_add_nfsv41_server(struct nfs_server *server) +{ +} +#endif /* CONFIG_NFS_V4_1 */ + void nfs_sysfs_add_server(struct nfs_server *server) { int ret; @@ -325,6 +383,8 @@ void nfs_sysfs_add_server(struct nfs_server *server) if (ret < 0) pr_warn("NFS: sysfs_create_file_ns for server-%d failed (%d)\n", server->s_sysfs_id, ret); + + nfs_sysfs_add_nfsv41_server(server); } EXPORT_SYMBOL_GPL(nfs_sysfs_add_server); From patchwork Mon Jan 27 21:50:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13951756 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 6E0791C5F13 for ; Mon, 27 Jan 2025 21:50:21 +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=1738014622; cv=none; b=o+OuELiYblCsgB3IoBIWPXPXQGEK6FYdJ7KtERilbQAwcFQuSDaHXio20KzolLal1Sj8iznxNi81rtffEtZwBRLbI23XlOJwCBrSrdivaHQj0oJyqXNf2X3qFBDh2lWZekGYsVW64gfh+JmhGxxERcnjOR75kRWgprbtGb4U96Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738014622; c=relaxed/simple; bh=LW++IZXmbaSsERqMxIOWwEVGWj0Uk6rC4ec5eXtd/k4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Go3yiLkVrubSAJ3gfXwnBu9Xx+VCsMn7Hr9YGBXvdKsjnkokyorQVSx0WFYPuLTaotRIy8dmKb1C/jKodk14QuIC6N7ddjo4gzDGs1Uf2By9hhOc4H00qHum9O5UsdSo+6wPbCeDIJFIZXFBW00uyq0E6H1CR0CWShAsICzJH+8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Gx7E6hyg; 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="Gx7E6hyg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 848C6C4CED2; Mon, 27 Jan 2025 21:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738014621; bh=LW++IZXmbaSsERqMxIOWwEVGWj0Uk6rC4ec5eXtd/k4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gx7E6hygCKad368/1SRsizo3Uivmt3SJfVLs9OdEP9covaz6IdsyUka7o0QzRq57b N8YG6Wyk7eqIiVhCoUk0qZBuZPB3t0vuQlgP13bcgv1Td+XEgHxBpSGxYfQKAW8y2L zVmJxZXrTWyeUJAeiAJCEBVD1d7cCnkXjDx4J6ukPSea8iQLRiDl2BeMzFATbJhuZ2 A2Eq7P8QjrYLqYoSh06zZjn2MI2Q7HTHnQCZxgyXU58NtvF7aEkMLcLt/7osmsolVa xcFoU76DhGJgLOte92WsPZ7SCHabDmJkuc+s/hWXX2nt6SxaBmCPPRtF/GoJtOzY1F 6fxxLlr6PfZSw== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH v2 2/5] sunrpc: Add a sysfs attr for xprtsec Date: Mon, 27 Jan 2025 16:50:16 -0500 Message-ID: <20250127215019.352509-3-anna@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250127215019.352509-1-anna@kernel.org> References: <20250127215019.352509-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Anna Schumaker This allows the admin to check the TLS configuration for each xprt. Signed-off-by: Anna Schumaker --- net/sunrpc/sysfs.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index 5c8ecdaaa985..dc3b7cd70000 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -129,6 +129,31 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj, return ret; } +static const char *xprtsec_strings[] = { + [RPC_XPRTSEC_NONE] = "none", + [RPC_XPRTSEC_TLS_ANON] = "tls-anon", + [RPC_XPRTSEC_TLS_X509] = "tls-x509", +}; + +static ssize_t rpc_sysfs_xprt_xprtsec_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj); + ssize_t ret; + + if (!xprt) { + ret = sprintf(buf, "\n"); + goto out; + } + + ret = sprintf(buf, "%s\n", xprtsec_strings[xprt->xprtsec.policy]); + xprt_put(xprt); +out: + return ret; + +} + static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -404,6 +429,9 @@ static struct kobj_attribute rpc_sysfs_xprt_dstaddr = __ATTR(dstaddr, static struct kobj_attribute rpc_sysfs_xprt_srcaddr = __ATTR(srcaddr, 0644, rpc_sysfs_xprt_srcaddr_show, NULL); +static struct kobj_attribute rpc_sysfs_xprt_xprtsec = __ATTR(xprtsec, + 0644, rpc_sysfs_xprt_xprtsec_show, NULL); + static struct kobj_attribute rpc_sysfs_xprt_info = __ATTR(xprt_info, 0444, rpc_sysfs_xprt_info_show, NULL); @@ -413,6 +441,7 @@ static struct kobj_attribute rpc_sysfs_xprt_change_state = __ATTR(xprt_state, static struct attribute *rpc_sysfs_xprt_attrs[] = { &rpc_sysfs_xprt_dstaddr.attr, &rpc_sysfs_xprt_srcaddr.attr, + &rpc_sysfs_xprt_xprtsec.attr, &rpc_sysfs_xprt_info.attr, &rpc_sysfs_xprt_change_state.attr, NULL, From patchwork Mon Jan 27 21:50:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13951757 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 8B9751D9329 for ; Mon, 27 Jan 2025 21:50:22 +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=1738014622; cv=none; b=G81oVL76K3N6AGOvoNdMGgJ63Y1SD3+9YWJ3KhomCc4zke4Ro98t3qxIINsNR9IiPRvW9B068zJTVp82mpx3oeY4lU/scegG4Pzcwd9tOLQHTK25RumqnUlpzg8bJND3d0aYdU0IDIZ8ZhTWTQdDNo1mk+E3XHCUVRZoSqemV1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738014622; c=relaxed/simple; bh=dBJ63pYa3Itg2TxqewLKklUTbSNfWuJZ0jQYbo2KwKI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ulmsKd/UF8tbaqPjxn/VhqiV1Noa+w42q2kWvf4ArIJ3E+lU9Y6QS2Kn+/G0UpYcSpL5Jscnpq2PiP6O699I6Kx8h/PYnLUuwzrx0gMowASKykM7lnuisXKPTaa0wcePtgwAwDt/fUHwGCA7JLJX1n1i/dl/bRkgAG86ciaK3kU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MwvuRTx5; 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="MwvuRTx5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A186C4CEE0; Mon, 27 Jan 2025 21:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738014622; bh=dBJ63pYa3Itg2TxqewLKklUTbSNfWuJZ0jQYbo2KwKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MwvuRTx5AhMEASq23Ks/mnLbaTbdKpLLSu5vty24sxmZutrwhmES0IqHJ5Zd/ZOdw NYdgd0TdbfUbsdS31Dy+8qmUS+avRvV5fQi64NYVBY5k4Ea8vEqOKBnXgcvkBXdygc ViwtGr8zk2TX9oSIJxNlGyJTF1fmi0srI/xNzWZ39SlH1/CnVvyyH33YPMijGSDgOb d0ol6TySI/3KDLqvaLrwin8fAqOcREdDGA8oda0/95y/YfgTVPD/siZkwKkPQPD25z lhBZDKpgrEqV57coTuMuAvlKsuHFcA5NrsBSS3fscRlxkBV1uxleHBo5yu0IZO6rIA lJKMNCciCJU4A== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH v2 3/5] sunrpc: Add a sysfs files for rpc_clnt information Date: Mon, 27 Jan 2025 16:50:17 -0500 Message-ID: <20250127215019.352509-4-anna@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250127215019.352509-1-anna@kernel.org> References: <20250127215019.352509-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Anna Schumaker These files display useful information about the RPC client, such as the rpc version number, program name, and maximum number of connections allowed. Signed-off-by: Anna Schumaker --- net/sunrpc/sysfs.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index dc3b7cd70000..0d382ab24f1f 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -59,6 +59,16 @@ static struct kobject *rpc_sysfs_object_alloc(const char *name, return NULL; } +static inline struct rpc_clnt * +rpc_sysfs_client_kobj_get_clnt(struct kobject *kobj) +{ + struct rpc_sysfs_client *c = container_of(kobj, + struct rpc_sysfs_client, kobject); + struct rpc_clnt *ret = c->clnt; + + return refcount_inc_not_zero(&ret->cl_count) ? ret : NULL; +} + static inline struct rpc_xprt * rpc_sysfs_xprt_kobj_get_xprt(struct kobject *kobj) { @@ -86,6 +96,51 @@ rpc_sysfs_xprt_switch_kobj_get_xprt(struct kobject *kobj) return xprt_switch_get(x->xprt_switch); } +static ssize_t rpc_sysfs_clnt_version_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj); + ssize_t ret; + + if (!clnt) + return sprintf(buf, "\n"); + + ret = sprintf(buf, "%u", clnt->cl_vers); + refcount_dec(&clnt->cl_count); + return ret; +} + +static ssize_t rpc_sysfs_clnt_program_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj); + ssize_t ret; + + if (!clnt) + return sprintf(buf, "\n"); + + ret = sprintf(buf, "%s", clnt->cl_program->name); + refcount_dec(&clnt->cl_count); + return ret; +} + +static ssize_t rpc_sysfs_clnt_max_connect_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj); + ssize_t ret; + + if (!clnt) + return sprintf(buf, "\n"); + + ret = sprintf(buf, "%u\n", clnt->cl_max_connect); + refcount_dec(&clnt->cl_count); + return ret; +} + static ssize_t rpc_sysfs_xprt_dstaddr_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) @@ -423,6 +478,23 @@ static const void *rpc_sysfs_xprt_namespace(const struct kobject *kobj) kobject)->xprt->xprt_net; } +static struct kobj_attribute rpc_sysfs_clnt_version = __ATTR(rpc_version, + 0444, rpc_sysfs_clnt_version_show, NULL); + +static struct kobj_attribute rpc_sysfs_clnt_program = __ATTR(program, + 0444, rpc_sysfs_clnt_program_show, NULL); + +static struct kobj_attribute rpc_sysfs_clnt_max_connect = __ATTR(max_connect, + 0644, rpc_sysfs_clnt_max_connect_show, NULL); + +static struct attribute *rpc_sysfs_rpc_clnt_attrs[] = { + &rpc_sysfs_clnt_version.attr, + &rpc_sysfs_clnt_program.attr, + &rpc_sysfs_clnt_max_connect.attr, + NULL, +}; +ATTRIBUTE_GROUPS(rpc_sysfs_rpc_clnt); + static struct kobj_attribute rpc_sysfs_xprt_dstaddr = __ATTR(dstaddr, 0644, rpc_sysfs_xprt_dstaddr_show, rpc_sysfs_xprt_dstaddr_store); @@ -459,6 +531,7 @@ ATTRIBUTE_GROUPS(rpc_sysfs_xprt_switch); static const struct kobj_type rpc_sysfs_client_type = { .release = rpc_sysfs_client_release, + .default_groups = rpc_sysfs_rpc_clnt_groups, .sysfs_ops = &kobj_sysfs_ops, .namespace = rpc_sysfs_client_namespace, }; From patchwork Mon Jan 27 21:50:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13951758 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 7D95B1D9329 for ; Mon, 27 Jan 2025 21:50:23 +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=1738014623; cv=none; b=XV87rmP6W2kmXiSchnWQVVPsVO1xNiZFM/F7x5HFKY1dg3YUKTOXGSgBdtMplDzmWBxA2g6yifjDmQdlBrMcjGbyOzhnCBjynjnNC3N32b+v8k99AN8MGbIOOksPYN9d5L6azuXSVB0S35zwZpM/l8U3ijdFr58pcmATy43CrWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738014623; c=relaxed/simple; bh=xRQuDPhyQq1ZosU+wo+72DlP+nNAzYLH3QpIu51tlSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uumJ2AmuB5eOut3EDAkSh3zwnhhJlzr0+W2AuPsmaQDWMIt+GTImazsq/VCXCwUDbLg2SkNovduCHkosjH35rZzFJLPfK68Cj12HVPKoE874ErvRMedQpl3pbg2tO/F6VXT1TIJ8NyIfntF6wu3laymip6gc1SnoUtSaC0R8jec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lzgG0mHQ; 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="lzgG0mHQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A41AAC4CEE2; Mon, 27 Jan 2025 21:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738014623; bh=xRQuDPhyQq1ZosU+wo+72DlP+nNAzYLH3QpIu51tlSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lzgG0mHQf2fTyVVkGJ1L9BCMhWv7EDCyBRm/vU4VZO6ikk5YeC5a9Hvp3B9ZgSFl9 wcMCaaUqUidwTaBNI7fM0CjoI+oSBcWktL2gc7qFAHWFKnkv95IiX6TX6tlII+G/uJ gR0+A3vAUBCGyldwb0AVJ+mq55JwdINOrqMiaCn6qaNQXnmLtRajxk4ag7j4TOtQuw 0trQLAYSZDNmdyCeDEzkc4YUgVC3bWxG/n3/YYYIhQ9M/3uJIuCf3GGiKDYgT+CTF1 PL3pZlS7b1uIOXPE/XF6F7g9UCxNkYEGKB3OM4DSFhajo6jV2/jP/88uDJmSY3595T immgELKtwcwRQ== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH v2 4/5] sunrpc: Add a sysfs file for adding a new xprt Date: Mon, 27 Jan 2025 16:50:18 -0500 Message-ID: <20250127215019.352509-5-anna@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250127215019.352509-1-anna@kernel.org> References: <20250127215019.352509-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Anna Schumaker Writing to this file will clone the 'main' xprt of an xprt_switch and add it to be used as an additional connection. Signed-off-by: Anna Schumaker --- v2: Rename the new file to add_xprt --- include/linux/sunrpc/xprtmultipath.h | 1 + net/sunrpc/sysfs.c | 54 ++++++++++++++++++++++++++++ net/sunrpc/xprtmultipath.c | 21 +++++++++++ 3 files changed, 76 insertions(+) diff --git a/include/linux/sunrpc/xprtmultipath.h b/include/linux/sunrpc/xprtmultipath.h index c0514c684b2c..c827c6ef0bc5 100644 --- a/include/linux/sunrpc/xprtmultipath.h +++ b/include/linux/sunrpc/xprtmultipath.h @@ -56,6 +56,7 @@ extern void rpc_xprt_switch_add_xprt(struct rpc_xprt_switch *xps, struct rpc_xprt *xprt); extern void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps, struct rpc_xprt *xprt, bool offline); +extern struct rpc_xprt *rpc_xprt_switch_get_main_xprt(struct rpc_xprt_switch *xps); extern void xprt_iter_init(struct rpc_xprt_iter *xpi, struct rpc_xprt_switch *xps); diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index 0d382ab24f1f..a9d155a2b0ea 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -305,6 +305,55 @@ static ssize_t rpc_sysfs_xprt_switch_info_show(struct kobject *kobj, return ret; } +static ssize_t rpc_sysfs_xprt_switch_add_xprt_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + return sprintf(buf, "# add one xprt to this xprt_switch\n"); +} + +static ssize_t rpc_sysfs_xprt_switch_add_xprt_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct rpc_xprt_switch *xprt_switch = + rpc_sysfs_xprt_switch_kobj_get_xprt(kobj); + struct xprt_create xprt_create_args; + struct rpc_xprt *xprt, *new; + + if (!xprt_switch) + return 0; + + xprt = rpc_xprt_switch_get_main_xprt(xprt_switch); + if (!xprt) + goto out; + + xprt_create_args.ident = xprt->xprt_class->ident; + xprt_create_args.net = xprt->xprt_net; + xprt_create_args.dstaddr = (struct sockaddr *)&xprt->addr; + xprt_create_args.addrlen = xprt->addrlen; + xprt_create_args.servername = xprt->servername; + xprt_create_args.bc_xprt = xprt->bc_xprt; + xprt_create_args.xprtsec = xprt->xprtsec; + xprt_create_args.connect_timeout = xprt->connect_timeout; + xprt_create_args.reconnect_timeout = xprt->max_reconnect_timeout; + + new = xprt_create_transport(&xprt_create_args); + if (IS_ERR_OR_NULL(new)) { + count = PTR_ERR(new); + goto out_put_xprt; + } + + rpc_xprt_switch_add_xprt(xprt_switch, new); + xprt_put(new); + +out_put_xprt: + xprt_put(xprt); +out: + xprt_switch_put(xprt_switch); + return count; +} + static ssize_t rpc_sysfs_xprt_dstaddr_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) @@ -523,8 +572,13 @@ ATTRIBUTE_GROUPS(rpc_sysfs_xprt); static struct kobj_attribute rpc_sysfs_xprt_switch_info = __ATTR(xprt_switch_info, 0444, rpc_sysfs_xprt_switch_info_show, NULL); +static struct kobj_attribute rpc_sysfs_xprt_switch_add_xprt = + __ATTR(add_xprt, 0644, rpc_sysfs_xprt_switch_add_xprt_show, + rpc_sysfs_xprt_switch_add_xprt_store); + static struct attribute *rpc_sysfs_xprt_switch_attrs[] = { &rpc_sysfs_xprt_switch_info.attr, + &rpc_sysfs_xprt_switch_add_xprt.attr, NULL, }; ATTRIBUTE_GROUPS(rpc_sysfs_xprt_switch); diff --git a/net/sunrpc/xprtmultipath.c b/net/sunrpc/xprtmultipath.c index 720d3ba742ec..a07b81ce93c3 100644 --- a/net/sunrpc/xprtmultipath.c +++ b/net/sunrpc/xprtmultipath.c @@ -92,6 +92,27 @@ void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps, xprt_put(xprt); } +/** + * rpc_xprt_switch_get_main_xprt - Get the 'main' xprt for an xprt switch. + * @xps: pointer to struct rpc_xprt_switch. + */ +struct rpc_xprt *rpc_xprt_switch_get_main_xprt(struct rpc_xprt_switch *xps) +{ + struct rpc_xprt_iter xpi; + struct rpc_xprt *xprt; + + xprt_iter_init_listall(&xpi, xps); + + xprt = xprt_iter_get_xprt(&xpi); + while (xprt && !xprt->main) { + xprt_put(xprt); + xprt = xprt_iter_get_next(&xpi); + } + + xprt_iter_destroy(&xpi); + return xprt; +} + static DEFINE_IDA(rpc_xprtswitch_ids); void xprt_multipath_cleanup_ids(void) From patchwork Mon Jan 27 21:50:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13951759 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 08CB71DA617 for ; Mon, 27 Jan 2025 21:50:23 +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=1738014624; cv=none; b=ToD8tYaMmBtEFFe8pR/vvo6zXlA4l8qgk+t40PbUrbrqNK+gavyTCX19ItFfFrL2LHsP/L+oAvDlnR5alAkrA31iOYyx2bC/NEL6HFCGfeB4y9g4qQezNw2UXWzocbZOrUD5JUG9u6PhmAsqZuEiucpEXePMxGFB3QFa2q6OeQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738014624; c=relaxed/simple; bh=YPLOQszizsGFDDLzcx2A+ERk187aWgDFqdDxBnlzllI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jphJXZsYFPuN5eq6HlesuCxeq3HuMJf9GSKb3G0IQBidQhqKv819RtK1+J4TQGM3bgzjhHHTfv/+1jU/uSgBjW1hzLnbv1db1rKhxIwmWMIOE5Zt//yJhNZHbNn0wuyUZ7VFQkbTx2sy8p7JhAwJDhwosGWr0n3rQ9UwQ4/stHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LhUr79/k; 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="LhUr79/k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39247C4CEE0; Mon, 27 Jan 2025 21:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738014623; bh=YPLOQszizsGFDDLzcx2A+ERk187aWgDFqdDxBnlzllI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LhUr79/kOgrSdk58vocdmoXHfjF+bAOOD7ztDWYw6c1nqTSpve+DcyN8z/mBNVbEw 81ZyTck4aijcObjKm/6GXSuQKro6+MDwvVgJGsUFbXsowmmy/ZofNRmMQfupV1xrRG xYSaYk2fUqATB5iGL8mnZAh6DKItdjSsZtJh5XUXI0LCv53Z/spl4fgwXNfKJg0xhz opi0EuObNZl9RlPhYeFyTYXvQTCGEUp00ZG1YVS3T15EpJqIvBxWBLYPSN+w5WpHXo MdGN/6C5FZpIbjuCdoq0yVa6+aw1+F/htMUbSf+9tyO4AKLfr5IlFHddnCBJOJvuZr VnT2W1t7q7HGw== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH v2 5/5] sunrpc: Add a sysfs file for one-step xprt deletion Date: Mon, 27 Jan 2025 16:50:19 -0500 Message-ID: <20250127215019.352509-6-anna@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250127215019.352509-1-anna@kernel.org> References: <20250127215019.352509-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Anna Schumaker Previously, the admin would need to set the xprt state to "offline" before attempting to remove. This patch adds a new sysfs attr that does both these steps in a single call. Suggested-by: Benjamin Coddington Signed-off-by: Anna Schumaker --- net/sunrpc/sysfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index a9d155a2b0ea..1e1cb2b3c51a 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -286,6 +286,14 @@ static ssize_t rpc_sysfs_xprt_state_show(struct kobject *kobj, return ret; } +static ssize_t rpc_sysfs_xprt_del_xprt_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + return sprintf(buf, "# delete this xprt\n"); +} + + static ssize_t rpc_sysfs_xprt_switch_info_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) @@ -464,6 +472,40 @@ static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj, return count; } +static ssize_t rpc_sysfs_xprt_del_xprt(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj); + struct rpc_xprt_switch *xps = rpc_sysfs_xprt_kobj_get_xprt_switch(kobj); + + if (!xprt || !xps) { + count = 0; + goto out; + } + + if (xprt->main) { + count = -EINVAL; + goto release_tasks; + } + + if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE)) { + count = -EINTR; + goto out_put; + } + + xprt_set_offline_locked(xprt, xps); + xprt_delete_locked(xprt, xps); + +release_tasks: + xprt_release_write(xprt, NULL); +out_put: + xprt_put(xprt); + xprt_switch_put(xps); +out: + return count; +} + int rpc_sysfs_init(void) { rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj); @@ -559,12 +601,16 @@ static struct kobj_attribute rpc_sysfs_xprt_info = __ATTR(xprt_info, static struct kobj_attribute rpc_sysfs_xprt_change_state = __ATTR(xprt_state, 0644, rpc_sysfs_xprt_state_show, rpc_sysfs_xprt_state_change); +static struct kobj_attribute rpc_sysfs_xprt_del = __ATTR(del_xprt, + 0644, rpc_sysfs_xprt_del_xprt_show, rpc_sysfs_xprt_del_xprt); + static struct attribute *rpc_sysfs_xprt_attrs[] = { &rpc_sysfs_xprt_dstaddr.attr, &rpc_sysfs_xprt_srcaddr.attr, &rpc_sysfs_xprt_xprtsec.attr, &rpc_sysfs_xprt_info.attr, &rpc_sysfs_xprt_change_state.attr, + &rpc_sysfs_xprt_del.attr, NULL, }; ATTRIBUTE_GROUPS(rpc_sysfs_xprt);