4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
32 #define DEBUG_SUBSYSTEM S_LNET
34 #include <lnet/lib-lnet.h>
35 #include <uapi/linux/lnet/lnet-dlc.h>
37 static int config_on_load = 0;
38 module_param(config_on_load, int, 0444);
39 MODULE_PARM_DESC(config_on_load, "configure network at module load");
41 static DEFINE_MUTEX(lnet_config_mutex);
43 static int lnet_configure(void *arg)
45 /* 'arg' only there so I can be passed to cfs_create_thread() */
48 mutex_lock(&lnet_config_mutex);
50 if (!the_lnet.ln_niinit_self) {
51 rc = try_module_get(THIS_MODULE);
56 rc = LNetNIInit(LNET_PID_LUSTRE);
58 the_lnet.ln_niinit_self = 1;
61 module_put(THIS_MODULE);
66 mutex_unlock(&lnet_config_mutex);
70 static int lnet_unconfigure(void)
74 mutex_lock(&lnet_config_mutex);
76 if (the_lnet.ln_niinit_self) {
77 the_lnet.ln_niinit_self = 0;
79 module_put(THIS_MODULE);
82 mutex_lock(&the_lnet.ln_api_mutex);
83 refcount = the_lnet.ln_refcount;
84 mutex_unlock(&the_lnet.ln_api_mutex);
86 mutex_unlock(&lnet_config_mutex);
88 return (refcount == 0) ? 0 : -EBUSY;
92 lnet_dyn_configure_net(struct libcfs_ioctl_hdr *hdr)
94 struct lnet_ioctl_config_data *conf =
95 (struct lnet_ioctl_config_data *)hdr;
98 if (conf->cfg_hdr.ioc_len < sizeof(*conf))
101 mutex_lock(&lnet_config_mutex);
102 if (the_lnet.ln_niinit_self)
103 rc = lnet_dyn_add_net(conf);
106 mutex_unlock(&lnet_config_mutex);
112 lnet_dyn_unconfigure_net(struct libcfs_ioctl_hdr *hdr)
114 struct lnet_ioctl_config_data *conf =
115 (struct lnet_ioctl_config_data *) hdr;
118 if (conf->cfg_hdr.ioc_len < sizeof(*conf))
121 mutex_lock(&lnet_config_mutex);
122 if (the_lnet.ln_niinit_self)
123 rc = lnet_dyn_del_net(conf->cfg_net);
126 mutex_unlock(&lnet_config_mutex);
132 lnet_dyn_configure_ni(struct libcfs_ioctl_hdr *hdr)
134 struct lnet_ioctl_config_ni *conf =
135 (struct lnet_ioctl_config_ni *)hdr;
138 if (conf->lic_cfg_hdr.ioc_len < sizeof(*conf))
141 mutex_lock(&lnet_config_mutex);
142 if (the_lnet.ln_niinit_self) {
143 struct lnet_ioctl_config_lnd_tunables *tun = NULL;
147 /* get the tunables if they are available */
148 if (conf->lic_cfg_hdr.ioc_len >=
149 sizeof(*conf) + sizeof(*tun))
150 tun = (struct lnet_ioctl_config_lnd_tunables *) conf->lic_bulk;
152 lnet_nid4_to_nid(conf->lic_nid, &nid);
153 net_id = LNET_NID_NET(&nid);
154 rc = lnet_dyn_add_ni(conf, net_id, tun);
156 mutex_unlock(&lnet_config_mutex);
162 lnet_dyn_unconfigure_ni(struct libcfs_ioctl_hdr *hdr)
164 struct lnet_ioctl_config_ni *conf =
165 (struct lnet_ioctl_config_ni *) hdr;
169 if (conf->lic_cfg_hdr.ioc_len < sizeof(*conf) ||
170 !the_lnet.ln_niinit_self)
173 lnet_nid4_to_nid(conf->lic_nid, &nid);
174 mutex_lock(&lnet_config_mutex);
175 if (the_lnet.ln_niinit_self)
176 rc = lnet_dyn_del_ni(&nid);
179 mutex_unlock(&lnet_config_mutex);
185 lnet_ioctl(struct notifier_block *nb,
186 unsigned long cmd, void *vdata)
188 struct libcfs_ioctl_hdr *hdr = vdata;
192 case IOC_LIBCFS_CONFIGURE: {
193 struct libcfs_ioctl_data *data =
194 (struct libcfs_ioctl_data *)hdr;
196 if (data->ioc_hdr.ioc_len < sizeof(*data)) {
199 the_lnet.ln_nis_from_mod_params = data->ioc_flags;
200 rc = lnet_configure(NULL);
205 case IOC_LIBCFS_UNCONFIGURE:
206 rc = lnet_unconfigure();
209 case IOC_LIBCFS_ADD_NET:
210 rc = lnet_dyn_configure_net(hdr);
213 case IOC_LIBCFS_DEL_NET:
214 rc = lnet_dyn_unconfigure_net(hdr);
217 case IOC_LIBCFS_ADD_LOCAL_NI:
218 rc = lnet_dyn_configure_ni(hdr);
221 case IOC_LIBCFS_DEL_LOCAL_NI:
222 rc = lnet_dyn_unconfigure_ni(hdr);
226 /* Passing LNET_PID_ANY only gives me a ref if the net is up
227 * already; I'll need it to ensure the net can't go down while
228 * I'm called into it */
229 rc = LNetNIInit(LNET_PID_ANY);
231 rc = LNetCtl(cmd, hdr);
236 return notifier_from_ioctl_errno(rc);
239 static struct notifier_block lnet_ioctl_handler = {
240 .notifier_call = lnet_ioctl,
243 static int __init lnet_init(void)
248 rc = lnet_lib_init();
250 CERROR("lnet_lib_init: error %d\n", rc);
254 if (live_router_check_interval != INT_MIN ||
255 dead_router_check_interval != INT_MIN)
256 LCONSOLE_WARN("live_router_check_interval and dead_router_check_interval have been deprecated. Use alive_router_check_interval instead. Ignoring these deprecated parameters.\n");
258 rc = blocking_notifier_chain_register(&libcfs_ioctl_list,
259 &lnet_ioctl_handler);
262 if (config_on_load) {
263 /* Have to schedule a separate thread to avoid deadlocking
265 (void)kthread_run(lnet_configure, NULL, "lnet_initd");
271 static void __exit lnet_exit(void)
275 rc = blocking_notifier_chain_unregister(&libcfs_ioctl_list,
276 &lnet_ioctl_handler);
283 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
284 MODULE_DESCRIPTION("Lustre Networking layer");
285 MODULE_VERSION(LNET_VERSION);
286 MODULE_LICENSE("GPL");
288 module_init(lnet_init);
289 module_exit(lnet_exit);