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, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LNET
34 #include <lnet/lib-lnet.h>
35 #include <lnet/lib-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 struct mutex lnet_config_mutex;
44 lnet_configure(void *arg)
46 /* 'arg' only there so I can be passed to cfs_create_thread() */
49 mutex_lock(&lnet_config_mutex);
51 if (!the_lnet.ln_niinit_self) {
52 rc = try_module_get(THIS_MODULE);
57 rc = LNetNIInit(LNET_PID_LUSTRE);
59 the_lnet.ln_niinit_self = 1;
62 module_put(THIS_MODULE);
67 mutex_unlock(&lnet_config_mutex);
72 lnet_unconfigure (void)
76 mutex_lock(&lnet_config_mutex);
78 if (the_lnet.ln_niinit_self) {
79 the_lnet.ln_niinit_self = 0;
81 module_put(THIS_MODULE);
84 mutex_lock(&the_lnet.ln_api_mutex);
85 refcount = the_lnet.ln_refcount;
86 mutex_unlock(&the_lnet.ln_api_mutex);
88 mutex_unlock(&lnet_config_mutex);
90 return (refcount == 0) ? 0 : -EBUSY;
94 lnet_dyn_configure_net(struct libcfs_ioctl_hdr *hdr)
96 struct lnet_ioctl_config_data *conf =
97 (struct lnet_ioctl_config_data *)hdr;
100 if (conf->cfg_hdr.ioc_len < sizeof(*conf))
103 mutex_lock(&lnet_config_mutex);
104 if (the_lnet.ln_niinit_self)
105 rc = lnet_dyn_add_net(conf);
108 mutex_unlock(&lnet_config_mutex);
114 lnet_dyn_unconfigure_net(struct libcfs_ioctl_hdr *hdr)
116 struct lnet_ioctl_config_data *conf =
117 (struct lnet_ioctl_config_data *) hdr;
120 if (conf->cfg_hdr.ioc_len < sizeof(*conf))
123 mutex_lock(&lnet_config_mutex);
124 if (the_lnet.ln_niinit_self)
125 rc = lnet_dyn_del_net(conf->cfg_net);
128 mutex_unlock(&lnet_config_mutex);
134 lnet_dyn_configure_ni(struct libcfs_ioctl_hdr *hdr)
136 struct lnet_ioctl_config_ni *conf =
137 (struct lnet_ioctl_config_ni *)hdr;
140 if (conf->lic_cfg_hdr.ioc_len < sizeof(*conf))
143 mutex_lock(&lnet_config_mutex);
144 if (the_lnet.ln_niinit_self)
145 rc = lnet_dyn_add_ni(conf);
148 mutex_unlock(&lnet_config_mutex);
154 lnet_dyn_unconfigure_ni(struct libcfs_ioctl_hdr *hdr)
156 struct lnet_ioctl_config_ni *conf =
157 (struct lnet_ioctl_config_ni *) hdr;
160 if (conf->lic_cfg_hdr.ioc_len < sizeof(*conf))
163 mutex_lock(&lnet_config_mutex);
164 if (the_lnet.ln_niinit_self)
165 rc = lnet_dyn_del_ni(conf);
168 mutex_unlock(&lnet_config_mutex);
174 lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
179 case IOC_LIBCFS_CONFIGURE: {
180 struct libcfs_ioctl_data *data =
181 (struct libcfs_ioctl_data *)hdr;
183 if (data->ioc_hdr.ioc_len < sizeof(*data))
186 the_lnet.ln_nis_from_mod_params = data->ioc_flags;
187 return lnet_configure(NULL);
190 case IOC_LIBCFS_UNCONFIGURE:
191 return lnet_unconfigure();
193 case IOC_LIBCFS_ADD_NET:
194 return lnet_dyn_configure_net(hdr);
196 case IOC_LIBCFS_DEL_NET:
197 return lnet_dyn_unconfigure_net(hdr);
199 case IOC_LIBCFS_ADD_LOCAL_NI:
200 return lnet_dyn_configure_ni(hdr);
202 case IOC_LIBCFS_DEL_LOCAL_NI:
203 return lnet_dyn_unconfigure_ni(hdr);
206 /* Passing LNET_PID_ANY only gives me a ref if the net is up
207 * already; I'll need it to ensure the net can't go down while
208 * I'm called into it */
209 rc = LNetNIInit(LNET_PID_ANY);
211 rc = LNetCtl(cmd, hdr);
218 DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl);
220 static int __init lnet_init(void)
225 mutex_init(&lnet_config_mutex);
227 rc = lnet_lib_init();
229 CERROR("lnet_lib_init: error %d\n", rc);
233 rc = libcfs_register_ioctl(&lnet_ioctl_handler);
236 if (config_on_load) {
237 /* Have to schedule a separate thread to avoid deadlocking
239 (void)kthread_run(lnet_configure, NULL, "lnet_initd");
245 static void __exit lnet_exit(void)
249 rc = libcfs_deregister_ioctl(&lnet_ioctl_handler);
255 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
256 MODULE_DESCRIPTION("Lustre Networking layer");
257 MODULE_VERSION(LNET_VERSION);
258 MODULE_LICENSE("GPL");
260 module_init(lnet_init);
261 module_exit(lnet_exit);