1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
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>
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
37 #define OSC_REQUEST_PORTAL 1
38 #define OSC_REPLY_PORTAL 2
39 #define OSC_BULK_PORTAL 3
41 #define OST_REQUEST_PORTAL 4
42 #define OST_REPLY_PORTAL 5
43 #define OST_BULK_PORTAL 6
45 #define MDC_REQUEST_PORTAL 7
46 #define MDC_REPLY_PORTAL 8
47 #define MDC_BULK_PORTAL 9
49 #define MDS_REQUEST_PORTAL 10
50 #define MDS_REPLY_PORTAL 11
51 #define MDS_BULK_PORTAL 12
53 /* default rpc ring length */
54 #define RPC_RING_LENGTH 2
56 #define SVC_STOPPING 1
64 typedef int (*rep_unpack_t)(char *, int, struct ptlrep_hdr **, union ptl_rep *);
65 typedef int (*req_pack_t)(char *, int, char *, int, struct ptlreq_hdr **,
66 union ptl_req*, int *, char **);
68 typedef int (*req_unpack_t)(char *buf, int len, struct ptlreq_hdr **,
70 typedef int (*rep_pack_t)(char *buf1, int len1, char *buf2, int len2,
71 struct ptlrep_hdr **, union ptl_rep*,
72 int *replen, char **repbuf);
74 struct ptlrpc_client {
75 struct lustre_peer cli_server;
76 struct obd_device *cli_obd;
77 __u32 cli_request_portal;
78 __u32 cli_reply_portal;
79 rep_unpack_t cli_rep_unpack;
80 req_pack_t cli_req_pack;
86 /* These do double-duty in rq_type and rq_flags */
87 #define PTL_RPC_INTR 1
88 #define PTL_RPC_REQUEST 2
89 #define PTL_RPC_REPLY 3
90 #define PTL_RPC_BULK 4
91 #define PTL_RPC_SENT 5
92 #define PTL_BULK_SENT 6
93 #define PTL_BULK_RCVD 6
95 struct ptlrpc_request {
96 int rq_type; /* one of PTL_RPC_REQUEST, PTL_RPC_REPLY, PTL_RPC_BULK */
98 struct list_head rq_list;
99 struct obd_device *rq_obd;
107 struct ptlreq_hdr *rq_reqhdr;
108 union ptl_req rq_req;
112 struct ptlrep_hdr *rq_rephdr;
113 union ptl_rep rq_rep;
118 void * rq_reply_handle;
119 wait_queue_head_t rq_wait_for_rep;
122 ptl_md_t rq_reply_md;
123 ptl_handle_md_t rq_reply_md_h;
124 ptl_handle_me_t rq_reply_me_h;
126 /* outgoing req/rep */
128 ptl_handle_md_t rq_req_md_h;
130 __u32 rq_reply_portal;
133 struct lustre_peer rq_peer;
136 struct ptlrpc_bulk_desc {
138 struct lustre_peer b_peer;
142 int (*b_cb)(struct ptlrpc_bulk_desc *, void *);
144 struct obd_conn b_conn;
147 wait_queue_head_t b_waitq;
150 ptl_handle_md_t b_md_h;
151 ptl_handle_me_t b_me_h;
154 struct ptlrpc_service {
155 /* incoming request buffers */
156 /* FIXME: perhaps a list of EQs, if multiple NIs are used? */
157 char *srv_buf[RPC_RING_LENGTH];
161 __u32 srv_ring_length;
162 __u32 srv_req_portal;
163 __u32 srv_rep_portal;
164 __u32 srv_ref_count[RPC_RING_LENGTH];
165 ptl_handle_me_t srv_me_h[RPC_RING_LENGTH];
166 ptl_process_id_t srv_id;
167 ptl_md_t srv_md[RPC_RING_LENGTH];
168 ptl_handle_md_t srv_md_h[RPC_RING_LENGTH];
172 ptl_handle_eq_t srv_eq_h;
175 struct lustre_peer srv_self;
176 struct task_struct *srv_thread;
177 wait_queue_head_t srv_waitq;
178 wait_queue_head_t srv_ctl_waitq;
182 struct list_head srv_reqs;
184 req_unpack_t srv_req_unpack;
185 rep_pack_t srv_rep_pack;
186 int (*srv_handler)(struct obd_device *obddev,
187 struct ptlrpc_service *svc,
188 struct ptlrpc_request *req);
191 typedef int (*svc_handler_t)(struct obd_device *obddev,
192 struct ptlrpc_service *svc,
193 struct ptlrpc_request *req);
198 int ptlrpc_check_bulk_sent(struct ptlrpc_bulk_desc *);
199 int ptlrpc_send_bulk(struct ptlrpc_bulk_desc *, int portal);
200 int ptl_send_buf(struct ptlrpc_request *, struct lustre_peer *, int portal);
201 int ptlrpc_register_bulk(struct ptlrpc_bulk_desc *);
202 int ptlrpc_reply(struct obd_device *obddev, struct ptlrpc_service *svc,
203 struct ptlrpc_request *req);
204 int ptlrpc_error(struct obd_device *obddev, struct ptlrpc_service *svc,
205 struct ptlrpc_request *req);
206 int ptl_send_rpc(struct ptlrpc_request *request, struct lustre_peer *peer);
209 int ptlrpc_connect_client(int dev, char *uuid, int req_portal, int rep_portal,
210 req_pack_t req_pack, rep_unpack_t rep_unpack,
211 struct ptlrpc_client *cl);
212 int ptlrpc_queue_wait(struct ptlrpc_client *cl, struct ptlrpc_request *req);
213 int ptlrpc_queue_req(struct ptlrpc_client *peer, struct ptlrpc_request *req);
214 struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl,
215 int opcode, int namelen, char *name,
216 int tgtlen, char *tgt);
217 void ptlrpc_free_req(struct ptlrpc_request *request);
218 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct lustre_peer *);
219 int ptlrpc_check_status(struct ptlrpc_request *req, int err);
222 struct ptlrpc_service *
223 ptlrpc_init_svc(__u32 bufsize, int req_portal, int rep_portal, char *uuid,
224 req_unpack_t unpack, rep_pack_t pack, svc_handler_t);
225 void ptlrpc_stop_thread(struct ptlrpc_service *svc);
226 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
228 int rpc_register_service(struct ptlrpc_service *service, char *uuid);
229 int rpc_unregister_service(struct ptlrpc_service *service);
231 struct ptlrpc_svc_data {
233 struct ptlrpc_service *svc;
234 struct obd_device *dev;