|
| 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 | +} |
0 commit comments