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.sun.com/software/products/lustre/docs/GPLv2.pdf
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
27 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LNET
38 #include <lnet/lib-lnet.h>
39 #include <lnet/lib-dlc.h>
41 static int config_on_load = 0;
42 module_param(config_on_load, int, 0444);
43 MODULE_PARM_DESC(config_on_load, "configure network at module load");
45 static struct mutex lnet_config_mutex;
48 lnet_configure(void *arg)
50 /* 'arg' only there so I can be passed to cfs_create_thread() */
53 mutex_lock(&lnet_config_mutex);
55 if (!the_lnet.ln_niinit_self) {
56 rc = try_module_get(THIS_MODULE);
61 rc = LNetNIInit(LNET_PID_LUSTRE);
63 the_lnet.ln_niinit_self = 1;
66 module_put(THIS_MODULE);
71 mutex_unlock(&lnet_config_mutex);
76 lnet_unconfigure (void)
80 mutex_lock(&lnet_config_mutex);
82 if (the_lnet.ln_niinit_self) {
83 the_lnet.ln_niinit_self = 0;
85 module_put(THIS_MODULE);
88 mutex_lock(&the_lnet.ln_api_mutex);
89 refcount = the_lnet.ln_refcount;
90 mutex_unlock(&the_lnet.ln_api_mutex);
92 mutex_unlock(&lnet_config_mutex);
94 return (refcount == 0) ? 0 : -EBUSY;
98 lnet_dyn_configure(struct libcfs_ioctl_hdr *hdr)
100 struct lnet_ioctl_config_data *conf =
101 (struct lnet_ioctl_config_data *)hdr;
104 mutex_lock(&lnet_config_mutex);
105 if (the_lnet.ln_niinit_self)
106 rc = lnet_dyn_add_ni(LNET_PID_LUSTRE, conf);
109 mutex_unlock(&lnet_config_mutex);
114 lnet_dyn_unconfigure(struct libcfs_ioctl_hdr *hdr)
116 struct lnet_ioctl_config_data *conf =
117 (struct lnet_ioctl_config_data *) hdr;
120 mutex_lock(&lnet_config_mutex);
121 if (the_lnet.ln_niinit_self)
122 rc = lnet_dyn_del_ni(conf->cfg_net);
125 mutex_unlock(&lnet_config_mutex);
131 lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
136 case IOC_LIBCFS_CONFIGURE: {
137 struct libcfs_ioctl_data *data =
138 (struct libcfs_ioctl_data *)hdr;
139 the_lnet.ln_nis_from_mod_params = data->ioc_flags;
140 return lnet_configure(NULL);
143 case IOC_LIBCFS_UNCONFIGURE:
144 return lnet_unconfigure();
146 case IOC_LIBCFS_ADD_NET:
147 return lnet_dyn_configure(hdr);
149 case IOC_LIBCFS_DEL_NET:
150 return lnet_dyn_unconfigure(hdr);
153 /* Passing LNET_PID_ANY only gives me a ref if the net is up
154 * already; I'll need it to ensure the net can't go down while
155 * I'm called into it */
156 rc = LNetNIInit(LNET_PID_ANY);
158 rc = LNetCtl(cmd, hdr);
165 DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl);
167 static int __init lnet_init(void)
172 mutex_init(&lnet_config_mutex);
174 rc = lnet_lib_init();
176 CERROR("lnet_lib_init: error %d\n", rc);
180 rc = libcfs_register_ioctl(&lnet_ioctl_handler);
183 if (config_on_load) {
184 /* Have to schedule a separate thread to avoid deadlocking
186 (void)kthread_run(lnet_configure, NULL, "lnet_initd");
192 static void __exit lnet_exit(void)
196 rc = libcfs_deregister_ioctl(&lnet_ioctl_handler);
202 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
203 MODULE_DESCRIPTION("Lustre Networking layer");
204 MODULE_VERSION(LNET_VERSION);
205 MODULE_LICENSE("GPL");
207 module_init(lnet_init);
208 module_exit(lnet_exit);