Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lnet / lnet / module.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef EXPORT_SYMTAB
38 # define EXPORT_SYMTAB
39 #endif
40 #define DEBUG_SUBSYSTEM S_LNET
41 #include <lnet/lib-lnet.h>
42
43 static int config_on_load = 0;
44 CFS_MODULE_PARM(config_on_load, "i", int, 0444,
45                 "configure network at module load");
46
47 static struct semaphore lnet_config_mutex;
48
49 int
50 lnet_configure (void *arg)
51 {
52         /* 'arg' only there so I can be passed to cfs_kernel_thread() */
53         int    rc = 0;
54
55         LNET_MUTEX_DOWN(&lnet_config_mutex);
56
57         if (!the_lnet.ln_niinit_self) {
58                 rc = LNetNIInit(LUSTRE_SRV_LNET_PID);
59                 if (rc >= 0) {
60                         the_lnet.ln_niinit_self = 1;
61                         rc = 0;
62                 }
63         }
64
65         LNET_MUTEX_UP(&lnet_config_mutex);
66         return rc;
67 }
68
69 int
70 lnet_unconfigure (void)
71 {
72         int   refcount;
73         
74         LNET_MUTEX_DOWN(&lnet_config_mutex);
75
76         if (the_lnet.ln_niinit_self) {
77                 the_lnet.ln_niinit_self = 0;
78                 LNetNIFini();
79         }
80
81         LNET_MUTEX_DOWN(&the_lnet.ln_api_mutex);
82         refcount = the_lnet.ln_refcount;
83         LNET_MUTEX_UP(&the_lnet.ln_api_mutex);
84
85         LNET_MUTEX_UP(&lnet_config_mutex);
86         return (refcount == 0) ? 0 : -EBUSY;
87 }
88
89 int
90 lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data)
91 {
92         int   rc;
93
94         switch (cmd) {
95         case IOC_LIBCFS_CONFIGURE:
96                 return lnet_configure(NULL);
97
98         case IOC_LIBCFS_UNCONFIGURE:
99                 return lnet_unconfigure();
100                 
101         default:
102                 /* Passing LNET_PID_ANY only gives me a ref if the net is up
103                  * already; I'll need it to ensure the net can't go down while
104                  * I'm called into it */
105                 rc = LNetNIInit(LNET_PID_ANY);
106                 if (rc >= 0) {
107                         rc = LNetCtl(cmd, data);
108                         LNetNIFini();
109                 }
110                 return rc;
111         }
112 }
113
114 DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl);
115
116 int
117 init_lnet(void)
118 {
119         int                  rc;
120         ENTRY;
121
122         init_mutex(&lnet_config_mutex);
123
124         rc = LNetInit();
125         if (rc != 0) {
126                 CERROR("LNetInit: error %d\n", rc);
127                 RETURN(rc);
128         }
129
130         rc = libcfs_register_ioctl(&lnet_ioctl_handler);
131         LASSERT (rc == 0);
132
133         if (config_on_load) {
134                 /* Have to schedule a separate thread to avoid deadlocking
135                  * in modload */
136                 (void) cfs_kernel_thread(lnet_configure, NULL, 0);
137         }
138
139         RETURN(0);
140 }
141
142 void
143 fini_lnet(void)
144 {
145         int rc;
146
147         rc = libcfs_deregister_ioctl(&lnet_ioctl_handler);
148         LASSERT (rc == 0);
149
150         LNetFini();
151 }
152
153 EXPORT_SYMBOL(lnet_register_lnd);
154 EXPORT_SYMBOL(lnet_unregister_lnd);
155
156 EXPORT_SYMBOL(LNetMEAttach);
157 EXPORT_SYMBOL(LNetMEInsert);
158 EXPORT_SYMBOL(LNetMEUnlink);
159 EXPORT_SYMBOL(LNetEQAlloc);
160 EXPORT_SYMBOL(LNetMDAttach);
161 EXPORT_SYMBOL(LNetMDUnlink);
162 EXPORT_SYMBOL(LNetNIInit);
163 EXPORT_SYMBOL(LNetNIFini);
164 EXPORT_SYMBOL(LNetInit);
165 EXPORT_SYMBOL(LNetFini);
166 EXPORT_SYMBOL(LNetSnprintHandle);
167 EXPORT_SYMBOL(LNetPut);
168 EXPORT_SYMBOL(LNetGet);
169 EXPORT_SYMBOL(LNetEQWait);
170 EXPORT_SYMBOL(LNetEQFree);
171 EXPORT_SYMBOL(LNetEQGet);
172 EXPORT_SYMBOL(LNetGetId);
173 EXPORT_SYMBOL(LNetMDBind);
174 EXPORT_SYMBOL(LNetDist);
175 EXPORT_SYMBOL(LNetSetAsync);
176 EXPORT_SYMBOL(LNetCtl);
177 EXPORT_SYMBOL(LNetSetLazyPortal);
178 EXPORT_SYMBOL(LNetClearLazyPortal);
179 EXPORT_SYMBOL(the_lnet);
180 EXPORT_SYMBOL(lnet_iov_nob);
181 EXPORT_SYMBOL(lnet_extract_iov);
182 EXPORT_SYMBOL(lnet_kiov_nob);
183 EXPORT_SYMBOL(lnet_extract_kiov);
184 EXPORT_SYMBOL(lnet_copy_iov2iov);
185 EXPORT_SYMBOL(lnet_copy_iov2kiov);
186 EXPORT_SYMBOL(lnet_copy_kiov2iov);
187 EXPORT_SYMBOL(lnet_copy_kiov2kiov);
188 EXPORT_SYMBOL(lnet_finalize);
189 EXPORT_SYMBOL(lnet_parse);
190 EXPORT_SYMBOL(lnet_create_reply_msg);
191 EXPORT_SYMBOL(lnet_set_reply_msg_len);
192 EXPORT_SYMBOL(lnet_msgtyp2str);
193 EXPORT_SYMBOL(lnet_net2ni_locked);
194
195 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
196 MODULE_DESCRIPTION("Portals v3.1");
197 MODULE_LICENSE("GPL");
198
199 cfs_module(lnet, "1.0.0", init_lnet, fini_lnet);