Whamcloud - gitweb
Branch HEAD
[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_no_ack:1;    /* no ACK, even for
264                                                   difficult requests */
265         unsigned long          rs_scheduled:1;     /* being handled? */
266         unsigned long          rs_scheduled_ever:1;/* any schedule attempts? */
267         unsigned long          rs_handled:1;  /* been handled yet? */
268         unsigned long          rs_on_net:1;   /* reply_out_callback pending? */
269         unsigned long          rs_prealloc:1; /* rs from prealloc list */
270
271         int                    rs_size;
272         __u64                  rs_transno;
273         __u64                  rs_xid;
274         struct obd_export     *rs_export;
275         struct ptlrpc_service *rs_service;
276         lnet_handle_md_t       rs_md_h;
277         atomic_t               rs_refcount;
278
279         struct ptlrpc_svc_ctx *rs_svc_ctx;
280         struct lustre_msg     *rs_repbuf;       /* wrapper */
281         int                    rs_repbuf_len;   /* wrapper buf length */
282         int                    rs_repdata_len;  /* wrapper msg length */
283         struct lustre_msg     *rs_msg;          /* reply message */
284
285         /* locks awaiting client reply ACK */
286         int                    rs_nlocks;
287         struct lustre_handle   rs_locks[RS_MAX_LOCKS];
288         ldlm_mode_t            rs_modes[RS_MAX_LOCKS];
289 };
290
291 struct ptlrpc_thread;
292
293 enum rq_phase {
294         RQ_PHASE_NEW         = 0xebc0de00,
295         RQ_PHASE_RPC         = 0xebc0de01,
296         RQ_PHASE_BULK        = 0xebc0de02,
297         RQ_PHASE_INTERPRET   = 0xebc0de03,
298         RQ_PHASE_COMPLETE    = 0xebc0de04,
299 };
300
301 /** Type of request interpreter call-back */
302 typedef int (*ptlrpc_interpterer_t)(const struct lu_env *env,
303                                     struct ptlrpc_request *req,
304                                     void *arg, int rc);
305
306 struct ptlrpc_request_pool {
307         spinlock_t prp_lock;
308         struct list_head prp_req_list;    /* list of ptlrpc_request structs */
309         int prp_rq_size;
310         void (*prp_populate)(struct ptlrpc_request_pool *, int);
311 };
312
313 struct lu_context;
314 struct lu_env;
315
316 /**
317  * Represents remote procedure call.
318  */
319 struct ptlrpc_request {
320         int rq_type; /* one of PTL_RPC_MSG_* */
321         struct list_head rq_list;
322         struct list_head rq_timed_list;         /* server-side early replies */
323         struct list_head rq_history_list;       /* server-side history */
324         __u64            rq_history_seq;        /* history sequence # */
325         int rq_status;
326         spinlock_t rq_lock;
327         /* client-side flags are serialized by rq_lock */
328         unsigned long rq_intr:1, rq_replied:1, rq_err:1,
329                 rq_timedout:1, rq_resend:1, rq_restart:1,
330                 /*
331                  * when ->rq_replay is set, request is kept by the client even
332                  * after server commits corresponding transaction. This is
333                  * used for operations that require sequence of multiple
334                  * requests to be replayed. The only example currently is file
335                  * open/close/dw/setattr. When last request in such a sequence
336                  * is committed, ->rq_replay is cleared on all requests in the
337                  * sequence.
338                  */
339                 rq_replay:1,
340                 /* this is the last request in the sequence. */
341                 rq_sequence:1,
342                 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
343                 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
344                 rq_early:1, rq_must_unlink:1,
345                 /* server-side flags */
346                 rq_packed_final:1,  /* packed final reply */
347                 rq_sent_final:1;    /* stop sending early replies */
348
349         enum rq_phase rq_phase; /* one of RQ_PHASE_* */
350         atomic_t rq_refcount;   /* client-side refcount for SENT race,
351                                    server-side refcounf for multiple replies */
352
353         struct ptlrpc_thread *rq_svc_thread; /* initial thread servicing req */
354
355         int rq_request_portal;  /* XXX FIXME bug 249 */
356         int rq_reply_portal;    /* XXX FIXME bug 249 */
357
358         int rq_nob_received; /* client-side # reply bytes actually received  */
359
360         int rq_reqlen;
361         struct lustre_msg *rq_reqmsg;
362
363         int rq_replen;
364         struct lustre_msg *rq_repmsg;
365         __u64 rq_transno;
366         __u64 rq_xid;
367         struct list_head rq_replay_list;
368         struct list_head rq_mod_list;
369
370         struct ptlrpc_cli_ctx   *rq_cli_ctx;     /* client's half ctx */
371         struct ptlrpc_svc_ctx   *rq_svc_ctx;     /* server's half ctx */
372         struct list_head         rq_ctx_chain;   /* link to waited ctx */
373
374         struct sptlrpc_flavor    rq_flvr;        /* client & server */
375         enum lustre_sec_part     rq_sp_from;
376
377         unsigned long            /* client/server security flags */
378                                  rq_ctx_init:1,      /* context initiation */
379                                  rq_ctx_fini:1,      /* context destroy */
380                                  rq_bulk_read:1,     /* request bulk read */
381                                  rq_bulk_write:1,    /* request bulk write */
382                                  /* server authentication flags */
383                                  rq_auth_gss:1,      /* authenticated by gss */
384                                  rq_auth_remote:1,   /* authed as remote user */
385                                  rq_auth_usr_root:1, /* authed as root */
386                                  rq_auth_usr_mdt:1,  /* authed as mdt */
387                                  /* security tfm flags */
388                                  rq_pack_udesc:1,
389                                  rq_pack_bulk:1,
390                                  /* doesn't expect reply FIXME */
391                                  rq_no_reply:1;
392
393         uid_t                    rq_auth_uid;        /* authed uid */
394         uid_t                    rq_auth_mapped_uid; /* authed uid mapped to */
395
396         /* (server side), pointed directly into req buffer */
397         struct ptlrpc_user_desc *rq_user_desc;
398
399         /* early replies go to offset 0, regular replies go after that */
400         unsigned int             rq_reply_off;
401
402         /* various buffer pointers */
403         struct lustre_msg       *rq_reqbuf;      /* req wrapper */
404         int                      rq_reqbuf_len;  /* req wrapper buf len */
405         int                      rq_reqdata_len; /* req wrapper msg len */
406         char                    *rq_repbuf;      /* rep buffer */
407         int                      rq_repbuf_len;  /* rep buffer len */
408         struct lustre_msg       *rq_repdata;     /* rep wrapper msg */
409         int                      rq_repdata_len; /* rep wrapper msg len */
410         struct lustre_msg       *rq_clrbuf;      /* only in priv mode */
411         int                      rq_clrbuf_len;  /* only in priv mode */
412         int                      rq_clrdata_len; /* only in priv mode */
413
414         __u32 rq_req_swab_mask;
415         __u32 rq_rep_swab_mask;
416
417         int rq_import_generation;
418         enum lustre_imp_state rq_send_state;
419
420         int rq_early_count;           /* how many early replies (for stats) */
421
422         /* client+server request */
423         lnet_handle_md_t     rq_req_md_h;
424         struct ptlrpc_cb_id  rq_req_cbid;
425
426         /* server-side... */
427         struct timeval       rq_arrival_time;       /* request arrival time */
428         struct ptlrpc_reply_state *rq_reply_state;  /* separated reply state */
429         struct ptlrpc_request_buffer_desc *rq_rqbd; /* incoming request buffer*/
430 #ifdef CRAY_XT3
431         __u32                rq_uid;            /* peer uid, used in MDS only */
432 #endif
433
434         /* client-only incoming reply */
435         lnet_handle_md_t     rq_reply_md_h;
436         cfs_waitq_t          rq_reply_waitq;
437         struct ptlrpc_cb_id  rq_reply_cbid;
438
439         lnet_nid_t           rq_self;
440         lnet_process_id_t    rq_peer;
441         struct obd_export   *rq_export;
442         struct obd_import   *rq_import;
443
444         void (*rq_replay_cb)(struct ptlrpc_request *);
445         void (*rq_commit_cb)(struct ptlrpc_request *);
446         void  *rq_cb_data;
447
448         struct ptlrpc_bulk_desc *rq_bulk;/* client side bulk */
449
450         /* client outgoing req */
451         time_t rq_sent;                  /* when request/reply sent (secs), or
452                                           * time when request should be sent */
453
454         volatile time_t rq_deadline;     /* when request must finish. volatile
455                so that servers' early reply updates to the deadline aren't
456                kept in per-cpu cache */
457         int    rq_timeout;               /* service time estimate (secs) */
458
459         /* Multi-rpc bits */
460         struct list_head rq_set_chain;
461         struct ptlrpc_request_set *rq_set;
462         /** Async completion handler */
463         ptlrpc_interpterer_t rq_interpret_reply;
464         union ptlrpc_async_args rq_async_args;  /* Async completion context */
465         struct ptlrpc_request_pool *rq_pool;    /* Pool if request from
466                                                    preallocated list */
467         struct lu_context           rq_session;
468
469         /* request format */
470         struct req_capsule          rq_pill;
471 };
472
473 static inline void ptlrpc_close_replay_seq(struct ptlrpc_request *req)
474 {
475         spin_lock(&req->rq_lock);
476         req->rq_replay = 0;
477         req->rq_sequence = 1;
478         spin_unlock(&req->rq_lock);
479 }
480
481 static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
482 {
483         LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
484         LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
485         req->rq_req_swab_mask |= 1 << index;
486 }
487
488 static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
489 {
490         LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
491         LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
492         req->rq_rep_swab_mask |= 1 << index;
493 }
494
495 static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
496 {
497         LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
498         return req->rq_req_swab_mask & (1 << index);
499 }
500
501 static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
502 {
503         LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
504         return req->rq_rep_swab_mask & (1 << index);
505 }
506
507 static inline const char *
508 ptlrpc_rqphase2str(const struct ptlrpc_request *req)
509 {
510         switch (req->rq_phase) {
511         case RQ_PHASE_NEW:
512                 return "New";
513         case RQ_PHASE_RPC:
514                 return "Rpc";
515         case RQ_PHASE_BULK:
516                 return "Bulk";
517         case RQ_PHASE_INTERPRET:
518                 return "Interpret";
519         case RQ_PHASE_COMPLETE:
520                 return "Complete";
521         default:
522                 return "?Phase?";
523         }
524 }
525
526 /* Spare the preprocessor, spoil the bugs. */
527 #define FLAG(field, str) (field ? str : "")
528
529 #define DEBUG_REQ_FLAGS(req)                                                    \
530         ptlrpc_rqphase2str(req),                                                \
531         FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"),                    \
532         FLAG(req->rq_err, "E"),                                                 \
533         FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"),   \
534         FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"),                  \
535         FLAG(req->rq_no_resend, "N"),                                           \
536         FLAG(req->rq_waiting, "W"),                                             \
537         FLAG(req->rq_wait_ctx, "C")
538
539 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s"
540
541 void _debug_req(struct ptlrpc_request *req, __u32 mask,
542                 struct libcfs_debug_msg_data *data, const char *fmt, ...)
543         __attribute__ ((format (printf, 4, 5)));
544
545 #define debug_req(cdls, level, req, file, func, line, fmt, a...)              \
546 do {                                                                          \
547         CHECK_STACK();                                                        \
548                                                                               \
549         if (((level) & D_CANTMASK) != 0 ||                                    \
550             ((libcfs_debug & (level)) != 0 &&                                 \
551              (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) {              \
552                 static struct libcfs_debug_msg_data _req_dbg_data =           \
553                 DEBUG_MSG_DATA_INIT(cdls, DEBUG_SUBSYSTEM, file, func, line); \
554                 _debug_req((req), (level), &_req_dbg_data, fmt, ##a);         \
555         }                                                                     \
556 } while(0)
557
558 /* for most callers (level is a constant) this is resolved at compile time */
559 #define DEBUG_REQ(level, req, fmt, args...)                                   \
560 do {                                                                          \
561         if ((level) & (D_ERROR | D_WARNING)) {                                \
562                 static cfs_debug_limit_state_t cdls;                          \
563                 debug_req(&cdls, level, req, __FILE__, __func__, __LINE__,    \
564                           "@@@ "fmt" ", ## args);                             \
565         } else                                                                \
566                 debug_req(NULL, level, req, __FILE__, __func__, __LINE__,     \
567                           "@@@ "fmt" ", ## args);                             \
568 } while (0)
569
570 struct ptlrpc_bulk_page {
571         struct list_head bp_link;
572         int              bp_buflen;
573         int              bp_pageoffset; /* offset within a page */
574         struct page     *bp_page;
575 };
576
577 #define BULK_GET_SOURCE   0
578 #define BULK_PUT_SINK     1
579 #define BULK_GET_SINK     2
580 #define BULK_PUT_SOURCE   3
581
582 struct ptlrpc_bulk_desc {
583         unsigned long bd_success:1;              /* completed successfully */
584         unsigned long bd_network_rw:1;           /* accessible to the network */
585         unsigned long bd_type:2;                 /* {put,get}{source,sink} */
586         unsigned long bd_registered:1;           /* client side */
587         spinlock_t   bd_lock;                   /* serialise with callback */
588         int bd_import_generation;
589         struct obd_export *bd_export;
590         struct obd_import *bd_import;
591         __u32 bd_portal;
592         struct ptlrpc_request *bd_req;          /* associated request */
593         cfs_waitq_t            bd_waitq;        /* server side only WQ */
594         int                    bd_iov_count;    /* # entries in bd_iov */
595         int                    bd_max_iov;      /* allocated size of bd_iov */
596         int                    bd_nob;          /* # bytes covered */
597         int                    bd_nob_transferred; /* # bytes GOT/PUT */
598
599         __u64                  bd_last_xid;
600
601         struct ptlrpc_cb_id    bd_cbid;         /* network callback info */
602         lnet_handle_md_t       bd_md_h;         /* associated MD */
603         lnet_nid_t             bd_sender;       /* stash event::sender */
604
605         cfs_page_t           **bd_enc_pages;
606 #if defined(__KERNEL__)
607         lnet_kiov_t            bd_iov[0];
608 #else
609         lnet_md_iovec_t        bd_iov[0];
610 #endif
611 };
612
613 struct ptlrpc_thread {
614
615         struct list_head t_link; /* active threads in svc->srv_threads */
616
617         void *t_data;            /* thread-private data (preallocated memory) */
618         __u32 t_flags;
619
620         unsigned int t_id; /* service thread index, from ptlrpc_start_threads */
621         cfs_waitq_t t_ctl_waitq;
622         struct lu_env *t_env;
623 };
624
625 struct ptlrpc_request_buffer_desc {
626         struct list_head       rqbd_list;
627         struct list_head       rqbd_reqs;
628         struct ptlrpc_service *rqbd_service;
629         lnet_handle_md_t       rqbd_md_h;
630         int                    rqbd_refcount;
631         char                  *rqbd_buffer;
632         struct ptlrpc_cb_id    rqbd_cbid;
633         struct ptlrpc_request  rqbd_req;
634 };
635
636 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
637 typedef void (*svcreq_printfn_t)(void *, struct ptlrpc_request *);
638
639 struct ptlrpc_service {
640         struct list_head srv_list;              /* chain thru all services */
641         int              srv_max_req_size;      /* biggest request to receive */
642         int              srv_max_reply_size;    /* biggest reply to send */
643         int              srv_buf_size;          /* size of individual buffers */
644         int              srv_nbuf_per_group;    /* # buffers to allocate in 1 group */
645         int              srv_nbufs;             /* total # req buffer descs allocated */
646         int              srv_threads_min;       /* threads to start at SOW */
647         int              srv_threads_max;       /* thread upper limit */
648         int              srv_threads_started;   /* index of last started thread */
649         int              srv_threads_running;   /* # running threads */
650         int              srv_n_difficult_replies; /* # 'difficult' replies */
651         int              srv_n_active_reqs;     /* # reqs being served */
652         cfs_duration_t   srv_rqbd_timeout;      /* timeout before re-posting reqs, in tick */
653         int              srv_watchdog_factor;   /* soft watchdog timeout mutiplier */
654         unsigned         srv_cpu_affinity:1;    /* bind threads to CPUs */
655         unsigned         srv_at_check:1;        /* check early replies */
656         unsigned         srv_is_stopping:1;     /* under unregister_service */
657         cfs_time_t       srv_at_checktime;      /* debug */
658
659         __u32            srv_req_portal;
660         __u32            srv_rep_portal;
661
662         /* AT stuff */
663         struct adaptive_timeout srv_at_estimate;/* estimated rpc service time */
664         spinlock_t        srv_at_lock;
665         struct list_head  srv_at_list;          /* reqs waiting for replies */
666         cfs_timer_t       srv_at_timer;         /* early reply timer */
667
668         int               srv_n_queued_reqs;    /* # reqs in either of the queues below */
669         struct list_head  srv_req_in_queue;     /* incoming reqs */
670         struct list_head  srv_request_queue;    /* reqs waiting for service */
671
672         struct list_head  srv_request_history;  /* request history */
673         __u64             srv_request_seq;      /* next request sequence # */
674         __u64             srv_request_max_cull_seq; /* highest seq culled from history */
675         svcreq_printfn_t  srv_request_history_print_fn; /* service-specific print fn */
676
677         struct list_head  srv_idle_rqbds;       /* request buffers to be reposted */
678         struct list_head  srv_active_rqbds;     /* req buffers receiving */
679         struct list_head  srv_history_rqbds;    /* request buffer history */
680         int               srv_nrqbd_receiving;  /* # posted request buffers */
681         int               srv_n_history_rqbds;  /* # request buffers in history */
682         int               srv_max_history_rqbds;/* max # request buffers in history */
683
684         atomic_t          srv_outstanding_replies;
685         struct list_head  srv_active_replies;   /* all the active replies */
686         struct list_head  srv_reply_queue;      /* replies waiting for service */
687
688         cfs_waitq_t       srv_waitq; /* all threads sleep on this. This
689                                       * wait-queue is signalled when new
690                                       * incoming request arrives and when
691                                       * difficult reply has to be handled. */
692
693         struct list_head   srv_threads;         /* service thread list */
694         svc_handler_t      srv_handler;
695
696         char *srv_name; /* only statically allocated strings here; we don't clean them */
697         char *srv_thread_name; /* only statically allocated strings here; we don't clean them */
698
699         spinlock_t               srv_lock;
700
701         cfs_proc_dir_entry_t    *srv_procroot;
702         struct lprocfs_stats    *srv_stats;
703
704         /* List of free reply_states */
705         struct list_head         srv_free_rs_list;
706         /* waitq to run, when adding stuff to srv_free_rs_list */
707         cfs_waitq_t              srv_free_rs_waitq;
708
709         /*
710          * Tags for lu_context associated with this thread, see struct
711          * lu_context.
712          */
713         __u32                    srv_ctx_tags;
714         /*
715          * if non-NULL called during thread creation (ptlrpc_start_thread())
716          * to initialize service specific per-thread state.
717          */
718         int (*srv_init)(struct ptlrpc_thread *thread);
719         /*
720          * if non-NULL called during thread shutdown (ptlrpc_main()) to
721          * destruct state created by ->srv_init().
722          */
723         void (*srv_done)(struct ptlrpc_thread *thread);
724
725         //struct ptlrpc_srv_ni srv_interfaces[0];
726 };
727
728 struct ptlrpcd_ctl {
729         /**
730          * Ptlrpc thread control flags (LIOD_START, LIOD_STOP, LIOD_STOP_FORCE)
731          */
732         unsigned long               pc_flags;
733         /**
734          * Thread lock protecting structure fields.
735          */
736         spinlock_t                  pc_lock;
737         /**
738          * Start completion.
739          */
740         struct completion           pc_starting;
741         /**
742          * Stop completion.
743          */
744         struct completion           pc_finishing;
745         /**
746          * Thread requests set.
747          */
748         struct ptlrpc_request_set  *pc_set;
749         /**
750          * Thread name used in cfs_daemonize()
751          */
752         char                        pc_name[16];
753         /**
754          * Environment for request interpreters to run in.
755          */
756         struct lu_env               pc_env;
757 #ifndef __KERNEL__
758         /**
759          * Async rpcs flag to make sure that ptlrpcd_check() is called only
760          * once.
761          */
762         int                         pc_recurred;
763         /**
764          * Currently not used.
765          */
766         void                       *pc_callback;
767         /**
768          * User-space async rpcs callback.
769          */
770         void                       *pc_wait_callback;
771         /**
772          * User-space check idle rpcs callback.
773          */
774         void                       *pc_idle_callback;
775 #endif
776 };
777
778 /* Bits for pc_flags */
779 enum ptlrpcd_ctl_flags {
780         /**
781          * Ptlrpc thread start flag.
782          */
783         LIOD_START       = 1 << 0,
784         /**
785          * Ptlrpc thread stop flag.
786          */
787         LIOD_STOP        = 1 << 1,
788         /**
789          * Ptlrpc thread stop force flag. This will cause also
790          * aborting any inflight rpcs handled by thread.
791          */
792         LIOD_STOP_FORCE  = 1 << 2
793 };
794
795 /* ptlrpc/events.c */
796 extern lnet_handle_eq_t ptlrpc_eq_h;
797 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
798                                lnet_process_id_t *peer, lnet_nid_t *self);
799 extern void request_out_callback (lnet_event_t *ev);
800 extern void reply_in_callback(lnet_event_t *ev);
801 extern void client_bulk_callback (lnet_event_t *ev);
802 extern void request_in_callback(lnet_event_t *ev);
803 extern void reply_out_callback(lnet_event_t *ev);
804 extern void server_bulk_callback (lnet_event_t *ev);
805
806 /* ptlrpc/connection.c */
807 struct ptlrpc_connection *ptlrpc_connection_get(lnet_process_id_t peer,
808                                                 lnet_nid_t self,
809                                                 struct obd_uuid *uuid);
810 int ptlrpc_connection_put(struct ptlrpc_connection *c);
811 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
812 int ptlrpc_connection_init(void);
813 void ptlrpc_connection_fini(void);
814 extern lnet_pid_t ptl_get_pid(void);
815
816 /* ptlrpc/niobuf.c */
817 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
818 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
819 int ptlrpc_register_bulk(struct ptlrpc_request *req);
820 void ptlrpc_unregister_bulk (struct ptlrpc_request *req);
821
822 static inline int ptlrpc_bulk_active (struct ptlrpc_bulk_desc *desc)
823 {
824         int           rc;
825
826         spin_lock(&desc->bd_lock);
827         rc = desc->bd_network_rw;
828         spin_unlock(&desc->bd_lock);
829         return (rc);
830 }
831
832 #define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
833 #define PTLRPC_REPLY_EARLY           0x02
834 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
835 int ptlrpc_reply(struct ptlrpc_request *req);
836 int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
837 int ptlrpc_error(struct ptlrpc_request *req);
838 void ptlrpc_resend_req(struct ptlrpc_request *request);
839 int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
840 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
841 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
842
843 /* ptlrpc/client.c */
844 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
845                         struct ptlrpc_client *);
846 void ptlrpc_cleanup_client(struct obd_import *imp);
847 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
848
849 static inline int
850 ptlrpc_client_recv_or_unlink (struct ptlrpc_request *req)
851 {
852         int           rc;
853
854         spin_lock(&req->rq_lock);
855         rc = req->rq_receiving_reply || req->rq_must_unlink;
856         spin_unlock(&req->rq_lock);
857         return (rc);
858 }
859
860 static inline void
861 ptlrpc_wake_client_req (struct ptlrpc_request *req)
862 {
863         if (req->rq_set == NULL)
864                 cfs_waitq_signal(&req->rq_reply_waitq);
865         else
866                 cfs_waitq_signal(&req->rq_set->set_waitq);
867 }
868
869 int ptlrpc_queue_wait(struct ptlrpc_request *req);
870 int ptlrpc_replay_req(struct ptlrpc_request *req);
871 void ptlrpc_unregister_reply(struct ptlrpc_request *req);
872 void ptlrpc_restart_req(struct ptlrpc_request *req);
873 void ptlrpc_abort_inflight(struct obd_import *imp);
874 void ptlrpc_abort_set(struct ptlrpc_request_set *set);
875
876 struct ptlrpc_request_set *ptlrpc_prep_set(void);
877 int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
878                       set_interpreter_func fn, void *data);
879 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
880 int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set);
881 int ptlrpc_set_wait(struct ptlrpc_request_set *);
882 int ptlrpc_expired_set(void *data);
883 void ptlrpc_interrupted_set(void *data);
884 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
885 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
886 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
887 int ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
888                            struct ptlrpc_request *req);
889
890 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
891 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
892
893 struct ptlrpc_request_pool *
894 ptlrpc_init_rq_pool(int, int,
895                     void (*populate_pool)(struct ptlrpc_request_pool *, int));
896
897 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
898 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
899                                             const struct req_format *format);
900 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
901                                             struct ptlrpc_request_pool *,
902                                             const struct req_format *format);
903 void ptlrpc_request_free(struct ptlrpc_request *request);
904 int ptlrpc_request_pack(struct ptlrpc_request *request,
905                         __u32 version, int opcode);
906 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
907                                                 const struct req_format *format,
908                                                 __u32 version, int opcode);
909 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
910                              __u32 version, int opcode, char **bufs,
911                              struct ptlrpc_cli_ctx *ctx);
912 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
913                                        int opcode, int count, __u32 *lengths,
914                                        char **bufs);
915 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
916                                              __u32 version, int opcode,
917                                             int count, __u32 *lengths, char **bufs,
918                                             struct ptlrpc_request_pool *pool);
919 void ptlrpc_req_finished(struct ptlrpc_request *request);
920 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
921 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
922 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
923                                                int npages, int type, int portal);
924 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
925                                               int npages, int type, int portal);
926 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
927 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
928                            cfs_page_t *page, int pageoffset, int len);
929 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
930                                       struct obd_import *imp);
931 __u64 ptlrpc_next_xid(void);
932 __u64 ptlrpc_sample_next_xid(void);
933 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
934
935 struct ptlrpc_service_conf {
936         int psc_nbufs;
937         int psc_bufsize;
938         int psc_max_req_size;
939         int psc_max_reply_size;
940         int psc_req_portal;
941         int psc_rep_portal;
942         int psc_watchdog_factor;
943         int psc_min_threads;
944         int psc_max_threads;
945         __u32 psc_ctx_tags;
946 };
947
948 /* ptlrpc/service.c */
949 void ptlrpc_save_lock (struct ptlrpc_request *req,
950                        struct lustre_handle *lock, int mode, int no_ack);
951 void ptlrpc_commit_replies (struct obd_device *obd);
952 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
953 struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
954                                             svc_handler_t h, char *name,
955                                             struct proc_dir_entry *proc_entry,
956                                             svcreq_printfn_t prntfn,
957                                             char *threadname);
958
959 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
960                                        int max_reply_size,
961                                        int req_portal, int rep_portal,
962                                        int watchdog_factor,
963                                        svc_handler_t, char *name,
964                                        cfs_proc_dir_entry_t *proc_entry,
965                                        svcreq_printfn_t,
966                                        int min_threads, int max_threads,
967                                        char *threadname, __u32 ctx_tags);
968 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
969
970 int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc);
971 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc);
972 int ptlrpc_unregister_service(struct ptlrpc_service *service);
973 int liblustre_check_services (void *arg);
974 void ptlrpc_daemonize(char *name);
975 int ptlrpc_service_health_check(struct ptlrpc_service *);
976
977
978 struct ptlrpc_svc_data {
979         char *name;
980         struct ptlrpc_service *svc;
981         struct ptlrpc_thread *thread;
982         struct obd_device *dev;
983 };
984
985 /* ptlrpc/import.c */
986 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
987 int ptlrpc_init_import(struct obd_import *imp);
988 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
989 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
990
991 /* ptlrpc/pack_generic.c */
992 int ptlrpc_reconnect_import(struct obd_import *imp);
993 int lustre_msg_swabbed(struct lustre_msg *msg);
994 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
995 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
996                         char **bufs);
997 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
998                         __u32 *lens, char **bufs);
999 int lustre_pack_reply(struct ptlrpc_request *, int count, __u32 *lens,
1000                       char **bufs);
1001 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
1002                          __u32 *lens, char **bufs, int flags);
1003 #define LPRFL_EARLY_REPLY 1
1004 int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens,
1005                             char **bufs, int flags);
1006 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
1007                       unsigned int newlen, int move_data);
1008 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
1009 int lustre_msg_hdr_size(__u32 magic, int count);
1010 int lustre_msg_size(__u32 magic, int count, __u32 *lengths);
1011 int lustre_msg_size_v2(int count, __u32 *lengths);
1012 int lustre_packed_msg_size(struct lustre_msg *msg);
1013 int lustre_msg_early_size(void);
1014 int lustre_unpack_msg(struct lustre_msg *m, int len);
1015 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
1016 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
1017 int lustre_msg_buflen(struct lustre_msg *m, int n);
1018 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
1019 int lustre_msg_bufcount(struct lustre_msg *m);
1020 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
1021 void *lustre_swab_buf(struct lustre_msg *, int n, int minlen, void *swabber);
1022 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int n, int minlen,
1023                          void *swabber);
1024 void *lustre_swab_repbuf(struct ptlrpc_request *req, int n, int minlen,
1025                          void *swabber);
1026 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
1027 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
1028 __u32 lustre_msg_get_flags(struct lustre_msg *msg);
1029 void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
1030 void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
1031 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
1032 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
1033 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
1034 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
1035 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
1036 __u32 lustre_msg_get_type(struct lustre_msg *msg);
1037 __u32 lustre_msg_get_version(struct lustre_msg *msg);
1038 void lustre_msg_add_version(struct lustre_msg *msg, int version);
1039 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
1040 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
1041 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
1042 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
1043 __u64 lustre_msg_get_slv(struct lustre_msg *msg);
1044 __u32 lustre_msg_get_limit(struct lustre_msg *msg);
1045 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
1046 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
1047 int lustre_msg_get_status(struct lustre_msg *msg);
1048 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
1049 int lustre_msg_is_v1(struct lustre_msg *msg);
1050 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
1051 __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
1052 __u32 lustre_msg_get_service_time(struct lustre_msg *msg);
1053 __u32 lustre_msg_get_cksum(struct lustre_msg *msg);
1054 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
1055 void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
1056 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
1057 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
1058 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
1059 void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed);
1060 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
1061 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
1062 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
1063 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *sizes);
1064 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
1065 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
1066 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
1067 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
1068
1069 static inline void
1070 lustre_shrink_reply(struct ptlrpc_request *req, int segment,
1071                     unsigned int newlen, int move_data)
1072 {
1073         LASSERT(req->rq_reply_state);
1074         LASSERT(req->rq_repmsg);
1075         req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
1076                                            newlen, move_data);
1077 }
1078
1079 static inline void
1080 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
1081 {
1082         LASSERT(atomic_read(&rs->rs_refcount) > 0);
1083         atomic_inc(&rs->rs_refcount);
1084 }
1085
1086 static inline void
1087 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
1088 {
1089         LASSERT(atomic_read(&rs->rs_refcount) > 0);
1090         if (atomic_dec_and_test(&rs->rs_refcount))
1091                 lustre_free_reply_state(rs);
1092 }
1093
1094 /* Should only be called once per req */
1095 static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
1096 {
1097         if (req->rq_reply_state == NULL)
1098                 return; /* shouldn't occur */
1099         ptlrpc_rs_decref(req->rq_reply_state);
1100         req->rq_reply_state = NULL;
1101         req->rq_repmsg = NULL;
1102 }
1103
1104 static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
1105 {
1106         return lustre_msg_get_magic(req->rq_reqmsg);
1107 }
1108
1109 static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
1110 {
1111         switch (req->rq_reqmsg->lm_magic) {
1112         case LUSTRE_MSG_MAGIC_V2:
1113                 return req->rq_reqmsg->lm_repsize;
1114         default:
1115                 LASSERTF(0, "incorrect message magic: %08x\n",
1116                          req->rq_reqmsg->lm_magic);
1117                 return -EFAULT;
1118         }
1119 }
1120
1121 /* ldlm/ldlm_lib.c */
1122 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
1123 int client_obd_cleanup(struct obd_device *obddev);
1124 int client_connect_import(const struct lu_env *env,
1125                           struct lustre_handle *conn, struct obd_device *obd,
1126                           struct obd_uuid *cluuid, struct obd_connect_data *,
1127                           void *localdata);
1128 int client_disconnect_export(struct obd_export *exp);
1129 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
1130                            int priority);
1131 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
1132 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
1133
1134 /* ptlrpc/pinger.c */
1135 int ptlrpc_pinger_add_import(struct obd_import *imp);
1136 int ptlrpc_pinger_del_import(struct obd_import *imp);
1137 cfs_time_t ptlrpc_suspend_wakeup_time(void);
1138 #ifdef __KERNEL__
1139 void ping_evictor_start(void);
1140 void ping_evictor_stop(void);
1141 #else
1142 #define ping_evictor_start()    do {} while (0)
1143 #define ping_evictor_stop()     do {} while (0)
1144 #endif
1145 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req);
1146
1147 /* ptlrpc/ptlrpcd.c */
1148 int ptlrpcd_start(char *name, struct ptlrpcd_ctl *pc);
1149 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force);
1150 void ptlrpcd_wake(struct ptlrpc_request *req);
1151 void ptlrpcd_add_req(struct ptlrpc_request *req);
1152 int ptlrpcd_addref(void);
1153 void ptlrpcd_decref(void);
1154
1155 /* ptlrpc/lproc_ptlrpc.c */
1156 const char* ll_opcode2str(__u32 opcode);
1157 #ifdef LPROCFS
1158 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
1159 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
1160 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes);
1161 #else
1162 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
1163 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
1164 static inline void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes) {}
1165 #endif
1166
1167 /* ptlrpc/llog_server.c */
1168 int llog_origin_handle_create(struct ptlrpc_request *req);
1169 int llog_origin_handle_destroy(struct ptlrpc_request *req);
1170 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
1171 int llog_origin_handle_next_block(struct ptlrpc_request *req);
1172 int llog_origin_handle_read_header(struct ptlrpc_request *req);
1173 int llog_origin_handle_close(struct ptlrpc_request *req);
1174 int llog_origin_handle_cancel(struct ptlrpc_request *req);
1175 int llog_catinfo(struct ptlrpc_request *req);
1176
1177 /* ptlrpc/llog_client.c */
1178 extern struct llog_operations llog_client_ops;
1179
1180 #endif