From patchwork Wed Jan 8 21:36:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13931556 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 A121718D626 for ; Wed, 8 Jan 2025 21:36:34 +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=1736372195; cv=none; b=l/JR4AbwEunDd7fulBb0bMaKB3Xa/NkEKB64CEQPVaQ4X5kvAisxxxq8grikA24bT74Im558M7B4T/5iH6Ln+9nViSwxx4IFj3TPbSUaHt4CCwrHmOwLJU6l6hv/C56zD5MMkkISzNjhuccyN/7njHa+vNmLYNPlhbLVylrzY3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736372195; c=relaxed/simple; bh=L1eoayPBshlg653c5PNqUwjEenOxg4wjaADCiBWmjBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X1EvQW23c9kxVEgxYepozaU/jBdeN5MdqXyTUzcafikUuadKoV4W3mFw3Su+LQ0fkzzG9kUA58mLYNTP39Kn/Pz9FoPjV/xPyRSm7XQnvPTntb3A1jam445jFMP0qqJR6CIcXIr86gAxbkCAE64wOXWJU8Dby6VSF1HnKOwS6+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Obw3nYns; 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="Obw3nYns" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2649C4CEE1; Wed, 8 Jan 2025 21:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736372194; bh=L1eoayPBshlg653c5PNqUwjEenOxg4wjaADCiBWmjBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Obw3nYnssGJmdUy98+hIqYk1Ew9zArn7IhMhn3KUtE8fz7ffsSfRyOzS9wS0HigpS sqsyjwcourXXwC++BjBkgkoNdAyaUfLgykCqFkbLOafV7nI2Lsk3Qf30L1LhLcvyRZ UGm2zqdsUIYyFfxwCsTUCtl/ypdLZOaCgKOeAICItcvj9eQjh5v6ezO6hZdEXo0aYl XtwFnr893XSPBiy2RVMVyK/8dKD8PEr+Q4TacLDCHlCXKtjaV/rxx+gNzw9+oeOvdQ R0i8K4ANIXCH91Am3colFmtgVXJi5rPtIjc3xp42he4pjKGT8WGN82jyePv+a8pSwU E4H4nTvM2cLWA== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH 1/3] NFS: Add implid to sysfs Date: Wed, 8 Jan 2025 16:36:30 -0500 Message-ID: <20250108213632.260498-2-anna@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250108213632.260498-1-anna@kernel.org> References: <20250108213632.260498-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 --- fs/nfs/sysfs.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c index 7b59a40d40c0..6b82c92c45bf 100644 --- a/fs/nfs/sysfs.c +++ b/fs/nfs/sysfs.c @@ -272,6 +272,32 @@ 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; + 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; + 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 +335,33 @@ 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) +{ + struct nfs_client *clp = server->nfs_client; + int ret; + + if (clp->cl_implid && strlen(clp->cl_implid->domain) > 0) { + 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 +378,32 @@ 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); + +/* if (server->nfs_client->cl_serverowner) { + ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_serverowner.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); + } + + if (server->nfs_client->cl_serverscope) { + ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_serverscope.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); + } + + if (server->nfs_client->cl_implid) { + ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_implid.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); + }*/ } EXPORT_SYMBOL_GPL(nfs_sysfs_add_server); From patchwork Wed Jan 8 21:36:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13931558 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 B395E204088 for ; Wed, 8 Jan 2025 21:36:34 +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=1736372195; cv=none; b=LWF9pJY9PLCu3l350MyYeMws82eC/bIyT3xlBZfpR8evvBZF+ohhp13zxWARVZYnvmKQ64YX7IBqrMSAUWwCgeLMXn1lejkPKFwgZsRHNzEp8cytNN3fKNedchc8lWvwcXqvaZCj7ncgMZh1OinXQsguXbAiAYaz0z3+N2aN8m0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736372195; c=relaxed/simple; bh=Bc+C/cM85B8utmREyttjysNOrZ9zz9NLXY3W5HC/6XI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hxtnLhNvqgzD0Rr4O8pZH9etJyMzd3/d+3pCJvOD5I/syDinukBBdk3zMzdtagasor9UL6IaSBaFN+ap6f6sw1QpGX1WDFwHULoqwyC0mAAAdFTRIb+RLM5O3k3RDL5UAw5PsLq3rPxy7lrTqibUzbcAgRpbCZJ2EfgF+3t4YuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J1SvzkxB; 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="J1SvzkxB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69C63C4CEDF; Wed, 8 Jan 2025 21:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736372194; bh=Bc+C/cM85B8utmREyttjysNOrZ9zz9NLXY3W5HC/6XI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J1SvzkxBVfGoddU/b2aCw0r+ygmhtdrCG/lM9+ib9r1Vk9nq9BjfuPX81XkFF3pZY cNvWUfEhifGmYOpyJgLcH92U1vKvh8kVfHo1+sMYrpsQveRScorWNpfmQDjNXuT+M+ Z500tiLlSCzU5pomtiNdXoU+mEbngPhw90pRUf+ofn2v3iG63MERKpShh/nTtLtduQ tJihGpz7A4gvmzawI6a2yHOb6zLMypa82dNwLkPXjSfY/9Cwh7P5J6LItPfwtoCWTN 8gKqrVbbq/jgEdfLNTyWTCLWFk9fHkviTNY4S1vzQCkpx5Qzl+VYrvwmeWDx5jf+we atKBYocPfJkBQ== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH 2/3] sunrpc: Add a sysfs attr for xprtsec Date: Wed, 8 Jan 2025 16:36:31 -0500 Message-ID: <20250108213632.260498-3-anna@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250108213632.260498-1-anna@kernel.org> References: <20250108213632.260498-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 Wed Jan 8 21:36:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13931557 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 B39B820408A for ; Wed, 8 Jan 2025 21:36:35 +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=1736372195; cv=none; b=NZgHhfFYGnPPuZ/K7nVO0DS6OMXJ1Q9w76y41Z7xlfcBAiYHrG3b9sxqt/xRq+Dre3cJcmhLzYzN6dvj62tsmY1kqRe2fgmYmVNeca7G3WvOobvYhjKIB9aWqjgHvg1xUOlRObqDW4KaL4RUMatjos6w73a8OV2z/biH/RMc7zY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736372195; c=relaxed/simple; bh=MyXCNbnyTPJEVaJEYjeQQs5km6ICGwQITW6f87vuOeM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=liMa6YbsFQzwnPnCbJ0nt58RAbMOPmnzqf7CMkJuJAa4cCaLBkKw34Qr/kwdhED2SBhuuFb1HHOKHLQmHpr/0dcOflFfdFf+SIcNs+9f3m050ZWjq/ZVPp9KPr+jzs3ViKAgJuGOEGRiElMhfAxOj5hgaP7yCesJ2C8KClLaSUQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uAv9WFwA; 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="uAv9WFwA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02697C4CEE2; Wed, 8 Jan 2025 21:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736372195; bh=MyXCNbnyTPJEVaJEYjeQQs5km6ICGwQITW6f87vuOeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uAv9WFwA3XJGbaVaUNNQAZN0NfBER+Z6Gst7AR9HmZO1W+qfDL6kkTS6cFrjlRCDx rXYTi92XevJJnsSU2lo2MokXDFJOT614QvJJZnI+1V52kVsMmQS7zEiU4KCEkIRYaU De5nHeXxCIVdgeaYICgX07eiA6rRAoVQnvha9TUrcZgrJMZXjhkYi96H6jscH8pTK3 zINDiLkFKXY3nBWvaAK7EWCtncXkutWhS9l1MrzILQW9NUb9KpGqG6rigvFEMgxroz MA5i9IzfMc3EZWvPCjJ/pS7m8Wq3ldCd9VO2WYbXtzHkV076czGNKpBlVJJT5Kt1Sh zI4ARY5M92XZw== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH 3/3] sunrpc: Add a sysfs file for adding a new xprt Date: Wed, 8 Jan 2025 16:36:32 -0500 Message-ID: <20250108213632.260498-4-anna@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250108213632.260498-1-anna@kernel.org> References: <20250108213632.260498-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 --- 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 dc3b7cd70000..ce7dae140770 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -250,6 +250,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) @@ -451,8 +500,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(xprt_switch_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)