staging: lustre: DLC user/kernel space glue code
[deliverable/linux.git] / drivers / staging / lustre / lnet / lnet / module.c
1 /*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26 /*
27 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2012, 2015, Intel Corporation.
31 */
32 /*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 */
36
37 #define DEBUG_SUBSYSTEM S_LNET
38 #include "../../include/linux/lnet/lib-lnet.h"
39 #include "../../include/linux/lnet/lib-dlc.h"
40
41 static int config_on_load;
42 module_param(config_on_load, int, 0444);
43 MODULE_PARM_DESC(config_on_load, "configure network at module load");
44
45 static struct mutex lnet_config_mutex;
46
47 static int
48 lnet_configure(void *arg)
49 {
50 /* 'arg' only there so I can be passed to cfs_create_thread() */
51 int rc = 0;
52
53 mutex_lock(&lnet_config_mutex);
54
55 if (!the_lnet.ln_niinit_self) {
56 rc = LNetNIInit(LUSTRE_SRV_LNET_PID);
57 if (rc >= 0) {
58 the_lnet.ln_niinit_self = 1;
59 rc = 0;
60 }
61 }
62
63 mutex_unlock(&lnet_config_mutex);
64 return rc;
65 }
66
67 static int
68 lnet_unconfigure(void)
69 {
70 int refcount;
71
72 mutex_lock(&lnet_config_mutex);
73
74 if (the_lnet.ln_niinit_self) {
75 the_lnet.ln_niinit_self = 0;
76 LNetNIFini();
77 }
78
79 mutex_lock(&the_lnet.ln_api_mutex);
80 refcount = the_lnet.ln_refcount;
81 mutex_unlock(&the_lnet.ln_api_mutex);
82
83 mutex_unlock(&lnet_config_mutex);
84 return !refcount ? 0 : -EBUSY;
85 }
86
87 static int
88 lnet_dyn_configure(struct libcfs_ioctl_hdr *hdr)
89 {
90 struct lnet_ioctl_config_data *conf =
91 (struct lnet_ioctl_config_data *)hdr;
92 int rc;
93
94 if (conf->cfg_hdr.ioc_len < sizeof(*conf))
95 return -EINVAL;
96
97 mutex_lock(&lnet_config_mutex);
98 if (!the_lnet.ln_niinit_self) {
99 rc = -EINVAL;
100 goto out_unlock;
101 }
102 rc = lnet_dyn_add_ni(LUSTRE_SRV_LNET_PID,
103 conf->cfg_config_u.cfg_net.net_intf,
104 conf->cfg_config_u.cfg_net.net_peer_timeout,
105 conf->cfg_config_u.cfg_net.net_peer_tx_credits,
106 conf->cfg_config_u.cfg_net.net_peer_rtr_credits,
107 conf->cfg_config_u.cfg_net.net_max_tx_credits);
108 out_unlock:
109 mutex_unlock(&lnet_config_mutex);
110
111 return rc;
112 }
113
114 static int
115 lnet_dyn_unconfigure(struct libcfs_ioctl_hdr *hdr)
116 {
117 struct lnet_ioctl_config_data *conf =
118 (struct lnet_ioctl_config_data *)hdr;
119 int rc;
120
121 if (conf->cfg_hdr.ioc_len < sizeof(*conf))
122 return -EINVAL;
123
124 mutex_lock(&lnet_config_mutex);
125 if (!the_lnet.ln_niinit_self) {
126 rc = -EINVAL;
127 goto out_unlock;
128 }
129 rc = lnet_dyn_del_ni(conf->cfg_net);
130 out_unlock:
131 mutex_unlock(&lnet_config_mutex);
132
133 return rc;
134 }
135
136 static int
137 lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
138 {
139 int rc;
140
141 switch (cmd) {
142 case IOC_LIBCFS_CONFIGURE: {
143 struct libcfs_ioctl_data *data =
144 (struct libcfs_ioctl_data *)hdr;
145
146 if (data->ioc_hdr.ioc_len < sizeof(*data))
147 return -EINVAL;
148
149 the_lnet.ln_nis_from_mod_params = data->ioc_flags;
150 return lnet_configure(NULL);
151 }
152
153 case IOC_LIBCFS_UNCONFIGURE:
154 return lnet_unconfigure();
155
156 case IOC_LIBCFS_ADD_NET:
157 return lnet_dyn_configure(hdr);
158
159 case IOC_LIBCFS_DEL_NET:
160 return lnet_dyn_unconfigure(hdr);
161
162 default:
163 /*
164 * Passing LNET_PID_ANY only gives me a ref if the net is up
165 * already; I'll need it to ensure the net can't go down while
166 * I'm called into it
167 */
168 rc = LNetNIInit(LNET_PID_ANY);
169 if (rc >= 0) {
170 rc = LNetCtl(cmd, hdr);
171 LNetNIFini();
172 }
173 return rc;
174 }
175 }
176
177 static DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl);
178
179 static int __init
180 init_lnet(void)
181 {
182 int rc;
183
184 mutex_init(&lnet_config_mutex);
185
186 rc = lnet_init();
187 if (rc) {
188 CERROR("lnet_init: error %d\n", rc);
189 return rc;
190 }
191
192 rc = libcfs_register_ioctl(&lnet_ioctl_handler);
193 LASSERT(!rc);
194
195 if (config_on_load) {
196 /*
197 * Have to schedule a separate thread to avoid deadlocking
198 * in modload
199 */
200 (void) kthread_run(lnet_configure, NULL, "lnet_initd");
201 }
202
203 return 0;
204 }
205
206 static void __exit
207 fini_lnet(void)
208 {
209 int rc;
210
211 rc = libcfs_deregister_ioctl(&lnet_ioctl_handler);
212 LASSERT(!rc);
213
214 lnet_fini();
215 }
216
217 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
218 MODULE_DESCRIPTION("LNet v3.1");
219 MODULE_LICENSE("GPL");
220 MODULE_VERSION("1.0.0");
221
222 module_init(init_lnet);
223 module_exit(fini_lnet);
This page took 0.047505 seconds and 5 git commands to generate.