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