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