Whamcloud - gitweb
*** empty log message ***
[fs/lustre-release.git] / lustre / include / linux / lustre_net.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 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
23 #ifndef _LUSTRE_NET_H
24 #define _LUSTRE_NET_H
25
26 #include <linux/kp30.h>
27 #include <linux/obd_support.h>
28 #include <linux/obd_class.h>
29 #include <portals/p30.h>
30 #include <linux/lustre_idl.h>
31
32 /* FOO_REQUEST_PORTAL is for incoming requests on the FOO
33  * FOO_REPLY_PORTAL   is for incoming replies on the FOO
34  * FOO_BULK_PORTAL    is for incoming bulk on the FOO
35  */
36
37 #define OSC_REQUEST_PORTAL 1
38 #define OSC_REPLY_PORTAL   2
39 #define OSC_BULK_PORTAL    3
40
41 #define OST_REQUEST_PORTAL 4
42 #define OST_REPLY_PORTAL   5
43 #define OST_BULK_PORTAL    6
44
45 #define MDC_REQUEST_PORTAL 7
46 #define MDC_REPLY_PORTAL   8
47 #define MDC_BULK_PORTAL    9
48
49 #define MDS_REQUEST_PORTAL 10
50 #define MDS_REPLY_PORTAL   11
51 #define MDS_BULK_PORTAL    12
52
53 /* default rpc ring length */
54 #define RPC_RING_LENGTH    2
55
56 /* generic wrappable next */
57 #define NEXT_INDEX(index, max)  (((index+1) >= max) ? 0 : (index+1))
58
59 #define SVC_STOPPING 1
60 #define SVC_RUNNING 2
61 #define SVC_STOPPED 4
62 #define SVC_KILLED  8
63 #define SVC_EVENT  16
64 #define SVC_LIST   32
65 #define SVC_SIGNAL 64
66
67 typedef int (*rep_unpack_t)(char *, int, struct ptlrep_hdr **, union ptl_rep *);
68 typedef int (*req_pack_t)(char *, int, char *, int, struct ptlreq_hdr **,
69                           union ptl_req*, int *, char **); 
70
71 typedef int (*req_unpack_t)(char *buf, int len, struct ptlreq_hdr **, 
72                             union ptl_req *);
73 typedef int (*rep_pack_t)(char *buf1, int len1, char *buf2, int len2,
74                           struct ptlrep_hdr **, union ptl_rep*, 
75                           int *replen, char **repbuf); 
76
77 struct ptlrpc_client {
78         struct lustre_peer cli_server;
79         struct obd_device *cli_obd;
80         __u32 cli_request_portal;
81         __u32 cli_reply_portal;
82         rep_unpack_t cli_rep_unpack;
83         req_pack_t cli_req_pack;
84
85         spinlock_t cli_lock;
86         __u32 cli_xid;
87 };
88
89 /* These do double-duty in rq_type and rq_flags */
90 #define PTL_RPC_INTR    1
91 #define PTL_RPC_REQUEST 2
92 #define PTL_RPC_REPLY   3
93 #define PTL_RPC_BULK    4
94 #define PTL_RPC_SENT    5
95 #define PTL_BULK_SENT   6
96 #define PTL_BULK_RCVD   6
97
98 struct ptlrpc_request { 
99         int rq_type; /* one of PTL_RPC_REQUEST, PTL_RPC_REPLY, PTL_RPC_BULK */
100         struct list_head rq_list;
101         struct obd_device *rq_obd;
102         int rq_status;
103         int rq_flags; 
104         __u32 rq_connid;
105         __u32 rq_xid;
106
107         char *rq_reqbuf;
108         int rq_reqlen;
109         struct ptlreq_hdr *rq_reqhdr;
110         union ptl_req rq_req;
111
112         char *rq_repbuf;
113         int rq_replen;
114         struct ptlrep_hdr *rq_rephdr;
115         union ptl_rep rq_rep;
116
117         char *rq_bulkbuf;
118         int rq_bulklen;
119
120         void * rq_reply_handle;
121         wait_queue_head_t rq_wait_for_rep;
122
123         /* incoming reply */
124         ptl_md_t rq_reply_md;
125         ptl_handle_md_t rq_reply_md_h;
126         ptl_handle_me_t rq_reply_me_h;
127
128         /* outgoing req/rep */
129         ptl_md_t rq_req_md;
130         ptl_handle_md_t rq_req_md_h;
131
132         __u32 rq_reply_portal;
133         __u32 rq_req_portal;
134
135         struct lustre_peer rq_peer;
136 };
137
138 struct ptlrpc_bulk_desc {
139         int b_flags;
140         struct lustre_peer b_peer;
141         __u32 b_portal;
142         char *b_buf;
143         int b_buflen;
144         int (*b_cb)(struct ptlrpc_bulk_desc *, void *);
145         struct page *b_page;
146         struct obd_conn b_conn;
147         __u32 b_xid;
148
149         wait_queue_head_t b_waitq;
150
151         ptl_md_t b_md;
152         ptl_handle_md_t b_md_h;
153         ptl_handle_me_t b_me_h;
154 };
155
156 struct ptlrpc_service {
157         /* incoming request buffers */
158         /* FIXME: perhaps a list of EQs, if multiple NIs are used? */
159         char *srv_buf[RPC_RING_LENGTH];
160         __u32 srv_buf_size;
161         __u32 srv_me_active;
162         __u32 srv_me_tail;
163         __u32 srv_md_active;
164         __u32 srv_ring_length;
165         __u32 srv_req_portal;
166         __u32 srv_rep_portal;
167         __u32 srv_ref_count[RPC_RING_LENGTH];
168         ptl_handle_me_t srv_me_h[RPC_RING_LENGTH];
169         ptl_process_id_t srv_id;
170         ptl_md_t srv_md[RPC_RING_LENGTH];
171         ptl_handle_md_t srv_md_h[RPC_RING_LENGTH];
172         __u32 srv_xid;
173
174         /* event queue */
175         ptl_handle_eq_t srv_eq_h;
176
177         __u32 srv_flags; 
178         struct lustre_peer srv_self;
179         struct task_struct *srv_thread;
180         wait_queue_head_t srv_waitq;
181         wait_queue_head_t srv_ctl_waitq;
182         int ost_flags;
183
184         spinlock_t srv_lock;
185         struct list_head srv_reqs;
186         ptl_event_t  srv_ev;
187         req_unpack_t      srv_req_unpack;
188         rep_pack_t        srv_rep_pack;
189         int (*srv_handler)(struct obd_device *obddev, 
190                            struct ptlrpc_service *svc,
191                            struct ptlrpc_request *req);
192 };
193
194 typedef int (*svc_handler_t)(struct obd_device *obddev,
195                              struct ptlrpc_service *svc,
196                              struct ptlrpc_request *req);
197
198
199
200 /* rpc/niobuf.c */
201 int ptlrpc_check_bulk_sent(struct ptlrpc_bulk_desc *);
202 int ptlrpc_send_bulk(struct ptlrpc_bulk_desc *, int portal);
203 int ptl_send_buf(struct ptlrpc_request *, struct lustre_peer *, int portal);
204 int ptlrpc_register_bulk(struct ptlrpc_bulk_desc *);
205 int ptlrpc_reply(struct obd_device *obddev, struct ptlrpc_service *svc,
206                  struct ptlrpc_request *req);
207 int ptlrpc_error(struct obd_device *obddev, struct ptlrpc_service *svc,
208                  struct ptlrpc_request *req);
209 int ptl_send_rpc(struct ptlrpc_request *request, struct lustre_peer *peer);
210 int ptl_received_rpc(struct ptlrpc_service *service);
211
212 /* rpc/client.c */
213 int ptlrpc_connect_client(int dev, char *uuid, int req_portal, int rep_portal, 
214                           req_pack_t req_pack, rep_unpack_t rep_unpack,
215                           struct ptlrpc_client *cl);
216 int ptlrpc_queue_wait(struct ptlrpc_client *cl, struct ptlrpc_request *req);
217 int ptlrpc_queue_req(struct ptlrpc_client *peer, struct ptlrpc_request *req);
218 struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl, 
219                                        int opcode, int namelen, char *name,
220                                        int tgtlen, char *tgt);
221 void ptlrpc_free_req(struct ptlrpc_request *request);
222 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct lustre_peer *);
223
224 /* rpc/service.c */
225 struct ptlrpc_service *
226 ptlrpc_init_svc(__u32 bufsize, int req_portal, int rep_portal, char *uuid,
227                 req_unpack_t unpack, rep_pack_t pack, svc_handler_t);
228 void ptlrpc_stop_thread(struct ptlrpc_service *svc);
229 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
230                         char *name);
231 int rpc_register_service(struct ptlrpc_service *service, char *uuid);
232 int rpc_unregister_service(struct ptlrpc_service *service);
233
234 struct ptlrpc_svc_data { 
235         char *name;
236         struct ptlrpc_service *svc; 
237         struct obd_device *dev;
238 }; 
239
240 #endif