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 #define LDLM_REQUEST_PORTAL 13
54 #define LDLM_REPLY_PORTAL 14
56 /* default rpc ring length */
57 #define RPC_RING_LENGTH 2
59 #define SVC_STOPPING 1
67 struct ptlrpc_client {
68 struct lustre_peer cli_server;
69 struct obd_device *cli_obd;
70 struct list_head cli_sending_head;
71 struct list_head cli_sent_head;
72 __u32 cli_request_portal;
73 __u32 cli_reply_portal;
77 __u32 cli_generation; /* changes upon new connection */
78 __u32 cli_epoch; /* changes when peer changes */
79 __u32 cli_bootcount; /* peer's boot count */
80 struct semaphore cli_rpc_sem;
83 /* These do double-duty in rq_type and rq_flags */
84 #define PTL_RPC_INTR 1
85 #define PTL_RPC_REQUEST 2
86 #define PTL_RPC_REPLY 3
87 #define PTL_RPC_BULK 4
88 #define PTL_RPC_SENT 5
89 #define PTL_BULK_SENT 6
90 #define PTL_BULK_RCVD 7
93 struct ptlrpc_request {
94 int rq_type; /* one of PTL_RPC_REQUEST, PTL_RPC_REPLY, PTL_RPC_BULK */
96 struct list_head rq_list;
97 struct obd_device *rq_obd;
105 struct lustre_msg *rq_reqmsg;
109 struct lustre_msg *rq_repmsg;
114 void * rq_reply_handle;
115 wait_queue_head_t rq_wait_for_rep;
118 ptl_md_t rq_reply_md;
119 ptl_handle_md_t rq_reply_md_h;
120 ptl_handle_me_t rq_reply_me_h;
122 /* outgoing req/rep */
124 ptl_handle_md_t rq_req_md_h;
126 __u32 rq_reply_portal;
129 struct lustre_peer rq_peer;
130 struct ptlrpc_client *rq_client;
133 struct ptlrpc_bulk_desc {
135 struct lustre_peer b_peer;
139 int (*b_cb)(struct ptlrpc_bulk_desc *, void *);
141 struct obd_conn b_conn;
144 wait_queue_head_t b_waitq;
147 ptl_handle_md_t b_md_h;
148 ptl_handle_me_t b_me_h;
151 struct ptlrpc_service {
152 /* incoming request buffers */
153 /* FIXME: perhaps a list of EQs, if multiple NIs are used? */
154 char *srv_buf[RPC_RING_LENGTH];
155 __u32 srv_ref_count[RPC_RING_LENGTH];
156 ptl_handle_me_t srv_me_h[RPC_RING_LENGTH];
158 __u32 srv_ring_length;
159 __u32 srv_req_portal;
160 __u32 srv_rep_portal;
165 ptl_handle_eq_t srv_eq_h;
168 struct lustre_peer srv_self;
169 ptl_process_id_t srv_id;
171 struct task_struct *srv_thread;
172 wait_queue_head_t srv_waitq;
173 wait_queue_head_t srv_ctl_waitq;
176 struct list_head srv_reqs;
178 int (*srv_handler)(struct obd_device *obddev,
179 struct ptlrpc_service *svc,
180 struct ptlrpc_request *req);
183 typedef int (*svc_handler_t)(struct obd_device *obddev,
184 struct ptlrpc_service *svc,
185 struct ptlrpc_request *req);
190 int ptlrpc_check_bulk_sent(struct ptlrpc_bulk_desc *);
191 int ptlrpc_send_bulk(struct ptlrpc_bulk_desc *, int portal);
192 int ptl_send_buf(struct ptlrpc_request *, struct lustre_peer *, int portal);
193 int ptlrpc_register_bulk(struct ptlrpc_bulk_desc *);
194 int ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *bulk);
195 int ptlrpc_reply(struct obd_device *obddev, struct ptlrpc_service *svc,
196 struct ptlrpc_request *req);
197 int ptlrpc_error(struct obd_device *obddev, struct ptlrpc_service *svc,
198 struct ptlrpc_request *req);
199 int ptl_send_rpc(struct ptlrpc_request *request, struct ptlrpc_client *cl);
200 void ptlrpc_link_svc_me(struct ptlrpc_service *service, int i);
203 void ptlrpc_init_client(int dev, int req_portal, int rep_portal,
204 struct ptlrpc_client *cl);
205 int ptlrpc_connect_client(int dev, char *uuid, struct ptlrpc_client *cl);
206 int ptlrpc_queue_wait(struct ptlrpc_client *cl, struct ptlrpc_request *req);
207 int ptlrpc_queue_req(struct ptlrpc_client *peer, struct ptlrpc_request *req);
208 struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl, int opcode,
209 int count, int *lengths, char **bufs);
210 void ptlrpc_free_req(struct ptlrpc_request *request);
211 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct lustre_peer *);
212 int ptlrpc_check_status(struct ptlrpc_request *req, int err);
215 struct ptlrpc_service *
216 ptlrpc_init_svc(__u32 bufsize, int req_portal, int rep_portal, char *uuid,
218 void ptlrpc_stop_thread(struct ptlrpc_service *svc);
219 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
221 int rpc_unregister_service(struct ptlrpc_service *service);
223 struct ptlrpc_svc_data {
225 struct ptlrpc_service *svc;
226 struct obd_device *dev;
229 /* rpc/pack_generic.c */
230 int lustre_pack_msg(int count, int *lens, char **bufs, int *len, char **buf);
231 int lustre_msg_size(int count, int *lengths);
232 int lustre_unpack_msg(char *buf, int len);
233 void *lustre_msg_buf(struct lustre_msg *m, int n);