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