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, 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>
40 static int config_on_load = 0;
41 CFS_MODULE_PARM(config_on_load, "i", int, 0444,
42 "configure network at module load");
44 static struct mutex lnet_config_mutex;
47 lnet_configure (void *arg)
49 /* 'arg' only there so I can be passed to cfs_create_thread() */
52 LNET_MUTEX_LOCK(&lnet_config_mutex);
54 if (!the_lnet.ln_niinit_self) {
55 rc = LNetNIInit(LUSTRE_SRV_LNET_PID);
57 the_lnet.ln_niinit_self = 1;
62 LNET_MUTEX_UNLOCK(&lnet_config_mutex);
67 lnet_unconfigure (void)
71 LNET_MUTEX_LOCK(&lnet_config_mutex);
73 if (the_lnet.ln_niinit_self) {
74 the_lnet.ln_niinit_self = 0;
78 LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
79 refcount = the_lnet.ln_refcount;
80 LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
82 LNET_MUTEX_UNLOCK(&lnet_config_mutex);
83 return (refcount == 0) ? 0 : -EBUSY;
87 lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data)
92 case IOC_LIBCFS_CONFIGURE:
93 return lnet_configure(NULL);
95 case IOC_LIBCFS_UNCONFIGURE:
96 return lnet_unconfigure();
99 /* Passing LNET_PID_ANY only gives me a ref if the net is up
100 * already; I'll need it to ensure the net can't go down while
101 * I'm called into it */
102 rc = LNetNIInit(LNET_PID_ANY);
104 rc = LNetCtl(cmd, data);
111 DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl);
119 mutex_init(&lnet_config_mutex);
123 CERROR("LNetInit: error %d\n", rc);
127 rc = libcfs_register_ioctl(&lnet_ioctl_handler);
130 if (config_on_load) {
131 /* Have to schedule a separate thread to avoid deadlocking
133 (void) cfs_create_thread(lnet_configure, NULL, 0);
144 rc = libcfs_deregister_ioctl(&lnet_ioctl_handler);
150 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
151 MODULE_DESCRIPTION("Portals v3.1");
152 MODULE_LICENSE("GPL");
154 cfs_module(lnet, "1.0.0", init_lnet, fini_lnet);