Whamcloud - gitweb
* Added loopback optimisation to lib-move.c
[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_PORTALS
26
27 #include <portals/lib-p30.h>
28 #include <portals/p30.h>
29 #include <portals/nal.h>
30 #include <libcfs/kp30.h>
31 #include <portals/kpr.h>
32
33 extern void (kping_client)(struct portal_ioctl_data *);
34
35 static int kportal_ioctl(struct portal_ioctl_data *data,
36                          unsigned int cmd, unsigned long arg)
37 {
38         int err;
39         char str[PTL_NALFMT_SIZE];
40         ENTRY;
41
42         switch (cmd) {
43         case IOC_PORTAL_PING: {
44                 void (*ping)(struct portal_ioctl_data *);
45
46                 CDEBUG(D_IOCTL, "doing %d pings to nid "LPX64" (%s)\n",
47                        data->ioc_count, data->ioc_nid,
48                        portals_nid2str(data->ioc_nal, data->ioc_nid, str));
49                 ping = PORTAL_SYMBOL_GET(kping_client);
50                 if (!ping)
51                         CERROR("PORTAL_SYMBOL_GET failed\n");
52                 else {
53                         ping(data);
54                         PORTAL_SYMBOL_PUT(kping_client);
55                 }
56                 RETURN(0);
57         }
58
59         case IOC_PORTAL_GET_NID: {
60                 ptl_handle_ni_t    nih;
61                 ptl_process_id_t   pid;
62
63                 CDEBUG (D_IOCTL, "Getting nid for nal [%x]\n", data->ioc_nal);
64
65                 err = PtlNIInit(data->ioc_nal, LUSTRE_SRV_PTL_PID, NULL,
66                                 NULL, &nih);
67                 if (!(err == PTL_OK || err == PTL_IFACE_DUP))
68                         RETURN (-EINVAL);
69
70                 err = PtlGetId (nih, &pid);
71                 LASSERT (err == PTL_OK);
72
73                 PtlNIFini(nih);
74
75                 data->ioc_nid = pid.nid;
76                 if (copy_to_user ((char *)arg, data, sizeof (*data)))
77                         RETURN (-EFAULT);
78                 RETURN(0);
79         }
80
81         case IOC_PORTAL_FAIL_NID: {
82                 ptl_handle_ni_t    nih;
83
84                 CDEBUG (D_IOCTL, "fail nid: [%d] "LPU64" count %d\n",
85                         data->ioc_nal, data->ioc_nid, data->ioc_count);
86
87                 err = PtlNIInit(data->ioc_nal, LUSTRE_SRV_PTL_PID, NULL,
88                                 NULL, &nih);
89                 if (!(err == PTL_OK || err == PTL_IFACE_DUP))
90                         return (-EINVAL);
91
92                 if (err == PTL_OK) {
93                         /* There's no point in failing an interface that
94                          * came into existance just for this */
95                         err = -EINVAL;
96                 } else {
97                         err = PtlFailNid (nih, data->ioc_nid, data->ioc_count);
98                         if (err != PTL_OK)
99                                 err = -EINVAL;
100                 }
101
102                 PtlNIFini(nih);
103                 RETURN (err);
104         }
105
106         case IOC_PORTAL_LOOPBACK: {
107                 ptl_handle_ni_t  nih;
108                 int              enabled = data->ioc_flags;
109                 int              set = data->ioc_misc;
110
111                 CDEBUG (D_IOCTL, "loopback: [%d] %d %d\n",
112                         data->ioc_nal, enabled, set);
113
114                 err = PtlNIInit(data->ioc_nal, LUSTRE_SRV_PTL_PID, NULL,
115                                 NULL, &nih);
116                 if (!(err == PTL_OK || err == PTL_IFACE_DUP))
117                         return (-EINVAL);
118
119                 if (err == PTL_OK) {
120                         /* There's no point in failing an interface that
121                          * came into existance just for this */
122                         err = -EINVAL;
123                 } else {
124                         err = PtlLoopback (nih, set, &enabled);
125                         if (err != PTL_OK) {
126                                 err = -EINVAL;
127                         } else {
128                                 data->ioc_flags = enabled;
129                                 if (copy_to_user ((char *)arg, data, 
130                                                   sizeof (*data)))
131                                         err = -EFAULT;
132                                 else
133                                         err = 0;
134                         }
135                 }
136
137                 PtlNIFini(nih);
138                 RETURN (err);
139         }
140         default:
141                 RETURN(-EINVAL);
142         }
143         /* Not Reached */
144 }
145
146 DECLARE_IOCTL_HANDLER(kportal_ioctl_handler, kportal_ioctl);
147 extern struct semaphore ptl_mutex;
148
149 static int init_kportals_module(void)
150 {
151         int rc;
152         ENTRY;
153
154         init_mutex(&ptl_mutex);
155         rc = PtlInit(NULL);
156         if (rc) {
157                 CERROR("PtlInit: error %d\n", rc);
158                 RETURN(rc);
159         }
160
161         rc = libcfs_register_ioctl(&kportal_ioctl_handler);
162         LASSERT (rc == 0);
163
164         RETURN(rc);
165 }
166
167 static void exit_kportals_module(void)
168 {
169         int rc;
170
171         rc = libcfs_deregister_ioctl(&kportal_ioctl_handler);
172         LASSERT (rc == 0);
173
174         PtlFini();
175 }
176
177 EXPORT_SYMBOL(ptl_register_nal);
178 EXPORT_SYMBOL(ptl_unregister_nal);
179
180 EXPORT_SYMBOL(ptl_err_str);
181 EXPORT_SYMBOL(PtlMEAttach);
182 EXPORT_SYMBOL(PtlMEInsert);
183 EXPORT_SYMBOL(PtlMEUnlink);
184 EXPORT_SYMBOL(PtlEQAlloc);
185 EXPORT_SYMBOL(PtlMDAttach);
186 EXPORT_SYMBOL(PtlMDUnlink);
187 EXPORT_SYMBOL(PtlNIInit);
188 EXPORT_SYMBOL(PtlNIFini);
189 EXPORT_SYMBOL(PtlInit);
190 EXPORT_SYMBOL(PtlFini);
191 EXPORT_SYMBOL(PtlSnprintHandle);
192 EXPORT_SYMBOL(PtlPut);
193 EXPORT_SYMBOL(PtlGet);
194 EXPORT_SYMBOL(PtlEQWait);
195 EXPORT_SYMBOL(PtlEQFree);
196 EXPORT_SYMBOL(PtlEQGet);
197 EXPORT_SYMBOL(PtlGetId);
198 EXPORT_SYMBOL(PtlMDBind);
199 EXPORT_SYMBOL(lib_iov_nob);
200 EXPORT_SYMBOL(lib_copy_iov2buf);
201 EXPORT_SYMBOL(lib_copy_buf2iov);
202 EXPORT_SYMBOL(lib_extract_iov);
203 EXPORT_SYMBOL(lib_kiov_nob);
204 EXPORT_SYMBOL(lib_copy_kiov2buf);
205 EXPORT_SYMBOL(lib_copy_buf2kiov);
206 EXPORT_SYMBOL(lib_extract_kiov);
207 EXPORT_SYMBOL(lib_finalize);
208 EXPORT_SYMBOL(lib_parse);
209 EXPORT_SYMBOL(lib_create_reply_msg);
210 EXPORT_SYMBOL(lib_init);
211 EXPORT_SYMBOL(lib_fini);
212
213 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
214 MODULE_DESCRIPTION("Portals v3.1");
215 MODULE_LICENSE("GPL");
216
217 cfs_module(portals, "1.0.0", init_kportals_module, exit_kportals_module);