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