Whamcloud - gitweb
* Landed portals:b_port_step as follows...
[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         default:
106                 RETURN(-EINVAL);
107         }
108         /* Not Reached */
109 }
110
111 DECLARE_IOCTL_HANDLER(kportal_ioctl_handler, kportal_ioctl);
112 extern struct semaphore ptl_mutex;
113
114 static int init_kportals_module(void)
115 {
116         int rc;
117         ENTRY;
118
119         init_mutex(&ptl_mutex);
120         rc = PtlInit(NULL);
121         if (rc) {
122                 CERROR("PtlInit: error %d\n", rc);
123                 RETURN(rc);
124         }
125
126         rc = libcfs_register_ioctl(&kportal_ioctl_handler);
127         LASSERT (rc == 0);
128
129         RETURN(rc);
130 }
131
132 static void exit_kportals_module(void)
133 {
134         int rc;
135
136         rc = libcfs_deregister_ioctl(&kportal_ioctl_handler);
137         LASSERT (rc == 0);
138
139         PtlFini();
140 }
141
142 EXPORT_SYMBOL(ptl_register_nal);
143 EXPORT_SYMBOL(ptl_unregister_nal);
144
145 EXPORT_SYMBOL(ptl_err_str);
146 EXPORT_SYMBOL(PtlMEAttach);
147 EXPORT_SYMBOL(PtlMEInsert);
148 EXPORT_SYMBOL(PtlMEUnlink);
149 EXPORT_SYMBOL(PtlEQAlloc);
150 EXPORT_SYMBOL(PtlMDAttach);
151 EXPORT_SYMBOL(PtlMDUnlink);
152 EXPORT_SYMBOL(PtlNIInit);
153 EXPORT_SYMBOL(PtlNIFini);
154 EXPORT_SYMBOL(PtlInit);
155 EXPORT_SYMBOL(PtlFini);
156 EXPORT_SYMBOL(PtlSnprintHandle);
157 EXPORT_SYMBOL(PtlPut);
158 EXPORT_SYMBOL(PtlGet);
159 EXPORT_SYMBOL(PtlEQWait);
160 EXPORT_SYMBOL(PtlEQFree);
161 EXPORT_SYMBOL(PtlEQGet);
162 EXPORT_SYMBOL(PtlGetId);
163 EXPORT_SYMBOL(PtlMDBind);
164 EXPORT_SYMBOL(lib_iov_nob);
165 EXPORT_SYMBOL(lib_copy_iov2buf);
166 EXPORT_SYMBOL(lib_copy_buf2iov);
167 EXPORT_SYMBOL(lib_extract_iov);
168 EXPORT_SYMBOL(lib_kiov_nob);
169 EXPORT_SYMBOL(lib_copy_kiov2buf);
170 EXPORT_SYMBOL(lib_copy_buf2kiov);
171 EXPORT_SYMBOL(lib_extract_kiov);
172 EXPORT_SYMBOL(lib_finalize);
173 EXPORT_SYMBOL(lib_parse);
174 EXPORT_SYMBOL(lib_create_reply_msg);
175 EXPORT_SYMBOL(lib_init);
176 EXPORT_SYMBOL(lib_fini);
177
178 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
179 MODULE_DESCRIPTION("Portals v3.1");
180 MODULE_LICENSE("GPL");
181
182 cfs_module(portals, "1.0.0", init_kportals_module, exit_kportals_module);