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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LNET
35 #include <lnet/lib-lnet.h>
36 #include <uapi/linux/lnet/lnet-dlc.h>
38 static int config_on_load = 0;
39 module_param(config_on_load, int, 0444);
40 MODULE_PARM_DESC(config_on_load, "configure network at module load");
42 static struct mutex lnet_config_mutex;
45 lnet_configure(void *arg)
47 /* 'arg' only there so I can be passed to cfs_create_thread() */
50 mutex_lock(&lnet_config_mutex);
52 if (!the_lnet.ln_niinit_self) {
53 rc = try_module_get(THIS_MODULE);
58 rc = LNetNIInit(LNET_PID_LUSTRE);
60 the_lnet.ln_niinit_self = 1;
63 module_put(THIS_MODULE);
68 mutex_unlock(&lnet_config_mutex);
73 lnet_unconfigure (void)
77 mutex_lock(&lnet_config_mutex);
79 if (the_lnet.ln_niinit_self) {
80 the_lnet.ln_niinit_self = 0;
82 module_put(THIS_MODULE);
85 mutex_lock(&the_lnet.ln_api_mutex);
86 refcount = the_lnet.ln_refcount;
87 mutex_unlock(&the_lnet.ln_api_mutex);
89 mutex_unlock(&lnet_config_mutex);
91 return (refcount == 0) ? 0 : -EBUSY;
95 lnet_dyn_configure_net(struct libcfs_ioctl_hdr *hdr)
97 struct lnet_ioctl_config_data *conf =
98 (struct lnet_ioctl_config_data *)hdr;
101 if (conf->cfg_hdr.ioc_len < sizeof(*conf))
104 mutex_lock(&lnet_config_mutex);
105 if (the_lnet.ln_niinit_self)
106 rc = lnet_dyn_add_net(conf);
109 mutex_unlock(&lnet_config_mutex);
115 lnet_dyn_unconfigure_net(struct libcfs_ioctl_hdr *hdr)
117 struct lnet_ioctl_config_data *conf =
118 (struct lnet_ioctl_config_data *) hdr;
121 if (conf->cfg_hdr.ioc_len < sizeof(*conf))
124 mutex_lock(&lnet_config_mutex);
125 if (the_lnet.ln_niinit_self)
126 rc = lnet_dyn_del_net(conf->cfg_net);
129 mutex_unlock(&lnet_config_mutex);
135 lnet_dyn_configure_ni(struct libcfs_ioctl_hdr *hdr)
137 struct lnet_ioctl_config_ni *conf =
138 (struct lnet_ioctl_config_ni *)hdr;
141 if (conf->lic_cfg_hdr.ioc_len < sizeof(*conf))
144 mutex_lock(&lnet_config_mutex);
145 if (the_lnet.ln_niinit_self)
146 rc = lnet_dyn_add_ni(conf);
149 mutex_unlock(&lnet_config_mutex);
155 lnet_dyn_unconfigure_ni(struct libcfs_ioctl_hdr *hdr)
157 struct lnet_ioctl_config_ni *conf =
158 (struct lnet_ioctl_config_ni *) hdr;
161 if (conf->lic_cfg_hdr.ioc_len < sizeof(*conf))
164 mutex_lock(&lnet_config_mutex);
165 if (the_lnet.ln_niinit_self)
166 rc = lnet_dyn_del_ni(conf);
169 mutex_unlock(&lnet_config_mutex);
175 lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
180 case IOC_LIBCFS_CONFIGURE: {
181 struct libcfs_ioctl_data *data =
182 (struct libcfs_ioctl_data *)hdr;
184 if (data->ioc_hdr.ioc_len < sizeof(*data))
187 the_lnet.ln_nis_from_mod_params = data->ioc_flags;
188 return lnet_configure(NULL);
191 case IOC_LIBCFS_UNCONFIGURE:
192 return lnet_unconfigure();
194 case IOC_LIBCFS_ADD_NET:
195 return lnet_dyn_configure_net(hdr);
197 case IOC_LIBCFS_DEL_NET:
198 return lnet_dyn_unconfigure_net(hdr);
200 case IOC_LIBCFS_ADD_LOCAL_NI:
201 return lnet_dyn_configure_ni(hdr);
203 case IOC_LIBCFS_DEL_LOCAL_NI:
204 return lnet_dyn_unconfigure_ni(hdr);
207 /* Passing LNET_PID_ANY only gives me a ref if the net is up
208 * already; I'll need it to ensure the net can't go down while
209 * I'm called into it */
210 rc = LNetNIInit(LNET_PID_ANY);
212 rc = LNetCtl(cmd, hdr);
219 DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl);
221 static int __init lnet_init(void)
226 mutex_init(&lnet_config_mutex);
228 rc = lnet_lib_init();
230 CERROR("lnet_lib_init: error %d\n", rc);
234 rc = libcfs_register_ioctl(&lnet_ioctl_handler);
237 if (config_on_load) {
238 /* Have to schedule a separate thread to avoid deadlocking
240 (void)kthread_run(lnet_configure, NULL, "lnet_initd");
246 static void __exit lnet_exit(void)
250 rc = libcfs_deregister_ioctl(&lnet_ioctl_handler);
256 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
257 MODULE_DESCRIPTION("Lustre Networking layer");
258 MODULE_VERSION(LNET_VERSION);
259 MODULE_LICENSE("GPL");
261 module_init(lnet_init);
262 module_exit(lnet_exit);