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