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 CONNMGR_REQUEST_PORTAL 1
38 #define CONNMGR_REPLY_PORTAL 2
39 #define OSC_REQUEST_PORTAL 3
40 #define OSC_REPLY_PORTAL 4
41 #define OSC_BULK_PORTAL 5
42 #define OST_REQUEST_PORTAL 6
43 #define OST_REPLY_PORTAL 7
44 #define OST_BULK_PORTAL 8
45 #define MDC_REQUEST_PORTAL 9
46 #define MDC_REPLY_PORTAL 10
47 #define MDC_BULK_PORTAL 11
48 #define MDS_REQUEST_PORTAL 12
49 #define MDS_REPLY_PORTAL 13
50 #define MDS_BULK_PORTAL 14
51 #define LDLM_REQUEST_PORTAL 15
52 #define LDLM_REPLY_PORTAL 16
53 #define LDLM_CLI_REQUEST_PORTAL 17
54 #define LDLM_CLI_REPLY_PORTAL 18
56 /* default rpc ring length */
57 #define RPC_RING_LENGTH 2
59 #define SVC_STOPPING 1
64 #define SVC_HA_EVENT 32
68 #define LUSTRE_CONN_NEW 1
69 #define LUSTRE_CONN_CON 2
70 #define LUSTRE_CONN_RECOVD 3
71 #define LUSTRE_CONN_FULL 4
73 struct ptlrpc_connection {
74 struct list_head c_link;
75 struct lustre_peer c_peer;
78 __u32 c_generation; /* changes upon new connection */
79 __u32 c_epoch; /* changes when peer changes */
80 __u32 c_bootcount; /* peer's boot count */
92 struct ptlrpc_client {
93 struct obd_device *cli_obd;
94 __u32 cli_request_portal;
95 __u32 cli_reply_portal;
97 struct semaphore cli_rpc_sem; /* limits outstanding requests */
99 spinlock_t cli_lock; /* protects lists */
100 struct list_head cli_sending_head;
101 struct list_head cli_sent_head;
102 struct list_head cli_ha_item;
104 struct recovd_obd *cli_recovd;
108 #define PTL_RPC_TYPE_REQUEST 2
109 #define PTL_RPC_TYPE_REPLY 3
111 /* state flags of requests */
112 #define PTL_RPC_FL_INTR 1
113 #define PTL_RPC_FL_REPLY 2
114 #define PTL_RPC_FL_SENT 4
115 #define PTL_BULK_FL_SENT 8
116 #define PTL_BULK_FL_RCVD 16
117 #define PTL_RPC_FL_ERR 32
118 #define PTL_RPC_FL_TIMEOUT 64
120 struct ptlrpc_request {
121 int rq_type; /* one of PTL_RPC_REQUEST, PTL_RPC_REPLY, PTL_RPC_BULK */
123 struct list_head rq_list;
124 struct obd_device *rq_obd;
130 struct lustre_msg *rq_reqmsg;
133 struct lustre_msg *rq_repmsg;
139 // void * rq_reply_handle;
140 wait_queue_head_t rq_wait_for_rep;
143 ptl_md_t rq_reply_md;
144 ptl_handle_md_t rq_reply_md_h;
145 ptl_handle_me_t rq_reply_me_h;
147 /* outgoing req/rep */
149 ptl_handle_md_t rq_req_md_h;
151 struct ptlrpc_connection *rq_connection;
152 struct ptlrpc_client *rq_client;
155 struct ptlrpc_bulk_desc {
157 struct ptlrpc_connection *b_connection;
161 int (*b_cb)(struct ptlrpc_bulk_desc *, void *);
163 struct obd_conn b_conn;
166 wait_queue_head_t b_waitq;
169 ptl_handle_md_t b_md_h;
170 ptl_handle_me_t b_me_h;
173 struct ptlrpc_service {
177 /* incoming request buffers */
178 /* FIXME: perhaps a list of EQs, if multiple NIs are used? */
179 char *srv_buf[RPC_RING_LENGTH];
180 __u32 srv_ref_count[RPC_RING_LENGTH];
181 ptl_handle_me_t srv_me_h[RPC_RING_LENGTH];
183 __u32 srv_ring_length;
184 __u32 srv_req_portal;
185 __u32 srv_rep_portal;
190 ptl_handle_eq_t srv_eq_h;
193 struct lustre_peer srv_self;
194 ptl_process_id_t srv_id;
196 struct task_struct *srv_thread;
197 wait_queue_head_t srv_waitq;
198 wait_queue_head_t srv_ctl_waitq;
201 struct list_head srv_reqs;
203 int (*srv_handler)(struct obd_device *obddev,
204 struct ptlrpc_service *svc,
205 struct ptlrpc_request *req);
208 typedef int (*svc_handler_t)(struct obd_device *obddev,
209 struct ptlrpc_service *svc,
210 struct ptlrpc_request *req);
212 /* rpc/connection.c */
213 struct ptlrpc_connection *ptlrpc_get_connection(struct lustre_peer *peer);
214 int ptlrpc_put_connection(struct ptlrpc_connection *c);
215 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
216 void ptlrpc_init_connection(void);
217 void ptlrpc_cleanup_connection(void);
220 int ptlrpc_check_bulk_sent(struct ptlrpc_bulk_desc *);
221 int ptlrpc_send_bulk(struct ptlrpc_bulk_desc *, int portal);
222 int ptlrpc_register_bulk(struct ptlrpc_bulk_desc *);
223 int ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *bulk);
224 int ptlrpc_reply(struct ptlrpc_service *svc, struct ptlrpc_request *req);
225 int ptlrpc_error(struct ptlrpc_service *svc, struct ptlrpc_request *req);
226 int ptl_send_rpc(struct ptlrpc_request *request);
227 void ptlrpc_link_svc_me(struct ptlrpc_service *service, int i);
230 void ptlrpc_init_client(struct recovd_obd *, int req_portal, int rep_portal,
231 struct ptlrpc_client *);
232 struct ptlrpc_connection *ptlrpc_uuid_to_connection(char *uuid);
233 int ptlrpc_queue_wait(struct ptlrpc_request *req);
234 struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl,
235 struct ptlrpc_connection *u, int opcode,
236 int count, int *lengths, char **bufs);
237 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
238 void ptlrpc_free_req(struct ptlrpc_request *request);
239 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct ptlrpc_connection *);
240 int ptlrpc_check_status(struct ptlrpc_request *req, int err);
243 struct ptlrpc_service *
244 ptlrpc_init_svc(__u32 bufsize, int req_portal, int rep_portal, char *uuid,
246 void ptlrpc_stop_thread(struct ptlrpc_service *svc);
247 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
249 int rpc_unregister_service(struct ptlrpc_service *service);
251 struct ptlrpc_svc_data {
253 struct ptlrpc_service *svc;
254 struct obd_device *dev;
257 /* rpc/pack_generic.c */
258 int lustre_pack_msg(int count, int *lens, char **bufs, int *len,
259 struct lustre_msg **msg);
260 int lustre_msg_size(int count, int *lengths);
261 int lustre_unpack_msg(struct lustre_msg *m, int len);
262 void *lustre_msg_buf(struct lustre_msg *m, int n);