net/smc: Introduce SMC-related proc files
Wen Gu
reviewerRFC PATCH 1/1 net/smc: Introduce SMC-related proc files
This patch introduces /proc/net/smc4 and /proc/net/smc6 files to report statistic information of SMC connections.
Compared with 'smcss' command in smc-tools, getting SMC connections via proc files is not efficient. However, in some container scenarios, some dependencies are lacked for compiling and using smc-tools. In this case, using proc files to check SMC connections becomes a simple and fast way.
--- include/net/smc.h | 5 +- net/smc/Makefile | 2 +- net/smc/af_smc.c | 22 ++++- net/smc/smc_diag.c | 29 +++--- net/smc/smc_proc.c | 283 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_proc.h | 35 +++++++ 6 files changed, 355 insertions(+), 21 deletions(-) create mode 100644 net/smc/smc_proc.c create mode 100644 net/smc/smc_proc.h
include/net/smc.h +4 -1
@@ -20,10 +20,13 @@struct sock ;#define SMC_MAX_PNETID_LEN 16/* Max. length of PNET id */ +#define SMC_HTABLE_SHIFT 9 +#define SMC_HTABLE_SIZE (1 << SMC_HTABLE_SHIFT)/* Size of SMC hashtable buckets */ struct smc_hashinfo { +unsigned int bkt_idx;rwlock_t lock; -struct hlist_head ht; +struct hlist_head ht[SMC_HTABLE_SIZE ]; };int smc_hash_sk (struct sock *sk);
net/smc/Makefile +1 -1
@@ -4,5 +4,5 @@ obj-$(CONFIG_SMC) += smc.o obj-$(CONFIG_SMC_DIAG) += smc_diag.o smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o smc-y += smc_cdc.o smc_tx.o smc_rx.o smc_close.o smc_ism.o smc_netlink.o smc_stats.o -smc-y += smc_tracepoint.o +smc-y += smc_tracepoint.o smc_proc.o smc-$(CONFIG_SYSCTL) += smc_sysctl.o
net/smc/af_smc.c +17 -5
@@ -53,6 +53,7 @@#include "smc_stats.h" #include "smc_tracepoint.h" #include "smc_sysctl.h" +#include "smc_proc.h" static DEFINE_MUTEX (smc_server_lgr_pending);/* serialize link group * creation on server
@@ -182,9 +183,8 @@ int smc_hash_sk(struct sock *sk)struct smc_hashinfo *h = sk->sk_prot->h.smc_hash;struct hlist_head *head; - head = &h->ht; -write_lock_bh (&h->lock); + head = &h->ht[h->bkt_idx++ & (SMC_HTABLE_SIZE -1 )];sk_add_node (sk, head);write_unlock_bh (&h->lock);sock_prot_inuse_add (sock_net (sk), sk->sk_prot,1 );
@@ -3448,7 +3448,7 @@ static void __net_exit smc_net_stat_exit(struct net *net)static int __init smc_init (void ) { -int rc; +int rc, i; rc =register_pernet_subsys (&smc_net_ops);if (rc)
@@ -3520,8 +3520,11 @@ static int __init smc_init(void)pr_err ("%s: sock_register fails with %d\n" , __func__, rc); goto out_proto6; } -INIT_HLIST_HEAD (&smc_v4_hashinfo.ht); -INIT_HLIST_HEAD (&smc_v6_hashinfo.ht); + +for (i =0 ; i <SMC_HTABLE_SIZE ; i++) { +INIT_HLIST_HEAD (&smc_v4_hashinfo.ht[i]); +INIT_HLIST_HEAD (&smc_v6_hashinfo.ht[i]); + } rc =smc_ib_register_client ();if (rc) {
@@ -3535,9 +3538,17 @@ static int __init smc_init(void) goto out_ib; } + rc =smc_proc_init (); +if (rc) { +pr_err ("%s: smc_proc_init fails with %d\n" , __func__, rc); + goto out_ulp; + } +static_branch_enable (&tcp_have_smc);return 0 ; +out_ulp: +tcp_unregister_ulp (&smc_ulp_ops); out_ib:smc_ib_unregister_client (); out_sock:
@@ -3572,6 +3583,7 @@ static int __init smc_init(void) static void __exit smc_exit(void) {static_branch_disable (&tcp_have_smc); +smc_proc_exit ();tcp_unregister_ulp (&smc_ulp_ops);sock_unregister (PF_SMC );smc_core_exit ();
net/smc/smc_diag.c +15 -14
@@ -197,24 +197,25 @@ static int smc_diag_dump_proto(struct proto *prot, struct sk_buff *skb,int snum = cb_ctx->pos[p_type];struct nlattr *bc =NULL ;struct hlist_head *head; -int rc =0 , num =0 ; +int rc =0 , num =0 , slot;struct sock *sk;read_lock (&prot->h.smc_hash->lock); - head = &prot->h.smc_hash->ht; -if (hlist_empty (head)) - goto out; - -sk_for_each (sk, head) { -if (!net_eq (sock_net (sk), net)) -continue ; -if (num < snum) - goto next; - rc =__smc_diag_dump (sk, skb, cb,nlmsg_data (cb->nlh), bc); -if (rc <0 ) - goto out; + +for (slot =0 ; slot <SMC_HTABLE_SIZE ; slot++) { + head = &prot->h.smc_hash->ht[slot]; + +sk_for_each (sk, head) { +if (!net_eq (sock_net (sk), net)) +continue ; +if (num < snum) + goto next; + rc =__smc_diag_dump (sk, skb, cb,nlmsg_data (cb->nlh), bc); +if (rc <0 ) + goto out; next: - num++; + num++; + } } out:
net/smc/smc_proc.c new file +283 -0
283 lines not on this page · raw message
net/smc/smc_proc.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _SMC_PROC_H_ +#define _SMC_PROC_H_ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/sysctl.h> +#include <net/sock.h> +#include <net/net_namespace.h> +#include "smc.h" + +#define CONN4_HDR ("%4s: %-14s%-14s%-3s%-9s%-17s%-17s%-3s%-8s%-9s%-3s%-2s%-2s\n") +#define CONN6_HDR ("%4s: %-38s%-38s%-3s%-9s%-17s%-17s%-3s%-8s%-9s%-3s%-2s%-2s\n") +#define CONN4_ADDR_FORMAT ("%4d: %08X:%04X %08X:%04X") +#define CONN6_ADDR_FORMAT ("%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X") +#define CONN_SK_FORMAT (" %c %08X %pK %pK %2d %-7lu ") +#define CONN_LGR_FORMAT (" %-2s %c %c") +#define CONN_SMCR_EXT (" %-8s %02d %-4X %-4X") + +struct smc_proc_private { +struct seq_net_private p; +int num, bucket, offset; +int protocol; +loff_t last_pos; +}; + +struct smc_proc_entry { +const char *name; +const struct seq_operations ops; +}; + +int __init smc_proc_init (void ); +void smc_proc_exit (void ); + +#endif
Signature · 1 line
1.8.3.1
Quoted 17 lines · Wen Gu
This patch introduces
/proc/net/smc4and/proc/net/smc6files to report statistic information of SMC connections.Compared with 'smcss' command in smc-tools, getting SMC connections via proc files is not efficient. However, in some container scenarios, some dependencies are lacked for compiling and using smc-tools. In this case, using proc files to check SMC connections becomes a simple and fast way.
Signed-off-by Wen Gu <[email protected]>--- include/net/smc.h | 5 +- net/smc/Makefile | 2 +- net/smc/af_smc.c | 22 ++++- net/smc/smc_diag.c | 29 +++--- net/smc/smc_proc.c | 283 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_proc.h | 35 +++++++ 6 files changed, 355 insertions(+), 21 deletions(-)
Quoted 3 lines
create mode 100644
net/smc/smc_proc.c
create mode 100644net/smc/smc_proc.h
Hi Wen,
I can understand your problem and frustration. However, there are two reasons I'm not really convinced by the proc file method:
1) AFAI, the proc method could consume many CPU time especially in case with a log of sockets to read the pseudo files.
2) We have already implemented the complex netlink method on the same purpose. I see the double expense to main the code.
Then the question is if the lack of dependency issue can be handle somehow, or the proc method is the only way to achieve this purpose?
Any opinion is welcome!
Thanks,
Wenjia
Wen Gu
reviewerQuoted 9 lines · Wenjia Zhang
Hi Wen,
I can understand your problem and frustration. However, there are two reasons I'm not really convinced by the proc file method:
1) AFAI, the proc method could consume many CPU time especially in case with a log of sockets to read the pseudo files.
2) We have already implemented the complex netlink method on the same purpose. I see the double expense to main the code.
Quoted 6 lines
Then the question is if the lack of dependency issue can be handle somehow, or the proc method is the only way to achieve this purpose?
Any opinion is welcome!
Thanks,
Wenjia
Hi, Wenjia. I agree with your concerns.
My initial intention is to make these proc files serve as a supplement to netlink to conveniently check smc connections in an environment where smc-tools cannot be easily obtained.
Yes, proc files won't be the first choice for diagnosis, but can be a convenient backup.
Thanks,
Wen Gu
Quoted 21 lines · Wen Gu
Quoted 9 lines · Wenjia Zhang
Hi Wen,
I can understand your problem and frustration. However, there are two reasons I'm not really convinced by the proc file method:
1) AFAI, the proc method could consume many CPU time especially in case with a log of sockets to read the pseudo files.
2) We have already implemented the complex netlink method on the same purpose. I see the double expense to main the code.Quoted 6 lines
Then the question is if the lack of dependency issue can be handle somehow, or the proc method is the only way to achieve this purpose?
Any opinion is welcome!
Thanks,
WenjiaHi, Wenjia. I agree with your concerns.
Quoted 9 lines
My initial intention is to make these proc files serve as a supplement to netlink to conveniently check smc connections in an environment where smc-tools cannot be easily obtained.
Yes, proc files won't be the first choice for diagnosis, but can be a convenient backup.
Thanks,
Wen Gu
As /proc is an interface to userface, we would have to maintain the 2 redundant methods basically forever. I personally don't think we should implement another interface without a very strong reason.
Wen Gu
reviewerQuoted 27 lines · Alexandra Winter
Quoted 24 lines · Wen Gu
Quoted 9 lines · Wenjia Zhang
Hi Wen,
I can understand your problem and frustration. However, there are two reasons I'm not really convinced by the proc file method:
1) AFAI, the proc method could consume many CPU time especially in case with a log of sockets to read the pseudo files.
2) We have already implemented the complex netlink method on the same purpose. I see the double expense to main the code.Quoted 6 lines
Then the question is if the lack of dependency issue can be handle somehow, or the proc method is the only way to achieve this purpose?
Any opinion is welcome!
Thanks,
WenjiaHi, Wenjia. I agree with your concerns.
My initial intention is to make these proc files serve as a supplement to netlink to conveniently check smc connections in an environment where smc-tools cannot be easily obtained.
Quoted 8 lines
Quoted 6 lines
Yes, proc files won't be the first choice for diagnosis, but can be a convenient backup.
Thanks,
Wen GuAs /proc is an interface to userface, we would have to maintain the 2 redundant methods basically forever. I personally don't think we should implement another interface without a very strong reason.
I understand, thank you Alexandra and Wenjia.
Regards,
Wen Gu