Whamcloud - gitweb
Cleanup compiler warnings
[fs/lustre-release.git] / lustre / include / 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 #if defined(__linux__)
27 #include <linux/lustre_net.h>
28 #elif defined(__APPLE__)
29 #include <darwin/lustre_net.h>
30 #elif defined(__WINNT__)
31 #include <winnt/lustre_net.h>
32 #else
33 #error Unsupported operating system.
34 #endif
35
36 #include <libcfs/libcfs.h>
37 // #include <obd.h>
38 #include <lnet/lnet.h>
39 #include <lustre/lustre_idl.h>
40 #include <lustre_ha.h>
41 #include <lustre_sec.h>
42 #include <lustre_import.h>
43 #include <lprocfs_status.h>
44 #include <lu_object.h>
45 #include <lustre_req_layout.h>
46
47 /* MD flags we _always_ use */
48 #define PTLRPC_MD_OPTIONS  0
49
50 /* Define maxima for bulk I/O
51  * CAVEAT EMPTOR, with multinet (i.e. routers forwarding between networks)
52  * these limits are system wide and not interface-local. */
53 #define PTLRPC_MAX_BRW_BITS     LNET_MTU_BITS
54 #define PTLRPC_MAX_BRW_SIZE     (1<<LNET_MTU_BITS)
55 #define PTLRPC_MAX_BRW_PAGES    (PTLRPC_MAX_BRW_SIZE >> CFS_PAGE_SHIFT)
56
57 /* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
58 #ifdef __KERNEL__
59 # if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
60 #  error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
61 # endif
62 # if (PTLRPC_MAX_BRW_SIZE != (PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE))
63 #  error "PTLRPC_MAX_BRW_SIZE isn't PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE"
64 # endif
65 # if (PTLRPC_MAX_BRW_SIZE > LNET_MTU)
66 #  error "PTLRPC_MAX_BRW_SIZE too big"
67 # endif
68 # if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV)
69 #  error "PTLRPC_MAX_BRW_PAGES too big"
70 # endif
71 #endif /* __KERNEL__ */
72
73 /* Size over which to OBD_VMALLOC() rather than OBD_ALLOC() service request
74  * buffers */
75 #define SVC_BUF_VMALLOC_THRESHOLD (2 * CFS_PAGE_SIZE)
76
77 /* The following constants determine how memory is used to buffer incoming
78  * service requests.
79  *
80  * ?_NBUFS              # buffers to allocate when growing the pool
81  * ?_BUFSIZE            # bytes in a single request buffer
82  * ?_MAXREQSIZE         # maximum request service will receive
83  *
84  * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
85  * of ?_NBUFS is added to the pool.
86  *
87  * Messages larger than ?_MAXREQSIZE are dropped.  Request buffers are
88  * considered full when less than ?_MAXREQSIZE is left in them.
89  */
90
91 #define LDLM_THREADS_AUTO_MIN                                                 \
92         min((int)(num_online_cpus() * num_online_cpus() * 2), 8)
93 #define LDLM_THREADS_AUTO_MAX (LDLM_THREADS_AUTO_MIN * 16)
94 #define LDLM_BL_THREADS  LDLM_THREADS_AUTO_MIN
95 #define LDLM_NBUFS      (64 * num_online_cpus())
96 #define LDLM_BUFSIZE    (8 * 1024)
97 #define LDLM_MAXREQSIZE (5 * 1024)
98 #define LDLM_MAXREPSIZE (1024)
99
100 #define MDT_MIN_THREADS 2UL
101 #define MDT_MAX_THREADS 512UL
102 #define MDT_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
103                                   num_physpages >> (25 - CFS_PAGE_SHIFT)), 2UL)
104 #define FLD_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
105                                   num_physpages >> (25 - CFS_PAGE_SHIFT)), 2UL)
106 #define SEQ_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
107                                   num_physpages >> (25 - CFS_PAGE_SHIFT)), 2UL)
108
109 /* Absolute limits */
110 #define MDS_THREADS_MIN 2
111 #define MDS_THREADS_MAX 512
112 #define MDS_THREADS_MIN_READPAGE 2
113 #define MDS_NBUFS       (64 * num_online_cpus())
114 #define MDS_BUFSIZE     (8 * 1024)
115 /* Assume file name length = FNAME_MAX = 256 (true for ext3).
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  * MDS_MAXREPSIZE ~= 8300 bytes = lustre_msg + llog_header
126  * or, for mds_close() and mds_reint_unlink() on a many-OST filesystem:
127  *      = 9210 bytes = lustre_msg + mds_body + 160 * (easize + cookiesize)
128  *
129  * Realistic size is about 512 bytes (20 character name + 128 char symlink),
130  * except in the open case where there are a large number of OSTs in a LOV.
131  */
132 #define MDS_MAXREQSIZE  (5 * 1024)
133 #define MDS_MAXREPSIZE  max(9 * 1024, 280 + LOV_MAX_STRIPE_COUNT * 56)
134
135 /* FLD_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + md_fld */
136 #define FLD_MAXREQSIZE  (160)
137
138 /* FLD_MAXREPSIZE == lustre_msg + ptlrpc_body + md_fld */
139 #define FLD_MAXREPSIZE  (152)
140
141 /* SEQ_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + lu_range +
142  * __u32 padding */
143 #define SEQ_MAXREQSIZE  (160)
144
145 /* SEQ_MAXREPSIZE == lustre_msg + ptlrpc_body + lu_range */
146 #define SEQ_MAXREPSIZE  (152)
147
148 #define MGS_THREADS_AUTO_MIN 2
149 #define MGS_THREADS_AUTO_MAX 32
150 #define MGS_NBUFS       (64 * num_online_cpus())
151 #define MGS_BUFSIZE     (8 * 1024)
152 #define MGS_MAXREQSIZE  (7 * 1024)
153 #define MGS_MAXREPSIZE  (9 * 1024)
154
155 /* Absolute limits */
156 #define OSS_THREADS_MIN 2
157 #define OSS_THREADS_MAX 512
158 #define OST_NBUFS       (64 * num_online_cpus())
159 #define OST_BUFSIZE     (8 * 1024)
160 /* OST_MAXREQSIZE ~= 4768 bytes =
161  * lustre_msg + obdo + 16 * obd_ioobj + 256 * niobuf_remote
162  *
163  * - single object with 16 pages is 512 bytes
164  * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
165  */
166 #define OST_MAXREQSIZE  (5 * 1024)
167 #define OST_MAXREPSIZE  (9 * 1024)
168
169 /* Macro to hide a typecast. */
170 #define ptlrpc_req_async_args(req) ((void *)&req->rq_async_args)
171
172 struct ptlrpc_connection {
173         struct list_head        c_link;
174         struct hlist_node       c_hash;
175         lnet_nid_t              c_self;
176         lnet_process_id_t       c_peer;
177         struct obd_uuid         c_remote_uuid;
178         atomic_t                c_refcount;
179 };
180
181 struct ptlrpc_client {
182         __u32                     cli_request_portal;
183         __u32                     cli_reply_portal;
184         char                     *cli_name;
185 };
186
187 /* state flags of requests */
188 /* XXX only ones left are those used by the bulk descs as well! */
189 #define PTL_RPC_FL_INTR      (1 << 0)  /* reply wait was interrupted by user */
190 #define PTL_RPC_FL_TIMEOUT   (1 << 7)  /* request timed out waiting for reply */
191
192 #define REQ_MAX_ACK_LOCKS 8
193
194 union ptlrpc_async_args {
195         /* Scratchpad for passing args to completion interpreter. Users
196          * cast to the struct of their choosing, and LASSERT that this is
197          * big enough.  For _tons_ of context, OBD_ALLOC a struct and store
198          * a pointer to it here.  The pointer_arg ensures this struct is at
199          * least big enough for that. */
200         void      *pointer_arg[9];
201         __u64      space[4];
202 };
203
204 struct ptlrpc_request_set;
205 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
206
207 struct ptlrpc_request_set {
208         int               set_remaining; /* # uncompleted requests */
209         cfs_waitq_t       set_waitq;
210         cfs_waitq_t      *set_wakeup_ptr;
211         struct list_head  set_requests;
212         struct list_head  set_cblist; /* list of completion callbacks */
213         set_interpreter_func    set_interpret; /* completion callback */
214         void              *set_arg; /* completion context */
215         /* locked so that any old caller can communicate requests to
216          * the set holder who can then fold them into the lock-free set */
217         spinlock_t        set_new_req_lock;
218         struct list_head  set_new_requests;
219 };
220
221 struct ptlrpc_set_cbdata {
222         struct list_head        psc_item;
223         set_interpreter_func    psc_interpret;
224         void                   *psc_data;
225 };
226
227 struct ptlrpc_bulk_desc;
228
229 /*
230  * ptlrpc callback & work item stuff
231  */
232 struct ptlrpc_cb_id {
233         void   (*cbid_fn)(lnet_event_t *ev);     /* specific callback fn */
234         void    *cbid_arg;                      /* additional arg */
235 };
236
237 #define RS_MAX_LOCKS 4
238 #define RS_DEBUG     1
239
240 struct ptlrpc_reply_state {
241         struct ptlrpc_cb_id    rs_cb_id;
242         struct list_head       rs_list;
243         struct list_head       rs_exp_list;
244         struct list_head       rs_obd_list;
245 #if RS_DEBUG
246         struct list_head       rs_debug_list;
247 #endif
248         /* updates to following flag serialised by srv_request_lock */
249         unsigned long          rs_difficult:1;     /* ACK/commit stuff */
250         unsigned long          rs_scheduled:1;     /* being handled? */
251         unsigned long          rs_scheduled_ever:1;/* any schedule attempts? */
252         unsigned long          rs_handled:1;  /* been handled yet? */
253         unsigned long          rs_on_net:1;   /* reply_out_callback pending? */
254         unsigned long          rs_prealloc:1; /* rs from prealloc list */
255
256         int                    rs_size;
257         __u64                  rs_transno;
258         __u64                  rs_xid;
259         struct obd_export     *rs_export;
260         struct ptlrpc_service *rs_service;
261         lnet_handle_md_t       rs_md_h;
262         atomic_t               rs_refcount;
263
264         struct ptlrpc_svc_ctx *rs_svc_ctx;
265         struct lustre_msg     *rs_repbuf;       /* wrapper */
266         int                    rs_repbuf_len;   /* wrapper buf length */
267         int                    rs_repdata_len;  /* wrapper msg length */
268         struct lustre_msg     *rs_msg;          /* reply message */
269
270         /* locks awaiting client reply ACK */
271         int                    rs_nlocks;
272         struct lustre_handle   rs_locks[RS_MAX_LOCKS];
273         ldlm_mode_t            rs_modes[RS_MAX_LOCKS];
274 };
275
276 struct ptlrpc_thread;
277
278 enum rq_phase {
279         RQ_PHASE_NEW         = 0xebc0de00,
280         RQ_PHASE_RPC         = 0xebc0de01,
281         RQ_PHASE_BULK        = 0xebc0de02,
282         RQ_PHASE_INTERPRET   = 0xebc0de03,
283         RQ_PHASE_COMPLETE    = 0xebc0de04,
284 };
285
286 struct ptlrpc_request_pool {
287         spinlock_t prp_lock;
288         struct list_head prp_req_list;    /* list of ptlrpc_request structs */
289         int prp_rq_size;
290         void (*prp_populate)(struct ptlrpc_request_pool *, int);
291 };
292
293 struct lu_context;
294 struct lu_env;
295
296 struct ptlrpc_request {
297         int rq_type; /* one of PTL_RPC_MSG_* */
298         struct list_head rq_list;
299         struct list_head rq_timed_list;         /* server-side early replies */
300         struct list_head rq_history_list;       /* server-side history */
301         __u64            rq_history_seq;        /* history sequence # */
302         int rq_status;
303         spinlock_t rq_lock;
304         /* client-side flags are serialized by rq_lock */
305         unsigned long rq_intr:1, rq_replied:1, rq_err:1,
306                 rq_timedout:1, rq_resend:1, rq_restart:1,
307                 /*
308                  * when ->rq_replay is set, request is kept by the client even
309                  * after server commits corresponding transaction. This is
310                  * used for operations that require sequence of multiple
311                  * requests to be replayed. The only example currently is file
312                  * open/close/dw/setattr. When last request in such a sequence
313                  * is committed, ->rq_replay is cleared on all requests in the
314                  * sequence.
315                  */
316                 rq_replay:1,
317                 /* this is the last request in the sequence. */
318                 rq_sequence:1,
319                 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
320                 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
321                 rq_early:1, rq_must_unlink:1,
322                 /* server-side flags */
323                 rq_packed_final:1,  /* packed final reply */
324                 rq_sent_final:1;    /* stop sending early replies */
325
326         enum rq_phase rq_phase; /* one of RQ_PHASE_* */
327         atomic_t rq_refcount;   /* client-side refcount for SENT race,
328                                    server-side refcounf for multiple replies */
329
330         struct ptlrpc_thread *rq_svc_thread; /* initial thread servicing req */
331
332         int rq_request_portal;  /* XXX FIXME bug 249 */
333         int rq_reply_portal;    /* XXX FIXME bug 249 */
334
335         int rq_nob_received; /* client-side # reply bytes actually received  */
336
337         int rq_reqlen;
338         struct lustre_msg *rq_reqmsg;
339
340         int rq_replen;
341         struct lustre_msg *rq_repmsg;
342         __u64 rq_transno;
343         __u64 rq_xid;
344         struct list_head rq_replay_list;
345         struct list_head rq_mod_list;
346
347         struct ptlrpc_cli_ctx   *rq_cli_ctx;     /* client's half ctx */
348         struct ptlrpc_svc_ctx   *rq_svc_ctx;     /* server's half ctx */
349         struct list_head         rq_ctx_chain;   /* link to waited ctx */
350
351         struct sptlrpc_flavor    rq_flvr;        /* client & server */
352         enum lustre_sec_part     rq_sp_from;
353
354         unsigned long            /* client/server security flags */
355                                  rq_ctx_init:1,      /* context initiation */
356                                  rq_ctx_fini:1,      /* context destroy */
357                                  rq_bulk_read:1,     /* request bulk read */
358                                  rq_bulk_write:1,    /* request bulk write */
359                                  /* server authentication flags */
360                                  rq_auth_gss:1,      /* authenticated by gss */
361                                  rq_auth_remote:1,   /* authed as remote user */
362                                  rq_auth_usr_root:1, /* authed as root */
363                                  rq_auth_usr_mdt:1,  /* authed as mdt */
364                                  /* security tfm flags */
365                                  rq_pack_udesc:1,
366                                  rq_pack_bulk:1,
367                                  /* doesn't expect reply FIXME */
368                                  rq_no_reply:1;
369
370         uid_t                    rq_auth_uid;        /* authed uid */
371         uid_t                    rq_auth_mapped_uid; /* authed uid mapped to */
372
373         /* (server side), pointed directly into req buffer */
374         struct ptlrpc_user_desc *rq_user_desc;
375
376         /* early replies go to offset 0, regular replies go after that */
377         unsigned int             rq_reply_off;
378
379         /* various buffer pointers */
380         struct lustre_msg       *rq_reqbuf;      /* req wrapper */
381         int                      rq_reqbuf_len;  /* req wrapper buf len */
382         int                      rq_reqdata_len; /* req wrapper msg len */
383         char                    *rq_repbuf;      /* rep buffer */
384         int                      rq_repbuf_len;  /* rep buffer len */
385         struct lustre_msg       *rq_repdata;     /* rep wrapper msg */
386         int                      rq_repdata_len; /* rep wrapper msg len */
387         struct lustre_msg       *rq_clrbuf;      /* only in priv mode */
388         int                      rq_clrbuf_len;  /* only in priv mode */
389         int                      rq_clrdata_len; /* only in priv mode */
390
391         __u32 rq_req_swab_mask;
392         __u32 rq_rep_swab_mask;
393
394         int rq_import_generation;
395         enum lustre_imp_state rq_send_state;
396
397         int rq_early_count;           /* how many early replies (for stats) */
398
399         /* client+server request */
400         lnet_handle_md_t     rq_req_md_h;
401         struct ptlrpc_cb_id  rq_req_cbid;
402
403         /* server-side... */
404         struct timeval       rq_arrival_time;       /* request arrival time */
405         struct ptlrpc_reply_state *rq_reply_state;  /* separated reply state */
406         struct ptlrpc_request_buffer_desc *rq_rqbd; /* incoming request buffer*/
407 #ifdef CRAY_XT3
408         __u32                rq_uid;            /* peer uid, used in MDS only */
409 #endif
410
411         /* client-only incoming reply */
412         lnet_handle_md_t     rq_reply_md_h;
413         cfs_waitq_t          rq_reply_waitq;
414         struct ptlrpc_cb_id  rq_reply_cbid;
415
416         lnet_nid_t           rq_self;
417         lnet_process_id_t    rq_peer;
418         struct obd_export   *rq_export;
419         struct obd_import   *rq_import;
420
421         void (*rq_replay_cb)(struct ptlrpc_request *);
422         void (*rq_commit_cb)(struct ptlrpc_request *);
423         void  *rq_cb_data;
424
425         struct ptlrpc_bulk_desc *rq_bulk;/* client side bulk */
426
427         /* client outgoing req */
428         time_t rq_sent;                  /* when request/reply sent (secs), or
429                                           * time when request should be sent */
430
431         volatile time_t rq_deadline;     /* when request must finish. volatile
432                so that servers' early reply updates to the deadline aren't
433                kept in per-cpu cache */
434         int    rq_timeout;               /* service time estimate (secs) */
435
436         /* Multi-rpc bits */
437         struct list_head rq_set_chain;
438         struct ptlrpc_request_set *rq_set;
439         void *rq_interpret_reply;               /* Async completion handler */
440         union ptlrpc_async_args rq_async_args;  /* Async completion context */
441         struct ptlrpc_request_pool *rq_pool;    /* Pool if request from
442                                                    preallocated list */
443         struct lu_context           rq_session;
444
445         /* request format */
446         struct req_capsule          rq_pill;
447 };
448
449 static inline void ptlrpc_close_replay_seq(struct ptlrpc_request *req)
450 {
451         spin_lock(&req->rq_lock);
452         req->rq_replay = 0;
453         req->rq_sequence = 1;
454         spin_unlock(&req->rq_lock);
455 }
456
457 static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
458 {
459         LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
460         LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
461         req->rq_req_swab_mask |= 1 << index;
462 }
463
464 static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
465 {
466         LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
467         LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
468         req->rq_rep_swab_mask |= 1 << index;
469 }
470
471 static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
472
473         LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
474         return req->rq_req_swab_mask & (1 << index);
475 }
476
477 static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
478 {
479         LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
480         return req->rq_rep_swab_mask & (1 << index);
481 }
482
483 static inline const char *
484 ptlrpc_rqphase2str(const struct ptlrpc_request *req)
485 {
486         switch (req->rq_phase) {
487         case RQ_PHASE_NEW:
488                 return "New";
489         case RQ_PHASE_RPC:
490                 return "Rpc";
491         case RQ_PHASE_BULK:
492                 return "Bulk";
493         case RQ_PHASE_INTERPRET:
494                 return "Interpret";
495         case RQ_PHASE_COMPLETE:
496                 return "Complete";
497         default:
498                 return "?Phase?";
499         }
500 }
501
502 /* Spare the preprocessor, spoil the bugs. */
503 #define FLAG(field, str) (field ? str : "")
504
505 #define DEBUG_REQ_FLAGS(req)                                                    \
506         ptlrpc_rqphase2str(req),                                                \
507         FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"),                    \
508         FLAG(req->rq_err, "E"),                                                 \
509         FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"),   \
510         FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"),                  \
511         FLAG(req->rq_no_resend, "N"),                                           \
512         FLAG(req->rq_waiting, "W"),                                             \
513         FLAG(req->rq_wait_ctx, "C")
514
515 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s"
516
517 void _debug_req(struct ptlrpc_request *req, __u32 mask,
518                 struct libcfs_debug_msg_data *data, const char *fmt, ...)
519         __attribute__ ((format (printf, 4, 5)));
520
521 #define debug_req(cdls, level, req, file, func, line, fmt, a...)              \
522 do {                                                                          \
523         CHECK_STACK();                                                        \
524                                                                               \
525         if (((level) & D_CANTMASK) != 0 ||                                    \
526             ((libcfs_debug & (level)) != 0 &&                                 \
527              (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) {              \
528                 static struct libcfs_debug_msg_data _req_dbg_data =           \
529                 DEBUG_MSG_DATA_INIT(cdls, DEBUG_SUBSYSTEM, file, func, line); \
530                 _debug_req((req), (level), &_req_dbg_data, fmt, ##a);         \
531         }                                                                     \
532 } while(0)
533
534 /* for most callers (level is a constant) this is resolved at compile time */
535 #define DEBUG_REQ(level, req, fmt, args...)                                   \
536 do {                                                                          \
537         if ((level) & (D_ERROR | D_WARNING)) {                                \
538                 static cfs_debug_limit_state_t cdls;                          \
539                 debug_req(&cdls, level, req, __FILE__, __func__, __LINE__,    \
540                           "@@@ "fmt" ", ## args);                             \
541         } else                                                                \
542                 debug_req(NULL, level, req, __FILE__, __func__, __LINE__,     \
543                           "@@@ "fmt" ", ## args);                             \
544 } while (0)
545
546 struct ptlrpc_bulk_page {
547         struct list_head bp_link;
548         int              bp_buflen;
549         int              bp_pageoffset; /* offset within a page */
550         struct page     *bp_page;
551 };
552
553 #define BULK_GET_SOURCE   0
554 #define BULK_PUT_SINK     1
555 #define BULK_GET_SINK     2
556 #define BULK_PUT_SOURCE   3
557
558 struct ptlrpc_bulk_desc {
559         unsigned long bd_success:1;              /* completed successfully */
560         unsigned long bd_network_rw:1;           /* accessible to the network */
561         unsigned long bd_type:2;                 /* {put,get}{source,sink} */
562         unsigned long bd_registered:1;           /* client side */
563         spinlock_t   bd_lock;                   /* serialise with callback */
564         int bd_import_generation;
565         struct obd_export *bd_export;
566         struct obd_import *bd_import;
567         __u32 bd_portal;
568         struct ptlrpc_request *bd_req;          /* associated request */
569         cfs_waitq_t            bd_waitq;        /* server side only WQ */
570         int                    bd_iov_count;    /* # entries in bd_iov */
571         int                    bd_max_iov;      /* allocated size of bd_iov */
572         int                    bd_nob;          /* # bytes covered */
573         int                    bd_nob_transferred; /* # bytes GOT/PUT */
574
575         __u64                  bd_last_xid;
576
577         struct ptlrpc_cb_id    bd_cbid;         /* network callback info */
578         lnet_handle_md_t       bd_md_h;         /* associated MD */
579         lnet_nid_t             bd_sender;       /* stash event::sender */
580
581         cfs_page_t           **bd_enc_pages;
582 #if defined(__KERNEL__)
583         lnet_kiov_t            bd_iov[0];
584 #else
585         lnet_md_iovec_t        bd_iov[0];
586 #endif
587 };
588
589 struct ptlrpc_thread {
590
591         struct list_head t_link; /* active threads for service, from svc->srv_threads */
592
593         void *t_data;            /* thread-private data (preallocated memory) */
594         __u32 t_flags;
595
596         unsigned int t_id; /* service thread index, from ptlrpc_start_threads */
597         cfs_waitq_t t_ctl_waitq;
598         struct lu_env *t_env;
599 };
600
601 struct ptlrpc_request_buffer_desc {
602         struct list_head       rqbd_list;
603         struct list_head       rqbd_reqs;
604         struct ptlrpc_service *rqbd_service;
605         lnet_handle_md_t       rqbd_md_h;
606         int                    rqbd_refcount;
607         char                  *rqbd_buffer;
608         struct ptlrpc_cb_id    rqbd_cbid;
609         struct ptlrpc_request  rqbd_req;
610 };
611
612 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
613 typedef void (*svcreq_printfn_t)(void *, struct ptlrpc_request *);
614
615 struct ptlrpc_service {
616         struct list_head srv_list;              /* chain thru all services */
617         int              srv_max_req_size;      /* biggest request to receive */
618         int              srv_max_reply_size;    /* biggest reply to send */
619         int              srv_buf_size;          /* size of individual buffers */
620         int              srv_nbuf_per_group;    /* # buffers to allocate in 1 group */
621         int              srv_nbufs;             /* total # req buffer descs allocated */
622         int              srv_threads_min;       /* threads to start at SOW */
623         int              srv_threads_max;       /* thread upper limit */
624         int              srv_threads_started;   /* index of last started thread */
625         int              srv_threads_running;   /* # running threads */
626         int              srv_n_difficult_replies; /* # 'difficult' replies */
627         int              srv_n_active_reqs;     /* # reqs being served */
628         cfs_duration_t   srv_rqbd_timeout;      /* timeout before re-posting reqs, in tick */
629         int              srv_watchdog_factor;   /* soft watchdog timeout mutiplier */
630         unsigned         srv_cpu_affinity:1;    /* bind threads to CPUs */
631         unsigned         srv_at_check:1;        /* check early replies */
632         cfs_time_t       srv_at_checktime;      /* debug */
633
634         __u32            srv_req_portal;
635         __u32            srv_rep_portal;
636
637         /* AT stuff */
638         struct adaptive_timeout srv_at_estimate;/* estimated rpc service time */
639         spinlock_t        srv_at_lock;
640         struct list_head  srv_at_list;          /* reqs waiting for replies */
641         cfs_timer_t       srv_at_timer;         /* early reply timer */
642
643         int               srv_n_queued_reqs;    /* # reqs in either of the queues below */
644         struct list_head  srv_req_in_queue;     /* incoming reqs */
645         struct list_head  srv_request_queue;    /* reqs waiting for service */
646
647         struct list_head  srv_request_history;  /* request history */
648         __u64             srv_request_seq;      /* next request sequence # */
649         __u64             srv_request_max_cull_seq; /* highest seq culled from history */
650         svcreq_printfn_t  srv_request_history_print_fn; /* service-specific print fn */
651
652         struct list_head  srv_idle_rqbds;       /* request buffers to be reposted */
653         struct list_head  srv_active_rqbds;     /* req buffers receiving */
654         struct list_head  srv_history_rqbds;    /* request buffer history */
655         int               srv_nrqbd_receiving;  /* # posted request buffers */
656         int               srv_n_history_rqbds;  /* # request buffers in history */
657         int               srv_max_history_rqbds;/* max # request buffers in history */
658
659         atomic_t          srv_outstanding_replies;
660         struct list_head  srv_active_replies;   /* all the active replies */
661         struct list_head  srv_reply_queue;      /* replies waiting for service */
662
663         cfs_waitq_t       srv_waitq; /* all threads sleep on this. This
664                                       * wait-queue is signalled when new
665                                       * incoming request arrives and when
666                                       * difficult reply has to be handled. */
667
668         struct list_head   srv_threads;         /* service thread list */
669         svc_handler_t      srv_handler;
670
671         char *srv_name; /* only statically allocated strings here; we don't clean them */
672         char *srv_thread_name; /* only statically allocated strings here; we don't clean them */
673
674         spinlock_t               srv_lock;
675
676         cfs_proc_dir_entry_t    *srv_procroot;
677         struct lprocfs_stats    *srv_stats;
678
679         /* List of free reply_states */
680         struct list_head         srv_free_rs_list;
681         /* waitq to run, when adding stuff to srv_free_rs_list */
682         cfs_waitq_t              srv_free_rs_waitq;
683
684         /*
685          * Tags for lu_context associated with this thread, see struct
686          * lu_context.
687          */
688         __u32                    srv_ctx_tags;
689         /*
690          * if non-NULL called during thread creation (ptlrpc_start_thread())
691          * to initialize service specific per-thread state.
692          */
693         int (*srv_init)(struct ptlrpc_thread *thread);
694         /*
695          * if non-NULL called during thread shutdown (ptlrpc_main()) to
696          * destruct state created by ->srv_init().
697          */
698         void (*srv_done)(struct ptlrpc_thread *thread);
699
700         //struct ptlrpc_srv_ni srv_interfaces[0];
701 };
702
703 /* ptlrpc/events.c */
704 extern lnet_handle_eq_t ptlrpc_eq_h;
705 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
706                                lnet_process_id_t *peer, lnet_nid_t *self);
707 extern void request_out_callback (lnet_event_t *ev);
708 extern void reply_in_callback(lnet_event_t *ev);
709 extern void client_bulk_callback (lnet_event_t *ev);
710 extern void request_in_callback(lnet_event_t *ev);
711 extern void reply_out_callback(lnet_event_t *ev);
712 extern void server_bulk_callback (lnet_event_t *ev);
713
714 /* ptlrpc/connection.c */
715 void ptlrpc_dump_connections(void);
716 void ptlrpc_readdress_connection(struct ptlrpc_connection *, struct obd_uuid *);
717 struct ptlrpc_connection *ptlrpc_get_connection(lnet_process_id_t peer,
718                                                 lnet_nid_t self, struct obd_uuid *uuid);
719 int ptlrpc_put_connection(struct ptlrpc_connection *c);
720 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
721 int ptlrpc_init_connection(void);
722 void ptlrpc_cleanup_connection(void);
723 extern lnet_pid_t ptl_get_pid(void);
724
725 /* ptlrpc/niobuf.c */
726 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
727 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
728 int ptlrpc_register_bulk(struct ptlrpc_request *req);
729 void ptlrpc_unregister_bulk (struct ptlrpc_request *req);
730
731 static inline int ptlrpc_bulk_active (struct ptlrpc_bulk_desc *desc)
732 {
733         int           rc;
734
735         spin_lock(&desc->bd_lock);
736         rc = desc->bd_network_rw;
737         spin_unlock(&desc->bd_lock);
738         return (rc);
739 }
740
741 #define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
742 #define PTLRPC_REPLY_EARLY           0x02
743 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
744 int ptlrpc_reply(struct ptlrpc_request *req);
745 int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
746 int ptlrpc_error(struct ptlrpc_request *req);
747 void ptlrpc_resend_req(struct ptlrpc_request *request);
748 int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
749 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
750 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
751
752 /* ptlrpc/client.c */
753 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
754                         struct ptlrpc_client *);
755 void ptlrpc_cleanup_client(struct obd_import *imp);
756 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
757
758 static inline int
759 ptlrpc_client_recv_or_unlink (struct ptlrpc_request *req)
760 {
761         int           rc;
762
763         spin_lock(&req->rq_lock);
764         rc = req->rq_receiving_reply || req->rq_must_unlink;
765         spin_unlock(&req->rq_lock);
766         return (rc);
767 }
768
769 static inline void
770 ptlrpc_wake_client_req (struct ptlrpc_request *req)
771 {
772         if (req->rq_set == NULL)
773                 cfs_waitq_signal(&req->rq_reply_waitq);
774         else
775                 cfs_waitq_signal(&req->rq_set->set_waitq);
776 }
777
778 int ptlrpc_queue_wait(struct ptlrpc_request *req);
779 int ptlrpc_replay_req(struct ptlrpc_request *req);
780 void ptlrpc_unregister_reply(struct ptlrpc_request *req);
781 void ptlrpc_restart_req(struct ptlrpc_request *req);
782 void ptlrpc_abort_inflight(struct obd_import *imp);
783
784 struct ptlrpc_request_set *ptlrpc_prep_set(void);
785 int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
786                       set_interpreter_func fn, void *data);
787 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
788 int ptlrpc_check_set(struct ptlrpc_request_set *set);
789 int ptlrpc_set_wait(struct ptlrpc_request_set *);
790 int ptlrpc_expired_set(void *data);
791 void ptlrpc_interrupted_set(void *data);
792 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
793 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
794 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
795 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *,
796                             struct ptlrpc_request *);
797
798 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
799 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
800 struct ptlrpc_request_pool *ptlrpc_init_rq_pool(int, int,
801                                                 void (*populate_pool)(struct ptlrpc_request_pool *, int));
802 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
803 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
804                                             const struct req_format *format);
805 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
806                                             struct ptlrpc_request_pool *,
807                                             const struct req_format *format);
808 void ptlrpc_request_free(struct ptlrpc_request *request);
809 int ptlrpc_request_pack(struct ptlrpc_request *request,
810                         __u32 version, int opcode);
811 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
812                                                 const struct req_format *format,
813                                                 __u32 version, int opcode);
814 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
815                              __u32 version, int opcode, char **bufs,
816                              struct ptlrpc_cli_ctx *ctx);
817 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
818                                        int opcode, int count, int *lengths,
819                                        char **bufs);
820 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
821                                              __u32 version, int opcode,
822                                             int count, int *lengths, char **bufs,
823                                             struct ptlrpc_request_pool *pool);
824 void ptlrpc_free_req(struct ptlrpc_request *request);
825 void ptlrpc_req_finished(struct ptlrpc_request *request);
826 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
827 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
828 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
829                                                int npages, int type, int portal);
830 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
831                                               int npages, int type, int portal);
832 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
833 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
834                            cfs_page_t *page, int pageoffset, int len);
835 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
836                                       struct obd_import *imp);
837 __u64 ptlrpc_next_xid(void);
838 __u64 ptlrpc_sample_next_xid(void);
839 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
840
841 struct ptlrpc_service_conf {
842         int psc_nbufs;
843         int psc_bufsize;
844         int psc_max_req_size;
845         int psc_max_reply_size;
846         int psc_req_portal;
847         int psc_rep_portal;
848         int psc_watchdog_factor;
849         int psc_min_threads;
850         int psc_max_threads;
851         __u32 psc_ctx_tags;
852 };
853
854 /* ptlrpc/service.c */
855 void ptlrpc_save_lock (struct ptlrpc_request *req,
856                        struct lustre_handle *lock, int mode);
857 void ptlrpc_commit_replies (struct obd_device *obd);
858 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
859 struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
860                                             svc_handler_t h, char *name,
861                                             struct proc_dir_entry *proc_entry,
862                                             svcreq_printfn_t prntfn,
863                                             char *threadname);
864
865 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
866                                        int max_reply_size,
867                                        int req_portal, int rep_portal,
868                                        int watchdog_factor,
869                                        svc_handler_t, char *name,
870                                        cfs_proc_dir_entry_t *proc_entry,
871                                        svcreq_printfn_t,
872                                        int min_threads, int max_threads,
873                                        char *threadname, __u32 ctx_tags);
874 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
875
876 int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc);
877 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc);
878 int ptlrpc_unregister_service(struct ptlrpc_service *service);
879 int liblustre_check_services (void *arg);
880 void ptlrpc_daemonize(char *name);
881 int ptlrpc_service_health_check(struct ptlrpc_service *);
882
883
884 struct ptlrpc_svc_data {
885         char *name;
886         struct ptlrpc_service *svc;
887         struct ptlrpc_thread *thread;
888         struct obd_device *dev;
889 };
890
891 /* ptlrpc/import.c */
892 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
893 int ptlrpc_init_import(struct obd_import *imp);
894 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
895 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
896
897 /* ptlrpc/pack_generic.c */
898 int ptlrpc_reconnect_import(struct obd_import *imp);
899 int lustre_msg_swabbed(struct lustre_msg *msg);
900 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
901 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
902                         char **bufs);
903 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
904                         int *lens, char **bufs);
905 int lustre_pack_reply(struct ptlrpc_request *, int count, int *lens,
906                       char **bufs);
907 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
908                          int *lens, char **bufs, int flags);
909 #define LPRFL_EARLY_REPLY 1
910 int lustre_pack_reply_flags(struct ptlrpc_request *, int count, int *lens,
911                             char **bufs, int flags);
912 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
913                       unsigned int newlen, int move_data);
914 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
915 int lustre_msg_hdr_size(__u32 magic, int count);
916 int lustre_msg_size(__u32 magic, int count, int *lengths);
917 int lustre_msg_size_v2(int count, int *lengths);
918 int lustre_packed_msg_size(struct lustre_msg *msg);
919 int lustre_msg_early_size(void);
920 int lustre_unpack_msg(struct lustre_msg *m, int len);
921 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
922 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
923 int lustre_msg_buflen(struct lustre_msg *m, int n);
924 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
925 int lustre_msg_bufcount(struct lustre_msg *m);
926 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
927 void *lustre_swab_buf(struct lustre_msg *, int n, int minlen, void *swabber);
928 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int n, int minlen,
929                          void *swabber);
930 void *lustre_swab_repbuf(struct ptlrpc_request *req, int n, int minlen,
931                          void *swabber);
932 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
933 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
934 __u32 lustre_msg_get_flags(struct lustre_msg *msg);
935 void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
936 void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
937 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
938 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
939 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
940 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
941 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
942 __u32 lustre_msg_get_type(struct lustre_msg *msg);
943 __u32 lustre_msg_get_version(struct lustre_msg *msg);
944 void lustre_msg_add_version(struct lustre_msg *msg, int version);
945 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
946 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
947 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
948 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
949 __u64 lustre_msg_get_slv(struct lustre_msg *msg);
950 __u32 lustre_msg_get_limit(struct lustre_msg *msg);
951 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
952 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
953 int lustre_msg_get_status(struct lustre_msg *msg);
954 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
955 int lustre_msg_is_v1(struct lustre_msg *msg);
956 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
957 __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
958 __u32 lustre_msg_get_service_time(struct lustre_msg *msg);
959 __u32 lustre_msg_get_cksum(struct lustre_msg *msg);
960 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
961 void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
962 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
963 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
964 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
965 void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed);
966 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
967 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
968 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
969 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, int *sizes);
970 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
971 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
972 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
973 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
974
975 static inline void
976 lustre_shrink_reply(struct ptlrpc_request *req, int segment,
977                     unsigned int newlen, int move_data)
978 {
979         LASSERT(req->rq_reply_state);
980         LASSERT(req->rq_repmsg);
981         req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
982                                            newlen, move_data);
983 }
984
985 static inline void
986 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
987 {
988         LASSERT(atomic_read(&rs->rs_refcount) > 0);
989         atomic_inc(&rs->rs_refcount);
990 }
991
992 static inline void
993 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
994 {
995         LASSERT(atomic_read(&rs->rs_refcount) > 0);
996         if (atomic_dec_and_test(&rs->rs_refcount))
997                 lustre_free_reply_state(rs);
998 }
999
1000 /* Should only be called once per req */
1001 static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
1002 {
1003         if (req->rq_reply_state == NULL)
1004                 return; /* shouldn't occur */
1005         ptlrpc_rs_decref(req->rq_reply_state);
1006         req->rq_reply_state = NULL;
1007         req->rq_repmsg = NULL;
1008 }
1009
1010 static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
1011 {
1012         return lustre_msg_get_magic(req->rq_reqmsg);
1013 }
1014
1015 static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
1016 {
1017         switch (req->rq_reqmsg->lm_magic) {
1018         case LUSTRE_MSG_MAGIC_V2:
1019                 return req->rq_reqmsg->lm_repsize;
1020         default:
1021                 LASSERTF(0, "incorrect message magic: %08x\n",
1022                          req->rq_reqmsg->lm_magic);
1023                 return -EFAULT;
1024         }
1025 }
1026
1027 /* ldlm/ldlm_lib.c */
1028 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
1029 int client_obd_cleanup(struct obd_device *obddev);
1030 int client_connect_import(const struct lu_env *env,
1031                           struct lustre_handle *conn, struct obd_device *obd,
1032                           struct obd_uuid *cluuid, struct obd_connect_data *,
1033                           void *localdata);
1034 int client_disconnect_export(struct obd_export *exp);
1035 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
1036                            int priority);
1037 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
1038 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
1039
1040 /* ptlrpc/pinger.c */
1041 int ptlrpc_pinger_add_import(struct obd_import *imp);
1042 int ptlrpc_pinger_del_import(struct obd_import *imp);
1043 cfs_time_t ptlrpc_suspend_wakeup_time(void);
1044 #ifdef __KERNEL__
1045 void ping_evictor_start(void);
1046 void ping_evictor_stop(void);
1047 #else
1048 #define ping_evictor_start()    do {} while (0)
1049 #define ping_evictor_stop()     do {} while (0)
1050 #endif
1051 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req);
1052
1053 /* ptlrpc/ptlrpcd.c */
1054 void ptlrpcd_wake(struct ptlrpc_request *req);
1055 void ptlrpcd_add_req(struct ptlrpc_request *req);
1056 int ptlrpcd_addref(void);
1057 void ptlrpcd_decref(void);
1058
1059 /* ptlrpc/lproc_ptlrpc.c */
1060 const char* ll_opcode2str(__u32 opcode);
1061 #ifdef LPROCFS
1062 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
1063 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
1064 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int opc, int bytes);
1065 #else
1066 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
1067 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
1068 static inline void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int opc,
1069                                       int bytes) {}
1070 #endif
1071
1072 /* ptlrpc/llog_server.c */
1073 int llog_origin_handle_create(struct ptlrpc_request *req);
1074 int llog_origin_handle_destroy(struct ptlrpc_request *req);
1075 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
1076 int llog_origin_handle_next_block(struct ptlrpc_request *req);
1077 int llog_origin_handle_read_header(struct ptlrpc_request *req);
1078 int llog_origin_handle_close(struct ptlrpc_request *req);
1079 int llog_origin_handle_cancel(struct ptlrpc_request *req);
1080 int llog_catinfo(struct ptlrpc_request *req);
1081
1082 /* ptlrpc/llog_client.c */
1083 extern struct llog_operations llog_client_ops;
1084
1085 #endif