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