1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#define DEBUG_SUBSYSTEM S_LNET
38#include <linux/lnet/lib-lnet.h>
39
40static int config_on_load = 0;
41CFS_MODULE_PARM(config_on_load, "i", int, 0444,
42 "configure network at module load");
43
44static struct mutex lnet_config_mutex;
45
46int
47lnet_configure (void *arg)
48{
49
50 int rc = 0;
51
52 LNET_MUTEX_LOCK(&lnet_config_mutex);
53
54 if (!the_lnet.ln_niinit_self) {
55 rc = LNetNIInit(LUSTRE_SRV_LNET_PID);
56 if (rc >= 0) {
57 the_lnet.ln_niinit_self = 1;
58 rc = 0;
59 }
60 }
61
62 LNET_MUTEX_UNLOCK(&lnet_config_mutex);
63 return rc;
64}
65
66int
67lnet_unconfigure (void)
68{
69 int refcount;
70
71 LNET_MUTEX_LOCK(&lnet_config_mutex);
72
73 if (the_lnet.ln_niinit_self) {
74 the_lnet.ln_niinit_self = 0;
75 LNetNIFini();
76 }
77
78 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
79 refcount = the_lnet.ln_refcount;
80 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
81
82 LNET_MUTEX_UNLOCK(&lnet_config_mutex);
83 return (refcount == 0) ? 0 : -EBUSY;
84}
85
86int
87lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data)
88{
89 int rc;
90
91 switch (cmd) {
92 case IOC_LIBCFS_CONFIGURE:
93 return lnet_configure(NULL);
94
95 case IOC_LIBCFS_UNCONFIGURE:
96 return lnet_unconfigure();
97
98 default:
99
100
101
102 rc = LNetNIInit(LNET_PID_ANY);
103 if (rc >= 0) {
104 rc = LNetCtl(cmd, data);
105 LNetNIFini();
106 }
107 return rc;
108 }
109}
110
111DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl);
112
113int
114init_lnet(void)
115{
116 int rc;
117 ENTRY;
118
119 mutex_init(&lnet_config_mutex);
120
121 rc = LNetInit();
122 if (rc != 0) {
123 CERROR("LNetInit: error %d\n", rc);
124 RETURN(rc);
125 }
126
127 rc = libcfs_register_ioctl(&lnet_ioctl_handler);
128 LASSERT (rc == 0);
129
130 if (config_on_load) {
131
132
133 (void) kthread_run(lnet_configure, NULL, "lnet_initd");
134 }
135
136 RETURN(0);
137}
138
139void
140fini_lnet(void)
141{
142 int rc;
143
144 rc = libcfs_deregister_ioctl(&lnet_ioctl_handler);
145 LASSERT (rc == 0);
146
147 LNetFini();
148}
149
150MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
151MODULE_DESCRIPTION("Portals v3.1");
152MODULE_LICENSE("GPL");
153
154cfs_module(lnet, "1.0.0", init_lnet, fini_lnet);
155