Skip to content

Commit 462791b

Browse files
Dust Lidavem330
authored andcommitted
net/smc: add sysctl interface for SMC
This patch add sysctl interface to support container environment for SMC as we talk in the mail list. Link: https://lore.kernel.org/netdev/20220224020253.GF5443@linux.alibaba.com Co-developed-by: Tony Lu <tonylu@linux.alibaba.com> Signed-off-by: Tony Lu <tonylu@linux.alibaba.com> Signed-off-by: Dust Li <dust.li@linux.alibaba.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1e385c0 commit 462791b

File tree

5 files changed

+116
-1
lines changed

5 files changed

+116
-1
lines changed

include/net/netns/smc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ struct netns_smc {
1414
struct smc_stats_rsn *fback_rsn;
1515

1616
bool limit_smc_hs; /* constraint on handshake */
17+
#ifdef CONFIG_SYSCTL
18+
struct ctl_table_header *smc_hdr;
19+
#endif
1720
};
1821
#endif

net/smc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ obj-$(CONFIG_SMC) += smc.o
44
obj-$(CONFIG_SMC_DIAG) += smc_diag.o
55
smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o
66
smc-y += smc_cdc.o smc_tx.o smc_rx.o smc_close.o smc_ism.o smc_netlink.o smc_stats.o
7-
smc-y += smc_tracepoint.o
7+
smc-y += smc_tracepoint.o smc_sysctl.o

net/smc/af_smc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "smc_close.h"
5252
#include "smc_stats.h"
5353
#include "smc_tracepoint.h"
54+
#include "smc_sysctl.h"
5455

5556
static DEFINE_MUTEX(smc_server_lgr_pending); /* serialize link group
5657
* creation on server
@@ -3273,9 +3274,17 @@ static int __init smc_init(void)
32733274
goto out_sock;
32743275
}
32753276

3277+
rc = smc_sysctl_init();
3278+
if (rc) {
3279+
pr_err("%s: sysctl_init fails with %d\n", __func__, rc);
3280+
goto out_ulp;
3281+
}
3282+
32763283
static_branch_enable(&tcp_have_smc);
32773284
return 0;
32783285

3286+
out_ulp:
3287+
tcp_unregister_ulp(&smc_ulp_ops);
32793288
out_sock:
32803289
sock_unregister(PF_SMC);
32813290
out_proto6:
@@ -3303,6 +3312,7 @@ static int __init smc_init(void)
33033312
static void __exit smc_exit(void)
33043313
{
33053314
static_branch_disable(&tcp_have_smc);
3315+
smc_sysctl_exit();
33063316
tcp_unregister_ulp(&smc_ulp_ops);
33073317
sock_unregister(PF_SMC);
33083318
smc_core_exit();

net/smc/smc_sysctl.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Shared Memory Communications over RDMA (SMC-R) and RoCE
4+
*
5+
* smc_sysctl.c: sysctl interface to SMC subsystem.
6+
*
7+
* Copyright (c) 2022, Alibaba Inc.
8+
*
9+
* Author: Tony Lu <tonylu@linux.alibaba.com>
10+
*
11+
*/
12+
13+
#include <linux/init.h>
14+
#include <linux/sysctl.h>
15+
#include <net/net_namespace.h>
16+
17+
#include "smc_sysctl.h"
18+
19+
static struct ctl_table smc_table[] = {
20+
{ }
21+
};
22+
23+
static __net_init int smc_sysctl_init_net(struct net *net)
24+
{
25+
struct ctl_table *table;
26+
27+
table = smc_table;
28+
if (!net_eq(net, &init_net)) {
29+
int i;
30+
31+
table = kmemdup(table, sizeof(smc_table), GFP_KERNEL);
32+
if (!table)
33+
goto err_alloc;
34+
35+
for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++)
36+
table[i].data += (void *)net - (void *)&init_net;
37+
}
38+
39+
net->smc.smc_hdr = register_net_sysctl(net, "net/smc", table);
40+
if (!net->smc.smc_hdr)
41+
goto err_reg;
42+
43+
return 0;
44+
45+
err_reg:
46+
if (!net_eq(net, &init_net))
47+
kfree(table);
48+
err_alloc:
49+
return -ENOMEM;
50+
}
51+
52+
static __net_exit void smc_sysctl_exit_net(struct net *net)
53+
{
54+
unregister_net_sysctl_table(net->smc.smc_hdr);
55+
}
56+
57+
static struct pernet_operations smc_sysctl_ops __net_initdata = {
58+
.init = smc_sysctl_init_net,
59+
.exit = smc_sysctl_exit_net,
60+
};
61+
62+
int __init smc_sysctl_init(void)
63+
{
64+
return register_pernet_subsys(&smc_sysctl_ops);
65+
}
66+
67+
void smc_sysctl_exit(void)
68+
{
69+
unregister_pernet_subsys(&smc_sysctl_ops);
70+
}

net/smc/smc_sysctl.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Shared Memory Communications over RDMA (SMC-R) and RoCE
4+
*
5+
* smc_sysctl.c: sysctl interface to SMC subsystem.
6+
*
7+
* Copyright (c) 2022, Alibaba Inc.
8+
*
9+
* Author: Tony Lu <tonylu@linux.alibaba.com>
10+
*
11+
*/
12+
13+
#ifndef _SMC_SYSCTL_H
14+
#define _SMC_SYSCTL_H
15+
16+
#ifdef CONFIG_SYSCTL
17+
18+
int smc_sysctl_init(void);
19+
void smc_sysctl_exit(void);
20+
21+
#else
22+
23+
int smc_sysctl_init(void)
24+
{
25+
return 0;
26+
}
27+
28+
void smc_sysctl_exit(void) { }
29+
30+
#endif /* CONFIG_SYSCTL */
31+
32+
#endif /* _SMC_SYSCTL_H */

0 commit comments

Comments
 (0)