Whamcloud - gitweb
Land b_smallfix onto HEAD (20040512_1806)
[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, 2003 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 #ifdef __KERNEL__
27 #include <linux/version.h>
28 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
29 #include <linux/tqueue.h>
30 #else
31 #include <linux/workqueue.h>
32 #endif
33 #endif
34
35 #include <linux/kp30.h>
36 // #include <linux/obd.h>
37 #include <portals/p30.h>
38 #include <linux/lustre_idl.h>
39 #include <linux/lustre_ha.h>
40 #include <linux/lustre_import.h>
41 #include <linux/lprocfs_status.h>
42
43 /* MD flags we _always_ use */
44 #define PTLRPC_MD_OPTIONS  (PTL_MD_EVENT_START_DISABLE | \
45                             PTL_MD_LUSTRE_COMPLETION_SEMANTICS)
46
47 /* Define some large-ish maxima for bulk I/O 
48  * CAVEAT EMPTOR, with multinet (i.e. gateways forwarding between networks)
49  * these limits are system wide and not interface-local. */
50 #define PTLRPC_MAX_BRW_SIZE     (1 << 20)
51 #define PTLRPC_MAX_BRW_PAGES    512
52
53 /* ...reduce to fit... */
54
55 #if CRAY_PORTALS
56 /* include a cray header here if relevant
57  * NB liblustre SIZE/PAGES is affected too, but it merges contiguous
58  * chunks, so FTTB, it always used contiguous MDs */
59 #else
60 # include <portals/lib-types.h>
61 #endif
62
63 #if (defined(PTL_MTU) && (PTL_MTU < PTLRPC_MAX_BRW_SIZE))
64 # undef  PTLRPC_MAX_BRW_SIZE
65 # define PTLRPC_MAX_BRW_SIZE  PTL_MTU
66 #endif
67 #if (defined(PTL_MD_MAX_IOV) && (PTL_MD_MAX_IOV < PTLRPC_MAX_BRW_PAGES ))
68 # undef  PTLRPC_MAX_BRW_PAGES
69 # define PTLRPC_MAX_BRW_PAGES PTL_MD_MAX_IOV
70 #endif
71
72 /* ...and make consistent... */
73
74 #if (PTLRPC_MAX_BRW_SIZE > PTLRPC_MAX_BRW_PAGES * PAGE_SIZE)
75 # undef  PTLRPC_MAX_BRW_SIZE
76 # define PTLRPC_MAX_BRW_SIZE   (PTLRPC_MAX_BRW_PAGES * PAGE_SIZE)
77 #else
78 # undef  PTLRPC_MAX_BRW_PAGES
79 # define PTLRPC_MAX_BRW_PAGES  (PTLRPC_MAX_BRW_SIZE / PAGE_SIZE)
80 #endif
81
82 #if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
83 #error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
84 #endif
85
86 /* Size over which to OBD_VMALLOC() rather than OBD_ALLOC() service request
87  * buffers */
88 #define SVC_BUF_VMALLOC_THRESHOLD (2*PAGE_SIZE)
89
90 /* The following constants determine how much memory is devoted to
91  * buffering in the lustre services.
92  *
93  * ?_NEVENTS            # event queue entries
94  *
95  * ?_NBUFS              # request buffers
96  * ?_BUFSIZE            # bytes in a single request buffer
97  * total memory = ?_NBUFS * ?_BUFSIZE
98  *
99  * ?_MAXREQSIZE         # maximum request service will receive
100  * messages larger than ?_MAXREQSIZE are dropped.
101  * request buffers are auto-unlinked when less than ?_MAXREQSIZE
102  * is left in them.
103  */
104
105 #define LDLM_NUM_THREADS        min(smp_num_cpus * smp_num_cpus * 8, 64)
106 #define LDLM_NBUF_MAX   512UL
107 #define LDLM_BUFSIZE    (8 * 1024)
108 #define LDLM_MAXREQSIZE (5 * 1024)
109 #define LDLM_MAXMEM      (num_physpages*(PAGE_SIZE/1024))
110 #define LDLM_NBUFS       min(LDLM_MAXMEM/LDLM_BUFSIZE, LDLM_NBUF_MAX)
111
112 #define MDT_MAX_THREADS 32UL
113 #define MDT_NUM_THREADS max(min_t(unsigned long, num_physpages / 8192, \
114                                   MDT_MAX_THREADS), 2UL)
115 #define MDS_NBUF_MAX    4096UL
116 #define MDS_BUFSIZE     (8 * 1024)
117 /* Assume file name length = FNAME_MAX = 256 (true for extN).
118  *        path name length = PATH_MAX = 4096
119  *        LOV MD size max  = EA_MAX = 4000
120  * symlink:  FNAME_MAX + PATH_MAX  <- largest
121  * link:     FNAME_MAX + PATH_MAX  (mds_rec_link < mds_rec_create)
122  * rename:   FNAME_MAX + FNAME_MAX
123  * open:     FNAME_MAX + EA_MAX
124  *
125  * MDS_MAXREQSIZE ~= 4736 bytes =
126  * lustre_msg + ldlm_request + mds_body + mds_rec_create + FNAME_MAX + PATH_MAX
127  *
128  * Realistic size is about 512 bytes (20 character name + 128 char symlink),
129  * except in the open case where there are a large number of OSTs in a LOV.
130  */
131 #define MDS_MAXREQSIZE  (5 * 1024)
132 #define MDS_MAXMEM      (num_physpages*(PAGE_SIZE/128))
133 #define MDS_NBUFS       min(MDS_MAXMEM/MDS_BUFSIZE, MDS_NBUF_MAX)
134
135 #define OST_MAX_THREADS 36UL
136 #define OST_NUM_THREADS max(min_t(unsigned long, num_physpages / 8192, \
137                                   OST_MAX_THREADS), 2UL)
138 #define OST_NBUF_MAX    5000UL
139 #define OST_BUFSIZE     (8 * 1024)
140 /* OST_MAXREQSIZE ~= 1640 bytes =
141  * lustre_msg + obdo + 16 * obd_ioobj + 64 * niobuf_remote
142  *
143  * - single object with 16 pages is 512 bytes
144  * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
145  */
146 #define OST_MAXREQSIZE  (5 * 1024)
147 #define OST_MAXMEM      (num_physpages*(PAGE_SIZE/128))
148 #define OST_NBUFS       min(OST_MAXMEM/OST_BUFSIZE, OST_NBUF_MAX)
149
150 #define PTLBD_NUM_THREADS        4
151 #define PTLBD_NBUFS      20
152 #define PTLBD_BUFSIZE    (32 * 1024)
153 #define PTLBD_MAXREQSIZE 1024
154
155 struct ptlrpc_peer {
156         ptl_nid_t         peer_nid;
157         struct ptlrpc_ni *peer_ni;
158 };
159
160 struct ptlrpc_connection {
161         struct list_head        c_link;
162         struct ptlrpc_peer      c_peer;
163         struct obd_uuid         c_remote_uuid;
164         atomic_t                c_refcount;
165 };
166
167 struct ptlrpc_client {
168         __u32                     cli_request_portal;
169         __u32                     cli_reply_portal;
170         char                     *cli_name;
171 };
172
173 /* state flags of requests */
174 /* XXX only ones left are those used by the bulk descs as well! */
175 #define PTL_RPC_FL_INTR      (1 << 0)  /* reply wait was interrupted by user */
176 #define PTL_RPC_FL_TIMEOUT   (1 << 7)  /* request timed out waiting for reply */
177
178 #define REQ_MAX_ACK_LOCKS 8
179
180 #define SWAB_PARANOIA 1
181 #if SWAB_PARANOIA
182 /* unpacking: assert idx not unpacked already */
183 #define LASSERT_REQSWAB(rq, idx)                                \
184 do {                                                            \
185         LASSERT ((idx) < sizeof ((rq)->rq_req_swab_mask) * 8);  \
186         LASSERT (((rq)->rq_req_swab_mask & (1 << (idx))) == 0); \
187         (rq)->rq_req_swab_mask |= (1 << (idx));                 \
188 } while (0)
189
190 #define LASSERT_REPSWAB(rq, idx)                                \
191 do {                                                            \
192         LASSERT ((idx) < sizeof ((rq)->rq_rep_swab_mask) * 8);  \
193         LASSERT (((rq)->rq_rep_swab_mask & (1 << (idx))) == 0); \
194         (rq)->rq_rep_swab_mask |= (1 << (idx));                 \
195 } while (0)
196
197 /* just looking: assert idx already unpacked */
198 #define LASSERT_REQSWABBED(rq, idx)                     \
199 LASSERT ((idx) < sizeof ((rq)->rq_req_swab_mask) * 8 && \
200          ((rq)->rq_req_swab_mask & (1 << (idx))) != 0)
201
202 #define LASSERT_REPSWABBED(rq, idx)                     \
203 LASSERT ((idx) < sizeof ((rq)->rq_rep_swab_mask) * 8 && \
204          ((rq)->rq_rep_swab_mask & (1 << (idx))) != 0)
205 #else
206 #define LASSERT_REQSWAB(rq, idx)
207 #define LASSERT_REPSWAB(rq, idx)
208 #define LASSERT_REQSWABBED(rq, idx)
209 #define LASSERT_REPSWABBED(rq, idx)
210 #endif
211
212 union ptlrpc_async_args {
213         /* Scratchpad for passing args to completion interpreter. Users
214          * cast to the struct of their choosing, and LASSERT that this is
215          * big enough.  For _tons_ of context, OBD_ALLOC a struct and store
216          * a pointer to it here.  The pointer_arg ensures this struct is at
217          * least big enough for that. */
218         void      *pointer_arg[9];
219         __u64      space[4];
220 };
221
222 struct ptlrpc_request_set;
223 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
224
225 struct ptlrpc_request_set {
226         int               set_remaining; /* # uncompleted requests */
227         wait_queue_head_t set_waitq;
228         wait_queue_head_t *set_wakeup_ptr;
229         struct list_head  set_requests;
230         set_interpreter_func    set_interpret; /* completion callback */
231         union ptlrpc_async_args set_args; /* completion context */
232         /* locked so that any old caller can communicate requests to
233          * the set holder who can then fold them into the lock-free set */
234         spinlock_t        set_new_req_lock;
235         struct list_head  set_new_requests;
236 };
237
238 struct ptlrpc_bulk_desc;
239
240 /*
241  * ptlrpc callback & work item stuff
242  */
243 struct ptlrpc_cb_id {
244         void   (*cbid_fn)(ptl_event_t *ev);     /* specific callback fn */
245         void    *cbid_arg;                      /* additional arg */
246 };
247
248 #define RS_MAX_LOCKS 4
249 #define RS_DEBUG     1
250
251 struct ptlrpc_reply_state {
252         struct ptlrpc_cb_id   rs_cb_id;
253         struct list_head      rs_list;
254         struct list_head      rs_exp_list;
255         struct list_head      rs_obd_list;
256 #if RS_DEBUG
257         struct list_head      rs_debug_list;
258 #endif
259         /* updates to following flag serialised by srv_request_lock */
260         unsigned int          rs_difficult:1;   /* ACK/commit stuff */
261         unsigned int          rs_scheduled:1;   /* being handled? */
262         unsigned int          rs_scheduled_ever:1; /* any schedule attempts? */
263         unsigned int          rs_handled:1;     /* been handled yet? */
264         unsigned int          rs_on_net:1;      /* reply_out_callback pending? */
265
266         int                   rs_size;
267         __u64                 rs_transno;
268         __u64                 rs_xid;
269         struct obd_export    *rs_export;
270         struct ptlrpc_srv_ni *rs_srv_ni;
271         ptl_handle_md_t       rs_md_h;
272
273         /* locks awaiting client reply ACK */
274         int                   rs_nlocks;
275         struct lustre_handle  rs_locks[RS_MAX_LOCKS];
276         ldlm_mode_t           rs_modes[RS_MAX_LOCKS];
277         /* last member: variable sized reply message */
278         struct lustre_msg     rs_msg;
279 };
280
281 struct ptlrpc_request {
282         int rq_type; /* one of PTL_RPC_MSG_* */
283         struct list_head rq_list;
284         int rq_status;
285         spinlock_t rq_lock;
286         /* client-side flags */
287         unsigned int rq_intr:1, rq_replied:1, rq_err:1,
288                 rq_timedout:1, rq_resend:1, rq_restart:1, rq_replay:1,
289                 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
290                 rq_no_delay:1, rq_net_err:1;
291         int rq_phase;
292         /* client-side refcount for SENT race */
293         atomic_t rq_refcount;
294
295         int rq_request_portal; /* XXX FIXME bug 249 */
296         int rq_reply_portal; /* XXX FIXME bug 249 */
297
298         /* client-side # reply bytes actually received  */
299         int rq_nob_received;
300
301         int rq_reqlen;
302         struct lustre_msg *rq_reqmsg;
303
304         int rq_timeout;
305         int rq_replen;
306         struct lustre_msg *rq_repmsg;
307         __u64 rq_transno;
308         __u64 rq_xid;
309         struct list_head rq_replay_list;
310
311 #if SWAB_PARANOIA
312         __u32 rq_req_swab_mask;
313         __u32 rq_rep_swab_mask;
314 #endif
315
316         int rq_import_generation;
317         enum lustre_imp_state rq_send_state;
318
319         /* client+server request */
320         ptl_handle_md_t      rq_req_md_h;
321         struct ptlrpc_cb_id  rq_req_cbid;
322
323         /* server-side... */
324         struct timeval                     rq_arrival_time; /* request arrival time */
325         struct ptlrpc_reply_state         *rq_reply_state; /* separated reply state */
326         struct ptlrpc_request_buffer_desc *rq_rqbd; /* incoming request buffer */
327         
328         /* client-only incoming reply */
329         ptl_handle_md_t      rq_reply_md_h;
330         wait_queue_head_t    rq_reply_waitq;
331         struct ptlrpc_cb_id  rq_reply_cbid;
332         
333         struct ptlrpc_peer rq_peer; /* XXX see service.c can this be factored away? */
334         struct obd_export *rq_export;
335         struct obd_import *rq_import;
336         
337         void (*rq_replay_cb)(struct ptlrpc_request *);
338         void (*rq_commit_cb)(struct ptlrpc_request *);
339         void  *rq_cb_data;
340
341         struct ptlrpc_bulk_desc *rq_bulk;       /* client side bulk */
342         time_t rq_sent;                         /* when the request was sent */
343
344         /* Multi-rpc bits */
345         struct list_head rq_set_chain;
346         struct ptlrpc_request_set *rq_set;
347         void *rq_interpret_reply;               /* Async completion handler */
348         union ptlrpc_async_args rq_async_args;  /* Async completion context */
349         void * rq_ptlrpcd_data;
350 };
351
352
353 #define RQ_PHASE_NEW           0xebc0de00
354 #define RQ_PHASE_RPC           0xebc0de01
355 #define RQ_PHASE_BULK          0xebc0de02
356 #define RQ_PHASE_INTERPRET     0xebc0de03
357 #define RQ_PHASE_COMPLETE      0xebc0de04
358
359 /* Spare the preprocessor, spoil the bugs. */
360 #define FLAG(field, str) (field ? str : "")
361
362 #define DEBUG_REQ_FLAGS(req)                                                    \
363         ((req->rq_phase == RQ_PHASE_NEW) ? "New" :                              \
364          (req->rq_phase == RQ_PHASE_RPC) ? "Rpc" :                              \
365          (req->rq_phase == RQ_PHASE_INTERPRET) ? "Interpret" :                  \
366          (req->rq_phase == RQ_PHASE_COMPLETE) ? "Complete" : "?phase?"),        \
367         FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"),                    \
368         FLAG(req->rq_err, "E"),                                                 \
369         FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"),   \
370         FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"),                  \
371         FLAG(req->rq_no_resend, "N"),                                           \
372         FLAG(req->rq_waiting, "W")
373
374 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s"
375
376 #define DEBUG_REQ(level, req, fmt, args...)                                    \
377 do {                                                                           \
378 CDEBUG(level, "@@@ " fmt                                                       \
379        " req@%p x"LPD64"/t"LPD64" o%d->%s@%s:%d lens %d/%d ref %d fl "         \
380        REQ_FLAGS_FMT"/%x/%x rc %d/%d\n" , ## args, req, req->rq_xid,           \
381        req->rq_transno,                                                        \
382        req->rq_reqmsg ? req->rq_reqmsg->opc : -1,                              \
383        req->rq_import ? (char *)req->rq_import->imp_target_uuid.uuid : "<?>",  \
384        req->rq_import ?                                                        \
385           (char *)req->rq_import->imp_connection->c_remote_uuid.uuid : "<?>",  \
386        (req->rq_import && req->rq_import->imp_client) ?                        \
387            req->rq_import->imp_client->cli_request_portal : -1,                \
388        req->rq_reqlen, req->rq_replen,                                         \
389        atomic_read(&req->rq_refcount),                                         \
390        DEBUG_REQ_FLAGS(req),                                                   \
391        req->rq_reqmsg ? req->rq_reqmsg->flags : 0,                             \
392        req->rq_repmsg ? req->rq_repmsg->flags : 0,                             \
393        req->rq_status, req->rq_repmsg ? req->rq_repmsg->status : 0);           \
394 } while (0)
395
396 struct ptlrpc_bulk_page {
397         struct list_head bp_link;
398         int bp_buflen;
399         int bp_pageoffset;                      /* offset within a page */
400         struct page *bp_page;
401 };
402
403 #define BULK_GET_SOURCE   0
404 #define BULK_PUT_SINK     1
405 #define BULK_GET_SINK     2
406 #define BULK_PUT_SOURCE   3
407
408 struct ptlrpc_bulk_desc {
409         unsigned int bd_success:1;              /* completed successfully */
410         unsigned int bd_network_rw:1;           /* accessible to the network */
411         unsigned int bd_type:2;                 /* {put,get}{source,sink} */
412         unsigned int bd_registered:1;           /* client side */
413         spinlock_t   bd_lock;                   /* serialise with callback */
414         int bd_import_generation;
415         struct obd_export *bd_export;
416         struct obd_import *bd_import;
417         __u32 bd_portal;
418         struct ptlrpc_request *bd_req;          /* associated request */
419         wait_queue_head_t      bd_waitq;        /* server side only WQ */
420         int                    bd_iov_count;    /* # entries in bd_iov */
421         int                    bd_max_iov;      /* allocated size of bd_iov */
422         int                    bd_nob;          /* # bytes covered */
423         int                    bd_nob_transferred; /* # bytes GOT/PUT */
424
425         __u64                  bd_last_xid;
426
427         struct ptlrpc_cb_id    bd_cbid;         /* network callback info */
428         ptl_handle_md_t        bd_md_h;         /* associated MD */
429         
430 #if (!CRAY_PORTALS && defined(__KERNEL__))
431         ptl_kiov_t             bd_iov[0];
432 #else
433         ptl_md_iovec_t         bd_iov[0];
434 #endif
435 };
436
437 struct ptlrpc_thread {
438         struct list_head t_link;
439
440         __u32 t_flags;
441         wait_queue_head_t t_ctl_waitq;
442 };
443
444 struct ptlrpc_request_buffer_desc {
445         struct list_head       rqbd_list;
446         struct ptlrpc_srv_ni  *rqbd_srv_ni;
447         ptl_handle_md_t        rqbd_md_h;
448         int                    rqbd_refcount;
449         char                  *rqbd_buffer;
450         struct ptlrpc_cb_id    rqbd_cbid;
451         struct ptlrpc_request  rqbd_req;
452 };
453
454 /* event queues are per-ni, because one day we may get a hardware
455  * supported NAL that delivers events asynchonously wrt kernel portals
456  * into the eq.
457  */
458 struct ptlrpc_ni { /* Generic interface state */
459         char                   *pni_name;
460         int                     pni_number;
461         ptl_handle_ni_t         pni_ni_h;
462         ptl_handle_eq_t         pni_eq_h;
463 };
464
465 struct ptlrpc_srv_ni {
466         /* Interface-specific service state */
467         struct ptlrpc_service  *sni_service;    /* owning service */
468         struct ptlrpc_ni       *sni_ni;         /* network interface */
469         struct list_head        sni_active_rqbds;   /* req buffers receiving */
470         struct list_head        sni_active_replies; /* all the active replies */
471         int                     sni_nrqbd_receiving; /* # posted request buffers */
472 };
473
474 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
475
476 struct ptlrpc_service {
477         struct list_head srv_list;              /* chain thru all services */
478         int              srv_max_req_size;      /* biggest request to receive */
479         int              srv_buf_size;          /* size of individual buffers */
480         int              srv_nbufs;             /* total # req buffer descs allocated */
481         int              srv_nthreads;          /* # running threads */
482         int              srv_n_difficult_replies; /* # 'difficult' replies */
483         int              srv_n_active_reqs;     /* # reqs being served */
484         int              srv_rqbd_timeout;      /* timeout before re-posting reqs */
485         
486         __u32 srv_req_portal;
487         __u32 srv_rep_portal;
488
489         int               srv_n_queued_reqs;    /* # reqs waiting to be served */
490         struct list_head  srv_request_queue;    /* reqs waiting for service */
491
492         struct list_head  srv_idle_rqbds;       /* request buffers to be reposted */
493
494         atomic_t          srv_outstanding_replies;
495         struct list_head  srv_reply_queue;      /* replies waiting for service */
496
497         wait_queue_head_t srv_waitq; /* all threads sleep on this */
498
499         struct list_head   srv_threads;
500         struct obd_device *srv_obddev;
501         svc_handler_t      srv_handler;
502         
503         char *srv_name;  /* only statically allocated strings here; we don't clean them */
504
505         spinlock_t               srv_lock;
506
507         struct proc_dir_entry   *srv_procroot;
508         struct lprocfs_stats    *srv_stats;
509         
510         struct ptlrpc_srv_ni srv_interfaces[0];
511 };
512
513 static inline char *ptlrpc_peernid2str(struct ptlrpc_peer *p, char *str)
514 {
515         LASSERT(p->peer_ni != NULL);
516         return (portals_nid2str(p->peer_ni->pni_number, p->peer_nid, str));
517 }
518
519 /* ptlrpc/events.c */
520 extern struct ptlrpc_ni ptlrpc_interfaces[];
521 extern int              ptlrpc_ninterfaces;
522 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid, struct ptlrpc_peer *peer);
523 extern void request_out_callback (ptl_event_t *ev);
524 extern void reply_in_callback(ptl_event_t *ev);
525 extern void client_bulk_callback (ptl_event_t *ev);
526 extern void request_in_callback(ptl_event_t *ev);
527 extern void reply_out_callback(ptl_event_t *ev);
528 extern void server_bulk_callback (ptl_event_t *ev);
529 extern int ptlrpc_default_nal(void);
530
531 /* ptlrpc/connection.c */
532 void ptlrpc_dump_connections(void);
533 void ptlrpc_readdress_connection(struct ptlrpc_connection *, struct obd_uuid *);
534 struct ptlrpc_connection *ptlrpc_get_connection(struct ptlrpc_peer *peer,
535                                                 struct obd_uuid *uuid);
536 int ptlrpc_put_connection(struct ptlrpc_connection *c);
537 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
538 void ptlrpc_init_connection(void);
539 void ptlrpc_cleanup_connection(void);
540
541 /* ptlrpc/niobuf.c */
542 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
543 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
544 int ptlrpc_register_bulk(struct ptlrpc_request *req);
545 void ptlrpc_unregister_bulk (struct ptlrpc_request *req);
546
547 static inline int ptlrpc_bulk_active (struct ptlrpc_bulk_desc *desc) 
548 {
549         unsigned long flags;
550         int           rc;
551
552         spin_lock_irqsave (&desc->bd_lock, flags);
553         rc = desc->bd_network_rw;
554         spin_unlock_irqrestore (&desc->bd_lock, flags);
555         return (rc);
556 }
557
558 int ptlrpc_send_reply(struct ptlrpc_request *req, int);
559 int ptlrpc_reply(struct ptlrpc_request *req);
560 int ptlrpc_error(struct ptlrpc_request *req);
561 void ptlrpc_resend_req(struct ptlrpc_request *request);
562 int ptl_send_rpc(struct ptlrpc_request *request);
563 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
564
565 /* ptlrpc/client.c */
566 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
567                         struct ptlrpc_client *);
568 void ptlrpc_cleanup_client(struct obd_import *imp);
569 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
570
571 static inline int
572 ptlrpc_client_receiving_reply (struct ptlrpc_request *req)
573 {
574         unsigned long flags;
575         int           rc;
576         
577         spin_lock_irqsave(&req->rq_lock, flags);
578         rc = req->rq_receiving_reply;
579         spin_unlock_irqrestore(&req->rq_lock, flags);
580         return (rc);
581 }
582
583 static inline int
584 ptlrpc_client_replied (struct ptlrpc_request *req)
585 {
586         unsigned long flags;
587         int           rc;
588         
589         spin_lock_irqsave(&req->rq_lock, flags);
590         rc = req->rq_replied;
591         spin_unlock_irqrestore(&req->rq_lock, flags);
592         return (rc);
593 }
594
595 static inline void
596 ptlrpc_wake_client_req (struct ptlrpc_request *req)
597 {
598         if (req->rq_set == NULL)
599                 wake_up(&req->rq_reply_waitq);
600         else
601                 wake_up(&req->rq_set->set_waitq);
602 }
603
604 int ptlrpc_queue_wait(struct ptlrpc_request *req);
605 int ptlrpc_replay_req(struct ptlrpc_request *req);
606 void ptlrpc_unregister_reply(struct ptlrpc_request *req);
607 void ptlrpc_restart_req(struct ptlrpc_request *req);
608 void ptlrpc_abort_inflight(struct obd_import *imp);
609
610 struct ptlrpc_request_set *ptlrpc_prep_set(void);
611 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
612 int ptlrpc_check_set(struct ptlrpc_request_set *set);
613 int ptlrpc_set_wait(struct ptlrpc_request_set *);
614 int ptlrpc_expired_set(void *data);
615 void ptlrpc_interrupted_set(void *data);
616 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
617 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
618 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
619 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *,
620                             struct ptlrpc_request *);
621
622 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, int opcode,
623                                        int count, int *lengths, char **bufs);
624 void ptlrpc_free_req(struct ptlrpc_request *request);
625 void ptlrpc_req_finished(struct ptlrpc_request *request);
626 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
627 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
628 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
629                                                int npages, int type, int portal);
630 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
631                                               int npages, int type, int portal);
632 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
633 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
634                            struct page *page, int pageoffset, int len);
635 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
636                                       struct obd_import *imp);
637 __u64 ptlrpc_next_xid(void);
638
639 /* ptlrpc/service.c */
640 void ptlrpc_save_lock (struct ptlrpc_request *req, 
641                        struct lustre_handle *lock, int mode);
642 void ptlrpc_commit_replies (struct obd_device *obd);
643 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
644 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
645                                        int req_portal, int rep_portal, 
646                                        svc_handler_t, char *name,
647                                        struct proc_dir_entry *proc_entry);
648 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
649 int ptlrpc_start_n_threads(struct obd_device *dev, struct ptlrpc_service *svc,
650                            int cnt, char *base_name);
651 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
652                         char *name);
653 int ptlrpc_unregister_service(struct ptlrpc_service *service);
654 int liblustre_check_services (void *arg);
655
656 struct ptlrpc_svc_data {
657         char *name;
658         struct ptlrpc_service *svc;
659         struct ptlrpc_thread *thread;
660         struct obd_device *dev;
661 };
662
663 /* ptlrpc/import.c */
664 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
665 int ptlrpc_init_import(struct obd_import *imp);
666 int ptlrpc_disconnect_import(struct obd_import *imp);
667 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
668
669 /* ptlrpc/pack_generic.c */
670 int lustre_msg_swabbed(struct lustre_msg *msg);
671 int lustre_pack_request(struct ptlrpc_request *, int count, int *lens,
672                         char **bufs);
673 int lustre_pack_reply(struct ptlrpc_request *, int count, int *lens,
674                       char **bufs);
675 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
676 int lustre_msg_size(int count, int *lengths);
677 int lustre_unpack_msg(struct lustre_msg *m, int len);
678 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
679 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
680 void *lustre_swab_buf(struct lustre_msg *, int n, int minlen, void *swabber);
681 void *lustre_swab_reqbuf (struct ptlrpc_request *req, int n, int minlen,
682                           void *swabber);
683 void *lustre_swab_repbuf (struct ptlrpc_request *req, int n, int minlen,
684                           void *swabber);
685
686 /* ldlm/ldlm_lib.c */
687 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf);
688 int client_obd_cleanup(struct obd_device * obddev, int flags);
689 int client_connect_import(struct lustre_handle *conn, struct obd_device *obd,
690                           struct obd_uuid *cluuid);
691 int client_disconnect_export(struct obd_export *exp, int failover);
692
693 /* ptlrpc/pinger.c */
694 int ptlrpc_pinger_add_import(struct obd_import *imp);
695 int ptlrpc_pinger_del_import(struct obd_import *imp);
696
697 /* ptlrpc/ptlrpcd.c */
698 void ptlrpcd_wake(struct ptlrpc_request *req);
699 void ptlrpcd_add_req(struct ptlrpc_request *req);
700 int ptlrpcd_addref(void);
701 void ptlrpcd_decref(void);
702
703 /* ptlrpc/lproc_ptlrpc.c */
704 #ifdef __KERNEL__
705 void ptlrpc_lprocfs_register_obd(struct obd_device *obddev);
706 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obddev);
707 #else
708 #define ptlrpc_lprocfs_register_obd(param...) do{}while(0)
709 #define ptlrpc_lprocfs_unregister_obd(param...) do{}while(0)
710 #endif
711
712 /* ptlrpc/llog_server.c */
713 int llog_origin_handle_create(struct ptlrpc_request *req);
714 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
715 int llog_origin_handle_next_block(struct ptlrpc_request *req);
716 int llog_origin_handle_read_header(struct ptlrpc_request *req);
717 int llog_origin_handle_close(struct ptlrpc_request *req);
718 int llog_origin_handle_cancel(struct ptlrpc_request *req);
719 int llog_catinfo(struct ptlrpc_request *req);
720
721 /* ptlrpc/llog_client.c */
722 extern struct llog_operations llog_client_ops;
723
724 #endif