Whamcloud - gitweb
LU-1347 build: remove the vim/emacs modelines
[fs/lustre-release.git] / lnet / lnet / module.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 #ifndef EXPORT_SYMTAB
36 # define EXPORT_SYMTAB
37 #endif
38 #define DEBUG_SUBSYSTEM S_LNET
39 #include <lnet/lib-lnet.h>
40
41 static int config_on_load = 0;
42 CFS_MODULE_PARM(config_on_load, "i", int, 0444,
43                 "configure network at module load");
44
45 static cfs_mutex_t lnet_config_mutex;
46
47 int
48 lnet_configure (void *arg)
49 {
50         /* 'arg' only there so I can be passed to cfs_create_thread() */
51         int    rc = 0;
52
53         LNET_MUTEX_LOCK(&lnet_config_mutex);
54
55         if (!the_lnet.ln_niinit_self) {
56                 rc = LNetNIInit(LUSTRE_SRV_LNET_PID);
57                 if (rc >= 0) {
58                         the_lnet.ln_niinit_self = 1;
59                         rc = 0;
60                 }
61         }
62
63         LNET_MUTEX_UNLOCK(&lnet_config_mutex);
64         return rc;
65 }
66
67 int
68 lnet_unconfigure (void)
69 {
70         int   refcount;
71         
72         LNET_MUTEX_LOCK(&lnet_config_mutex);
73
74         if (the_lnet.ln_niinit_self) {
75                 the_lnet.ln_niinit_self = 0;
76                 LNetNIFini();
77         }
78
79         LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex);
80         refcount = the_lnet.ln_refcount;
81         LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
82
83         LNET_MUTEX_UNLOCK(&lnet_config_mutex);
84         return (refcount == 0) ? 0 : -EBUSY;
85 }
86
87 int
88 lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data)
89 {
90         int   rc;
91
92         switch (cmd) {
93         case IOC_LIBCFS_CONFIGURE:
94                 return lnet_configure(NULL);
95
96         case IOC_LIBCFS_UNCONFIGURE:
97                 return lnet_unconfigure();
98                 
99         default:
100                 /* Passing LNET_PID_ANY only gives me a ref if the net is up
101                  * already; I'll need it to ensure the net can't go down while
102                  * I'm called into it */
103                 rc = LNetNIInit(LNET_PID_ANY);
104                 if (rc >= 0) {
105                         rc = LNetCtl(cmd, data);
106                         LNetNIFini();
107                 }
108                 return rc;
109         }
110 }
111
112 DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl);
113
114 int
115 init_lnet(void)
116 {
117         int                  rc;
118         ENTRY;
119
120         cfs_mutex_init(&lnet_config_mutex);
121
122         rc = LNetInit();
123         if (rc != 0) {
124                 CERROR("LNetInit: error %d\n", rc);
125                 RETURN(rc);
126         }
127
128         rc = libcfs_register_ioctl(&lnet_ioctl_handler);
129         LASSERT (rc == 0);
130
131         if (config_on_load) {
132                 /* Have to schedule a separate thread to avoid deadlocking
133                  * in modload */
134                 (void) cfs_create_thread(lnet_configure, NULL, 0);
135         }
136
137         RETURN(0);
138 }
139
140 void
141 fini_lnet(void)
142 {
143         int rc;
144
145         rc = libcfs_deregister_ioctl(&lnet_ioctl_handler);
146         LASSERT (rc == 0);
147
148         LNetFini();
149 }
150
151 EXPORT_SYMBOL(lnet_register_lnd);
152 EXPORT_SYMBOL(lnet_unregister_lnd);
153
154 EXPORT_SYMBOL(LNetMEAttach);
155 EXPORT_SYMBOL(LNetMEInsert);
156 EXPORT_SYMBOL(LNetMEUnlink);
157 EXPORT_SYMBOL(LNetEQAlloc);
158 EXPORT_SYMBOL(LNetMDAttach);
159 EXPORT_SYMBOL(LNetMDUnlink);
160 EXPORT_SYMBOL(LNetNIInit);
161 EXPORT_SYMBOL(LNetNIFini);
162 EXPORT_SYMBOL(LNetInit);
163 EXPORT_SYMBOL(LNetFini);
164 EXPORT_SYMBOL(LNetSnprintHandle);
165 EXPORT_SYMBOL(LNetPut);
166 EXPORT_SYMBOL(LNetGet);
167 EXPORT_SYMBOL(LNetEQWait);
168 EXPORT_SYMBOL(LNetEQFree);
169 EXPORT_SYMBOL(LNetEQGet);
170 EXPORT_SYMBOL(LNetGetId);
171 EXPORT_SYMBOL(LNetMDBind);
172 EXPORT_SYMBOL(LNetDist);
173 EXPORT_SYMBOL(LNetSetAsync);
174 EXPORT_SYMBOL(LNetCtl);
175 EXPORT_SYMBOL(LNetSetLazyPortal);
176 EXPORT_SYMBOL(LNetClearLazyPortal);
177 EXPORT_SYMBOL(the_lnet);
178 EXPORT_SYMBOL(lnet_iov_nob);
179 EXPORT_SYMBOL(lnet_extract_iov);
180 EXPORT_SYMBOL(lnet_kiov_nob);
181 EXPORT_SYMBOL(lnet_extract_kiov);
182 EXPORT_SYMBOL(lnet_copy_iov2iov);
183 EXPORT_SYMBOL(lnet_copy_iov2kiov);
184 EXPORT_SYMBOL(lnet_copy_kiov2iov);
185 EXPORT_SYMBOL(lnet_copy_kiov2kiov);
186 EXPORT_SYMBOL(lnet_finalize);
187 EXPORT_SYMBOL(lnet_parse);
188 EXPORT_SYMBOL(lnet_create_reply_msg);
189 EXPORT_SYMBOL(lnet_set_reply_msg_len);
190 EXPORT_SYMBOL(lnet_msgtyp2str);
191 EXPORT_SYMBOL(lnet_net2ni_locked);
192
193 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
194 MODULE_DESCRIPTION("Portals v3.1");
195 MODULE_LICENSE("GPL");
196
197 cfs_module(lnet, "1.0.0", init_lnet, fini_lnet);