GNU Linux-libre 5.19-rc6-gnu
[releases.git] / net / smc / smc_sysctl.c
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.h"
18 #include "smc_sysctl.h"
19
20 static struct ctl_table smc_table[] = {
21         {
22                 .procname       = "autocorking_size",
23                 .data           = &init_net.smc.sysctl_autocorking_size,
24                 .maxlen         = sizeof(unsigned int),
25                 .mode           = 0644,
26                 .proc_handler   = proc_douintvec,
27         },
28         {  }
29 };
30
31 int __net_init smc_sysctl_net_init(struct net *net)
32 {
33         struct ctl_table *table;
34
35         table = smc_table;
36         if (!net_eq(net, &init_net)) {
37                 int i;
38
39                 table = kmemdup(table, sizeof(smc_table), GFP_KERNEL);
40                 if (!table)
41                         goto err_alloc;
42
43                 for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++)
44                         table[i].data += (void *)net - (void *)&init_net;
45         }
46
47         net->smc.smc_hdr = register_net_sysctl(net, "net/smc", table);
48         if (!net->smc.smc_hdr)
49                 goto err_reg;
50
51         net->smc.sysctl_autocorking_size = SMC_AUTOCORKING_DEFAULT_SIZE;
52
53         return 0;
54
55 err_reg:
56         if (!net_eq(net, &init_net))
57                 kfree(table);
58 err_alloc:
59         return -ENOMEM;
60 }
61
62 void __net_exit smc_sysctl_net_exit(struct net *net)
63 {
64         struct ctl_table *table;
65
66         table = net->smc.smc_hdr->ctl_table_arg;
67         unregister_net_sysctl_table(net->smc.smc_hdr);
68         if (!net_eq(net, &init_net))
69                 kfree(table);
70 }