Whamcloud - gitweb
Update copyrights on source files changed since 2010-02-15.
[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 (c) 2007, 2010, Oracle and/or its affiliates. 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 /** \defgroup PtlRPC Portal RPC and networking module.
37  *
38  * PortalRPC is the layer used by rest of lustre code to achieve network
39  * communications: establish connections with corresponding export and import
40  * states, listen for a service, send and receive RPCs.
41  * PortalRPC also includes base recovery framework: packet resending and
42  * replaying, reconnections, pinger.
43  *
44  * PortalRPC utilizes LNet as its transport layer.
45  *
46  * @{
47  */
48
49
50 #ifndef _LUSTRE_NET_H
51 #define _LUSTRE_NET_H
52
53 /** \defgroup net net
54  *
55  * @{
56  */
57
58 #if defined(__linux__)
59 #include <linux/lustre_net.h>
60 #elif defined(__APPLE__)
61 #include <darwin/lustre_net.h>
62 #elif defined(__WINNT__)
63 #include <winnt/lustre_net.h>
64 #else
65 #error Unsupported operating system.
66 #endif
67
68 #include <libcfs/libcfs.h>
69 // #include <obd.h>
70 #include <lnet/lnet.h>
71 #include <lustre/lustre_idl.h>
72 #include <lustre_ha.h>
73 #include <lustre_sec.h>
74 #include <lustre_import.h>
75 #include <lprocfs_status.h>
76 #include <lu_object.h>
77 #include <lustre_req_layout.h>
78
79 #include <obd_support.h>
80 #include <lustre_ver.h>
81
82 /* MD flags we _always_ use */
83 #define PTLRPC_MD_OPTIONS  0
84
85 /**
86  * Define maxima for bulk I/O
87  * CAVEAT EMPTOR, with multinet (i.e. routers forwarding between networks)
88  * these limits are system wide and not interface-local. */
89 #define PTLRPC_MAX_BRW_BITS     LNET_MTU_BITS
90 #define PTLRPC_MAX_BRW_SIZE     (1<<LNET_MTU_BITS)
91 #define PTLRPC_MAX_BRW_PAGES    (PTLRPC_MAX_BRW_SIZE >> CFS_PAGE_SHIFT)
92
93 /* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
94 #ifdef __KERNEL__
95 # if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
96 #  error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
97 # endif
98 # if (PTLRPC_MAX_BRW_SIZE != (PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE))
99 #  error "PTLRPC_MAX_BRW_SIZE isn't PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE"
100 # endif
101 # if (PTLRPC_MAX_BRW_SIZE > LNET_MTU)
102 #  error "PTLRPC_MAX_BRW_SIZE too big"
103 # endif
104 # if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV)
105 #  error "PTLRPC_MAX_BRW_PAGES too big"
106 # endif
107 #endif /* __KERNEL__ */
108
109 /* Size over which to OBD_VMALLOC() rather than OBD_ALLOC() service request
110  * buffers */
111 #define SVC_BUF_VMALLOC_THRESHOLD (2 * CFS_PAGE_SIZE)
112
113 /**
114  * The following constants determine how memory is used to buffer incoming
115  * service requests.
116  *
117  * ?_NBUFS              # buffers to allocate when growing the pool
118  * ?_BUFSIZE            # bytes in a single request buffer
119  * ?_MAXREQSIZE         # maximum request service will receive
120  *
121  * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
122  * of ?_NBUFS is added to the pool.
123  *
124  * Messages larger than ?_MAXREQSIZE are dropped.  Request buffers are
125  * considered full when less than ?_MAXREQSIZE is left in them.
126  */
127 #define LDLM_THREADS_AUTO_MIN (2)
128 #define LDLM_THREADS_AUTO_MAX min_t(unsigned, cfs_num_online_cpus() * \
129                                   cfs_num_online_cpus() * 32, 128)
130 #define LDLM_BL_THREADS  LDLM_THREADS_AUTO_MIN
131 #define LDLM_NBUFS      (64 * cfs_num_online_cpus())
132 #define LDLM_BUFSIZE    (8 * 1024)
133 #define LDLM_MAXREQSIZE (5 * 1024)
134 #define LDLM_MAXREPSIZE (1024)
135
136 #define MDT_MIN_THREADS 2UL
137 #define MDT_MAX_THREADS 512UL
138 #define MDT_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
139                                   cfs_num_physpages >> (25 - CFS_PAGE_SHIFT)), \
140                                   2UL)
141
142 /** Absolute limits */
143 #define MDS_THREADS_MIN 2
144 #define MDS_THREADS_MAX 512
145 #define MDS_THREADS_MIN_READPAGE 2
146 #define MDS_NBUFS       (64 * cfs_num_online_cpus())
147 #define MDS_BUFSIZE     (8 * 1024)
148 /**
149  * Assume file name length = FNAME_MAX = 256 (true for ext3).
150  *        path name length = PATH_MAX = 4096
151  *        LOV MD size max  = EA_MAX = 4000
152  * symlink:  FNAME_MAX + PATH_MAX  <- largest
153  * link:     FNAME_MAX + PATH_MAX  (mds_rec_link < mds_rec_create)
154  * rename:   FNAME_MAX + FNAME_MAX
155  * open:     FNAME_MAX + EA_MAX
156  *
157  * MDS_MAXREQSIZE ~= 4736 bytes =
158  * lustre_msg + ldlm_request + mds_body + mds_rec_create + FNAME_MAX + PATH_MAX
159  * MDS_MAXREPSIZE ~= 8300 bytes = lustre_msg + llog_header
160  * or, for mds_close() and mds_reint_unlink() on a many-OST filesystem:
161  *      = 9210 bytes = lustre_msg + mds_body + 160 * (easize + cookiesize)
162  *
163  * Realistic size is about 512 bytes (20 character name + 128 char symlink),
164  * except in the open case where there are a large number of OSTs in a LOV.
165  */
166 #define MDS_MAXREQSIZE  (5 * 1024)
167 #define MDS_MAXREPSIZE  max(9 * 1024, 362 + LOV_MAX_STRIPE_COUNT * 56)
168
169 /** FLD_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + md_fld */
170 #define FLD_MAXREQSIZE  (160)
171
172 /** FLD_MAXREPSIZE == lustre_msg + ptlrpc_body + md_fld */
173 #define FLD_MAXREPSIZE  (152)
174
175 /**
176  * SEQ_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + lu_range +
177  * __u32 padding */
178 #define SEQ_MAXREQSIZE  (160)
179
180 /** SEQ_MAXREPSIZE == lustre_msg + ptlrpc_body + lu_range */
181 #define SEQ_MAXREPSIZE  (152)
182
183 /** MGS threads must be >= 3, see bug 22458 comment #28 */
184 #define MGS_THREADS_AUTO_MIN 3
185 #define MGS_THREADS_AUTO_MAX 32
186 #define MGS_NBUFS       (64 * cfs_num_online_cpus())
187 #define MGS_BUFSIZE     (8 * 1024)
188 #define MGS_MAXREQSIZE  (7 * 1024)
189 #define MGS_MAXREPSIZE  (9 * 1024)
190
191 /** Absolute OSS limits */
192 #define OSS_THREADS_MIN 3       /* difficult replies, HPQ, others */
193 #define OSS_THREADS_MAX 512
194 #define OST_NBUFS       (64 * cfs_num_online_cpus())
195 #define OST_BUFSIZE     (8 * 1024)
196
197 /**
198  * OST_MAXREQSIZE ~= 4768 bytes =
199  * lustre_msg + obdo + 16 * obd_ioobj + 256 * niobuf_remote
200  *
201  * - single object with 16 pages is 512 bytes
202  * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
203  */
204 #define OST_MAXREQSIZE  (5 * 1024)
205 #define OST_MAXREPSIZE  (9 * 1024)
206
207 /* Macro to hide a typecast. */
208 #define ptlrpc_req_async_args(req) ((void *)&req->rq_async_args)
209
210 /**
211  * Structure to single define portal connection.
212  */
213 struct ptlrpc_connection {
214         /** linkage for connections hash table */
215         cfs_hlist_node_t        c_hash;
216         /** Our own lnet nid for this connection */
217         lnet_nid_t              c_self;
218         /** Remote side nid for this connection */
219         lnet_process_id_t       c_peer;
220         /** UUID of the other side */
221         struct obd_uuid         c_remote_uuid;
222         /** reference counter for this connection */
223         cfs_atomic_t            c_refcount;
224 };
225
226 /** Client definition for PortalRPC */
227 struct ptlrpc_client {
228         /** What lnet portal does this client send messages to by default */
229         __u32                   cli_request_portal;
230         /** What portal do we expect replies on */
231         __u32                   cli_reply_portal;
232         /** Name of the client */
233         char                   *cli_name;
234 };
235
236 /** state flags of requests */
237 /* XXX only ones left are those used by the bulk descs as well! */
238 #define PTL_RPC_FL_INTR      (1 << 0)  /* reply wait was interrupted by user */
239 #define PTL_RPC_FL_TIMEOUT   (1 << 7)  /* request timed out waiting for reply */
240
241 #define REQ_MAX_ACK_LOCKS 8
242
243 union ptlrpc_async_args {
244         /**
245          * Scratchpad for passing args to completion interpreter. Users
246          * cast to the struct of their choosing, and LASSERT that this is
247          * big enough.  For _tons_ of context, OBD_ALLOC a struct and store
248          * a pointer to it here.  The pointer_arg ensures this struct is at
249          * least big enough for that.
250          */
251         void      *pointer_arg[11];
252         __u64      space[6];
253 };
254
255 struct ptlrpc_request_set;
256 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
257
258 /**
259  * Definition of request set structure.
260  * Request set is a list of requests (not necessary to the same target) that
261  * once populated with RPCs could be sent in parallel.
262  * There are two kinds of request sets. General purpose and with dedicated
263  * serving thread. Example of the latter is ptlrpcd set.
264  * For general purpose sets once request set started sending it is impossible
265  * to add new requests to such set.
266  * Provides a way to call "completion callbacks" when all requests in the set
267  * returned.
268  */
269 struct ptlrpc_request_set {
270         /** number of uncompleted requests */
271         cfs_atomic_t          set_remaining;
272         /** wait queue to wait on for request events */
273         cfs_waitq_t           set_waitq;
274         cfs_waitq_t          *set_wakeup_ptr;
275         /** List of requests in the set */
276         cfs_list_t            set_requests;
277         /**
278          * List of completion callbacks to be called when the set is completed
279          * This is only used if \a set_interpret is NULL.
280          * Links struct ptlrpc_set_cbdata.
281          */
282         cfs_list_t            set_cblist;
283         /** Completion callback, if only one. */
284         set_interpreter_func  set_interpret;
285         /** opaq argument passed to completion \a set_interpret callback. */
286         void                 *set_arg;
287         /**
288          * Lock for \a set_new_requests manipulations
289          * locked so that any old caller can communicate requests to
290          * the set holder who can then fold them into the lock-free set
291          */
292         cfs_spinlock_t        set_new_req_lock;
293         /** List of new yet unsent requests. Only used with ptlrpcd now. */
294         cfs_list_t            set_new_requests;
295 };
296
297 /**
298  * Description of a single ptrlrpc_set callback
299  */
300 struct ptlrpc_set_cbdata {
301         /** List linkage item */
302         cfs_list_t              psc_item;
303         /** Pointer to interpreting function */
304         set_interpreter_func    psc_interpret;
305         /** Opaq argument to pass to the callback */
306         void                   *psc_data;
307 };
308
309 struct ptlrpc_bulk_desc;
310
311 /**
312  * ptlrpc callback & work item stuff
313  */
314 struct ptlrpc_cb_id {
315         void   (*cbid_fn)(lnet_event_t *ev);     /* specific callback fn */
316         void    *cbid_arg;                      /* additional arg */
317 };
318
319 /** Maximum number of locks to fit into reply state */ 
320 #define RS_MAX_LOCKS 8
321 #define RS_DEBUG     1
322
323 /**
324  * Structure to define reply state on the server
325  * Reply state holds various reply message information. Also for "difficult"
326  * replies (rep-ack case) we store the state after sending reply and wait
327  * for the client to acknowledge the reception. In these cases locks could be
328  * added to the state for replay/failover consistency guarantees.
329  */
330 struct ptlrpc_reply_state {
331         /** Callback description */
332         struct ptlrpc_cb_id    rs_cb_id;
333         /** Linkage for list of all reply states in a system */
334         cfs_list_t             rs_list;
335         /** Linkage for list of all reply states on same export */
336         cfs_list_t             rs_exp_list;
337         /** Linkage for list of all reply states for same obd */
338         cfs_list_t             rs_obd_list;
339 #if RS_DEBUG
340         cfs_list_t             rs_debug_list;
341 #endif
342         /** A spinlock to protect the reply state flags */
343         cfs_spinlock_t         rs_lock;
344         /** Reply state flags */
345         unsigned long          rs_difficult:1;     /* ACK/commit stuff */
346         unsigned long          rs_no_ack:1;    /* no ACK, even for
347                                                   difficult requests */
348         unsigned long          rs_scheduled:1;     /* being handled? */
349         unsigned long          rs_scheduled_ever:1;/* any schedule attempts? */
350         unsigned long          rs_handled:1;  /* been handled yet? */
351         unsigned long          rs_on_net:1;   /* reply_out_callback pending? */
352         unsigned long          rs_prealloc:1; /* rs from prealloc list */
353         unsigned long          rs_committed:1;/* the transaction was committed
354                                                  and the rs was dispatched
355                                                  by ptlrpc_commit_replies */
356         /** Size of the state */
357         int                    rs_size;
358         /** opcode */
359         __u32                  rs_opc;
360         /** Transaction number */
361         __u64                  rs_transno;
362         /** xid */
363         __u64                  rs_xid;
364         struct obd_export     *rs_export;
365         struct ptlrpc_service *rs_service;
366         /** Lnet metadata handle for the reply */
367         lnet_handle_md_t       rs_md_h;
368         cfs_atomic_t           rs_refcount;
369
370         /** Context for the sevice thread */
371         struct ptlrpc_svc_ctx *rs_svc_ctx;
372         /** Reply buffer (actually sent to the client), encoded if needed */
373         struct lustre_msg     *rs_repbuf;       /* wrapper */
374         /** Size of the reply buffer */
375         int                    rs_repbuf_len;   /* wrapper buf length */
376         /** Size of the reply message */
377         int                    rs_repdata_len;  /* wrapper msg length */
378         /**
379          * Actual reply message. Its content is encrupted (if needed) to
380          * produce reply buffer for actual sending. In simple case
381          * of no network encryption we jus set \a rs_repbuf to \a rs_msg
382          */
383         struct lustre_msg     *rs_msg;          /* reply message */
384
385         /** Number of locks awaiting client ACK */
386         int                    rs_nlocks;
387         /** Handles of locks awaiting client reply ACK */
388         struct lustre_handle   rs_locks[RS_MAX_LOCKS];
389         /** Lock modes of locks in \a rs_locks */
390         ldlm_mode_t            rs_modes[RS_MAX_LOCKS];
391 };
392
393 struct ptlrpc_thread;
394
395 /** RPC stages */
396 enum rq_phase {
397         RQ_PHASE_NEW            = 0xebc0de00,
398         RQ_PHASE_RPC            = 0xebc0de01,
399         RQ_PHASE_BULK           = 0xebc0de02,
400         RQ_PHASE_INTERPRET      = 0xebc0de03,
401         RQ_PHASE_COMPLETE       = 0xebc0de04,
402         RQ_PHASE_UNREGISTERING  = 0xebc0de05,
403         RQ_PHASE_UNDEFINED      = 0xebc0de06
404 };
405
406 /** Type of request interpreter call-back */
407 typedef int (*ptlrpc_interpterer_t)(const struct lu_env *env,
408                                     struct ptlrpc_request *req,
409                                     void *arg, int rc);
410
411 /**
412  * Definition of request pool structure.
413  * The pool is used to store empty preallocated requests for the case
414  * when we would actually need to send something without performing
415  * any allocations (to avoid e.g. OOM).
416  */
417 struct ptlrpc_request_pool {
418         /** Locks the list */
419         cfs_spinlock_t prp_lock;
420         /** list of ptlrpc_request structs */
421         cfs_list_t prp_req_list;
422         /** Maximum message size that would fit into a rquest from this pool */
423         int prp_rq_size;
424         /** Function to allocate more requests for this pool */
425         void (*prp_populate)(struct ptlrpc_request_pool *, int);
426 };
427
428 struct lu_context;
429 struct lu_env;
430
431 struct ldlm_lock;
432
433 /**
434  * Basic request prioritization operations structure.
435  * The whole idea is centered around locks and RPCs that might affect locks.
436  * When a lock is contended we try to give priority to RPCs that might lead
437  * to fastest release of that lock.
438  * Currently only implemented for OSTs only in a way that makes all
439  * IO and truncate RPCs that are coming from a locked region where a lock is
440  * contended a priority over other requests.
441  */
442 struct ptlrpc_hpreq_ops {
443         /**
444          * Check if the lock handle of the given lock is the same as
445          * taken from the request.
446          */
447         int  (*hpreq_lock_match)(struct ptlrpc_request *, struct ldlm_lock *);
448         /**
449          * Check if the request is a high priority one.
450          */
451         int  (*hpreq_check)(struct ptlrpc_request *);
452 };
453
454 /**
455  * Represents remote procedure call.
456  *
457  * This is a staple structure used by everybody wanting to send a request
458  * in Lustre.
459  */
460 struct ptlrpc_request {
461         /* Request type: one of PTL_RPC_MSG_* */
462         int rq_type;
463         /**
464          * Linkage item through which this request is included into
465          * sending/delayed lists on client and into rqbd list on server
466          */
467         cfs_list_t rq_list;
468         /**
469          * Server side list of incoming unserved requests sorted by arrival
470          * time.  Traversed from time to time to notice about to expire
471          * requests and sent back "early replies" to clients to let them
472          * know server is alive and well, just very busy to service their
473          * requests in time
474          */
475         cfs_list_t rq_timed_list;
476         /** server-side history, used for debuging purposes. */
477         cfs_list_t rq_history_list;
478         /** server-side per-export list */
479         cfs_list_t rq_exp_list;
480         /** server-side hp handlers */
481         struct ptlrpc_hpreq_ops *rq_ops;
482         /** history sequence # */
483         __u64 rq_history_seq;
484         /** the index of service's srv_at_array into which request is linked */
485         time_t rq_at_index;
486         /** Result of request processing */
487         int rq_status;
488         /** Lock to protect request flags and some other important bits, like
489          * rq_list
490          */
491         cfs_spinlock_t rq_lock;
492         /** client-side flags are serialized by rq_lock */
493         unsigned long rq_intr:1, rq_replied:1, rq_err:1,
494                 rq_timedout:1, rq_resend:1, rq_restart:1,
495                 /**
496                  * when ->rq_replay is set, request is kept by the client even
497                  * after server commits corresponding transaction. This is
498                  * used for operations that require sequence of multiple
499                  * requests to be replayed. The only example currently is file
500                  * open/close. When last request in such a sequence is
501                  * committed, ->rq_replay is cleared on all requests in the
502                  * sequence.
503                  */
504                 rq_replay:1,
505                 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
506                 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
507                 rq_early:1, rq_must_unlink:1,
508                 rq_fake:1,          /* this fake req */
509                 /* server-side flags */
510                 rq_packed_final:1,  /* packed final reply */
511                 rq_hp:1,            /* high priority RPC */
512                 rq_at_linked:1,     /* link into service's srv_at_array */
513                 rq_reply_truncate:1,
514                 rq_committed:1,
515                 /* whether the "rq_set" is a valid one */
516                 rq_invalid_rqset:1;
517
518         enum rq_phase rq_phase; /* one of RQ_PHASE_* */
519         enum rq_phase rq_next_phase; /* one of RQ_PHASE_* to be used next */
520         cfs_atomic_t rq_refcount;/* client-side refcount for SENT race,
521                                     server-side refcounf for multiple replies */
522
523         /** initial thread servicing this request */
524         struct ptlrpc_thread *rq_svc_thread;
525
526         /** Portal to which this request would be sent */
527         int rq_request_portal;  /* XXX FIXME bug 249 */
528         /** Portal where to wait for reply and where reply would be sent */
529         int rq_reply_portal;    /* XXX FIXME bug 249 */
530
531         /**
532          * client-side:
533          * !rq_truncate : # reply bytes actually received,
534          *  rq_truncate : required repbuf_len for resend
535          */
536         int rq_nob_received;
537         /** Request length */
538         int rq_reqlen;
539          /** Request message - what client sent */
540         struct lustre_msg *rq_reqmsg;
541
542         /** Reply length */
543         int rq_replen;
544         /** Reply message - server response */
545         struct lustre_msg *rq_repmsg;
546         /** Transaction number */
547         __u64 rq_transno;
548         /** xid */
549         __u64 rq_xid;
550         /**
551          * List item to for replay list. Not yet commited requests get linked
552          * there.
553          * Also see \a rq_replay comment above.
554          */
555         cfs_list_t rq_replay_list;
556
557         /**
558          * security and encryption data
559          * @{ */
560         struct ptlrpc_cli_ctx   *rq_cli_ctx;     /* client's half ctx */
561         struct ptlrpc_svc_ctx   *rq_svc_ctx;     /* server's half ctx */
562         cfs_list_t               rq_ctx_chain;   /* link to waited ctx */
563
564         struct sptlrpc_flavor    rq_flvr;        /* client & server */
565         enum lustre_sec_part     rq_sp_from;
566
567         unsigned long            /* client/server security flags */
568                                  rq_ctx_init:1,      /* context initiation */
569                                  rq_ctx_fini:1,      /* context destroy */
570                                  rq_bulk_read:1,     /* request bulk read */
571                                  rq_bulk_write:1,    /* request bulk write */
572                                  /* server authentication flags */
573                                  rq_auth_gss:1,      /* authenticated by gss */
574                                  rq_auth_remote:1,   /* authed as remote user */
575                                  rq_auth_usr_root:1, /* authed as root */
576                                  rq_auth_usr_mdt:1,  /* authed as mdt */
577                                  /* security tfm flags */
578                                  rq_pack_udesc:1,
579                                  rq_pack_bulk:1,
580                                  /* doesn't expect reply FIXME */
581                                  rq_no_reply:1,
582                                  rq_pill_init:1;     /* pill initialized */
583
584         uid_t                    rq_auth_uid;        /* authed uid */
585         uid_t                    rq_auth_mapped_uid; /* authed uid mapped to */
586
587         /* (server side), pointed directly into req buffer */
588         struct ptlrpc_user_desc *rq_user_desc;
589
590         /** @} */
591
592         /** early replies go to offset 0, regular replies go after that */
593         unsigned int             rq_reply_off;
594
595         /* various buffer pointers */
596         struct lustre_msg       *rq_reqbuf;      /* req wrapper */
597         int                      rq_reqbuf_len;  /* req wrapper buf len */
598         int                      rq_reqdata_len; /* req wrapper msg len */
599         char                    *rq_repbuf;      /* rep buffer */
600         int                      rq_repbuf_len;  /* rep buffer len */
601         struct lustre_msg       *rq_repdata;     /* rep wrapper msg */
602         int                      rq_repdata_len; /* rep wrapper msg len */
603         struct lustre_msg       *rq_clrbuf;      /* only in priv mode */
604         int                      rq_clrbuf_len;  /* only in priv mode */
605         int                      rq_clrdata_len; /* only in priv mode */
606
607         /** Fields that help to see if request and reply were swabbed or not */
608         __u32 rq_req_swab_mask;
609         __u32 rq_rep_swab_mask;
610
611         /** What was import generation when this request was sent */
612         int rq_import_generation;
613         enum lustre_imp_state rq_send_state;
614
615         /** how many early replies (for stats) */
616         int rq_early_count;
617
618         /** client+server request */
619         lnet_handle_md_t     rq_req_md_h;
620         struct ptlrpc_cb_id  rq_req_cbid;
621         /** optional time limit for send attempts */
622         cfs_duration_t       rq_delay_limit;
623         /** time request was first queued */
624         cfs_time_t           rq_queued_time;
625
626         /* server-side... */
627         /** request arrival time */
628         struct timeval       rq_arrival_time;
629         /** separated reply state */
630         struct ptlrpc_reply_state *rq_reply_state;
631         /** incoming request buffer */
632         struct ptlrpc_request_buffer_desc *rq_rqbd;
633 #ifdef CRAY_XT3
634         __u32                rq_uid;            /* peer uid, used in MDS only */
635 #endif
636
637         /** client-only incoming reply */
638         lnet_handle_md_t     rq_reply_md_h;
639         cfs_waitq_t          rq_reply_waitq;
640         struct ptlrpc_cb_id  rq_reply_cbid;
641
642         /** our LNet NID */
643         lnet_nid_t           rq_self;
644         /** Peer description (the other side) */
645         lnet_process_id_t    rq_peer;
646         /** Server-side, export on which request was received */
647         struct obd_export   *rq_export;
648         /** Client side, import where request is being sent */
649         struct obd_import   *rq_import;
650
651         /** Replay callback, called after request is replayed at recovery */
652         void (*rq_replay_cb)(struct ptlrpc_request *);
653         /**
654          * Commit callback, called when request is committed and about to be
655          * freed.
656          */
657         void (*rq_commit_cb)(struct ptlrpc_request *);
658         /** Opaq data for replay and commit callbacks. */
659         void  *rq_cb_data;
660
661         /** For bulk requests on client only: bulk descriptor */
662         struct ptlrpc_bulk_desc *rq_bulk;
663
664         /** client outgoing req */
665         /**
666          * when request/reply sent (secs), or time when request should be sent
667          */
668         time_t rq_sent;
669
670         /** when request must finish. volatile
671          * so that servers' early reply updates to the deadline aren't
672          * kept in per-cpu cache */
673         volatile time_t rq_deadline;
674         /** when req reply unlink must finish. */
675         time_t rq_reply_deadline;
676         /** when req bulk unlink must finish. */
677         time_t rq_bulk_deadline;
678         /**
679          * service time estimate (secs) 
680          * If the requestsis not served by this time, it is marked as timed out.
681          */
682         int    rq_timeout;
683
684         /** Multi-rpc bits */
685         /** Link item for request set lists */
686         cfs_list_t  rq_set_chain;
687         /** Per-request waitq introduced by bug 21938 for recovery waiting */
688         cfs_waitq_t rq_set_waitq;
689         /** Link back to the request set */
690         struct ptlrpc_request_set *rq_set;
691         /** Async completion handler, called when reply is received */
692         ptlrpc_interpterer_t rq_interpret_reply;
693         /** Async completion context */
694         union ptlrpc_async_args rq_async_args;
695
696         /** Pool if request is from preallocated list */
697         struct ptlrpc_request_pool *rq_pool;
698
699         struct lu_context           rq_session;
700         struct lu_context           rq_recov_session;
701
702         /** request format description */
703         struct req_capsule          rq_pill;
704 };
705
706 /**
707  * Call completion handler for rpc if any, return it's status or original
708  * rc if there was no handler defined for this request.
709  */
710 static inline int ptlrpc_req_interpret(const struct lu_env *env,
711                                        struct ptlrpc_request *req, int rc)
712 {
713         if (req->rq_interpret_reply != NULL) {
714                 req->rq_status = req->rq_interpret_reply(env, req,
715                                                          &req->rq_async_args,
716                                                          rc);
717                 return req->rq_status;
718         }
719         return rc;
720 }
721
722 /**
723  * Returns 1 if request buffer at offset \a index was already swabbed
724  */
725 static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
726 {
727         LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
728         return req->rq_req_swab_mask & (1 << index);
729 }
730
731 /**
732  * Returns 1 if request reply buffer at offset \a index was already swabbed
733  */
734 static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
735 {
736         LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
737         return req->rq_rep_swab_mask & (1 << index);
738 }
739
740 /**
741  * Returns 1 if request needs to be swabbed into local cpu byteorder
742  */
743 static inline int ptlrpc_req_need_swab(struct ptlrpc_request *req)
744 {
745         return lustre_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
746 }
747
748 /**
749  * Returns 1 if request reply needs to be swabbed into local cpu byteorder
750  */
751 static inline int ptlrpc_rep_need_swab(struct ptlrpc_request *req)
752 {
753         return lustre_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
754 }
755
756 /**
757  * Mark request buffer at offset \a index that it was already swabbed
758  */
759 static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
760 {
761         LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
762         LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
763         req->rq_req_swab_mask |= 1 << index;
764 }
765
766 /**
767  * Mark request reply buffer at offset \a index that it was already swabbed
768  */
769 static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
770 {
771         LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
772         LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
773         req->rq_rep_swab_mask |= 1 << index;
774 }
775
776 /**
777  * Convert numerical request phase value \a phase into text string description
778  */
779 static inline const char *
780 ptlrpc_phase2str(enum rq_phase phase)
781 {
782         switch (phase) {
783         case RQ_PHASE_NEW:
784                 return "New";
785         case RQ_PHASE_RPC:
786                 return "Rpc";
787         case RQ_PHASE_BULK:
788                 return "Bulk";
789         case RQ_PHASE_INTERPRET:
790                 return "Interpret";
791         case RQ_PHASE_COMPLETE:
792                 return "Complete";
793         case RQ_PHASE_UNREGISTERING:
794                 return "Unregistering";
795         default:
796                 return "?Phase?";
797         }
798 }
799
800 /**
801  * Convert numerical request phase of the request \a req into text stringi
802  * description
803  */
804 static inline const char *
805 ptlrpc_rqphase2str(struct ptlrpc_request *req)
806 {
807         return ptlrpc_phase2str(req->rq_phase);
808 }
809
810 /**
811  * Debugging functions and helpers to print request structure into debug log
812  * @{
813  */ 
814 /* Spare the preprocessor, spoil the bugs. */
815 #define FLAG(field, str) (field ? str : "")
816
817 /** Convert bit flags into a string */
818 #define DEBUG_REQ_FLAGS(req)                                                    \
819         ptlrpc_rqphase2str(req),                                                \
820         FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"),                    \
821         FLAG(req->rq_err, "E"),                                                 \
822         FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"),   \
823         FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"),                  \
824         FLAG(req->rq_no_resend, "N"),                                           \
825         FLAG(req->rq_waiting, "W"),                                             \
826         FLAG(req->rq_wait_ctx, "C"), FLAG(req->rq_hp, "H"),                     \
827         FLAG(req->rq_committed, "M")
828
829 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s%s%s"
830
831 void _debug_req(struct ptlrpc_request *req, __u32 mask,
832                 struct libcfs_debug_msg_data *data, const char *fmt, ...)
833         __attribute__ ((format (printf, 4, 5)));
834
835 /**
836  * Helper that decides if we need to print request accordig to current debug
837  * level settings
838  */
839 #define debug_req(cdls, level, req, file, func, line, fmt, a...)              \
840 do {                                                                          \
841         CFS_CHECK_STACK();                                                    \
842                                                                               \
843         if (((level) & D_CANTMASK) != 0 ||                                    \
844             ((libcfs_debug & (level)) != 0 &&                                 \
845              (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) {              \
846                 static struct libcfs_debug_msg_data _req_dbg_data =           \
847                 DEBUG_MSG_DATA_INIT(cdls, DEBUG_SUBSYSTEM, file, func, line); \
848                 _debug_req((req), (level), &_req_dbg_data, fmt, ##a);         \
849         }                                                                     \
850 } while(0)
851
852 /**
853  * This is the debug print function you need to use to print request sturucture
854  * content into lustre debug log.
855  * for most callers (level is a constant) this is resolved at compile time */
856 #define DEBUG_REQ(level, req, fmt, args...)                                   \
857 do {                                                                          \
858         if ((level) & (D_ERROR | D_WARNING)) {                                \
859                 static cfs_debug_limit_state_t cdls;                          \
860                 debug_req(&cdls, level, req, __FILE__, __func__, __LINE__,    \
861                           "@@@ "fmt" ", ## args);                             \
862         } else                                                                \
863                 debug_req(NULL, level, req, __FILE__, __func__, __LINE__,     \
864                           "@@@ "fmt" ", ## args);                             \
865 } while (0)
866 /** @} */
867
868 /**
869  * Structure that defines a single page of a bulk transfer
870  */
871 struct ptlrpc_bulk_page {
872         /** Linkage to list of pages in a bulk */
873         cfs_list_t       bp_link;
874         /**
875          * Number of bytes in a page to transfer starting from \a bp_pageoffset
876          */
877         int              bp_buflen;
878         /** offset within a page */
879         int              bp_pageoffset;
880         /** The page itself */
881         struct page     *bp_page;
882 };
883
884 #define BULK_GET_SOURCE   0
885 #define BULK_PUT_SINK     1
886 #define BULK_GET_SINK     2
887 #define BULK_PUT_SOURCE   3
888
889 /**
890  * Definition of buk descriptor.
891  * Bulks are special "Two phase" RPCs where initial request message
892  * is sent first and it is followed bt a transfer (o receiving) of a large
893  * amount of data to be settled into pages referenced from the bulk descriptors.
894  * Bulks transfers (the actual data following the small requests) are done
895  * on separate LNet portals.
896  * In lustre we use bulk transfers for READ and WRITE transfers from/to OSTs.
897  *  Another user is readpage for MDT.
898  */
899 struct ptlrpc_bulk_desc {
900         /** completed successfully */
901         unsigned long bd_success:1;
902         /** accessible to the network (network io potentially in progress) */
903         unsigned long bd_network_rw:1;
904         /** {put,get}{source,sink} */
905         unsigned long bd_type:2;
906         /** client side */
907         unsigned long bd_registered:1;
908         /** For serialization with callback */
909         cfs_spinlock_t bd_lock;
910         /** Import generation when request for this bulk was sent */
911         int bd_import_generation;
912         /** Server side - export this bulk created for */
913         struct obd_export *bd_export;
914         /** Client side - import this bulk was sent on */
915         struct obd_import *bd_import;
916         /** LNet portal for this bulk */
917         __u32 bd_portal;
918         /** Back pointer to the request */
919         struct ptlrpc_request *bd_req;
920         cfs_waitq_t            bd_waitq;        /* server side only WQ */
921         int                    bd_iov_count;    /* # entries in bd_iov */
922         int                    bd_max_iov;      /* allocated size of bd_iov */
923         int                    bd_nob;          /* # bytes covered */
924         int                    bd_nob_transferred; /* # bytes GOT/PUT */
925
926         __u64                  bd_last_xid;
927
928         struct ptlrpc_cb_id    bd_cbid;         /* network callback info */
929         lnet_handle_md_t       bd_md_h;         /* associated MD */
930         lnet_nid_t             bd_sender;       /* stash event::sender */
931
932 #if defined(__KERNEL__)
933         /*
934          * encrypt iov, size is either 0 or bd_iov_count.
935          */
936         lnet_kiov_t           *bd_enc_iov;
937
938         lnet_kiov_t            bd_iov[0];
939 #else
940         lnet_md_iovec_t        bd_iov[0];
941 #endif
942 };
943
944 /**
945  * Definition of server service thread structure
946  */
947 struct ptlrpc_thread {
948         /**
949          * List of active threads in svc->srv_threads
950          */
951         cfs_list_t t_link;
952         /**
953          * thread-private data (preallocated memory)
954          */
955         void *t_data;
956         __u32 t_flags;
957         /**
958          * service thread index, from ptlrpc_start_threads
959          */
960         unsigned int t_id;
961         /**
962          * service thread pid
963          */
964         pid_t t_pid; 
965         /**
966          * put watchdog in the structure per thread b=14840
967          */
968         struct lc_watchdog *t_watchdog;
969         /**
970          * the svc this thread belonged to b=18582
971          */
972         struct ptlrpc_service *t_svc;
973         cfs_waitq_t t_ctl_waitq;
974         struct lu_env *t_env;
975 };
976
977 /**
978  * Request buffer descriptor structure.
979  * This is a structure that contains one posted request buffer for service.
980  * Once data land into a buffer, event callback creates actual request and
981  * notifies wakes one of the service threads to process new incoming request.
982  * More than one request can fit into the buffer.
983  */
984 struct ptlrpc_request_buffer_desc {
985         /** Link item for rqbds on a service */
986         cfs_list_t             rqbd_list;
987         /** History of requests for this buffer */
988         cfs_list_t             rqbd_reqs;
989         /** Back pointer to service for which this buffer is registered */
990         struct ptlrpc_service *rqbd_service;
991         /** LNet descriptor */
992         lnet_handle_md_t       rqbd_md_h;
993         int                    rqbd_refcount;
994         /** The buffer itself */
995         char                  *rqbd_buffer;
996         struct ptlrpc_cb_id    rqbd_cbid;
997         /**
998          * This "embedded" request structure is only used for the
999          * last request to fit into the buffer
1000          */
1001         struct ptlrpc_request  rqbd_req;
1002 };
1003
1004 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
1005 typedef void (*svcreq_printfn_t)(void *, struct ptlrpc_request *);
1006 typedef int (*svc_hpreq_handler_t)(struct ptlrpc_request *);
1007
1008 /**
1009  * How many high priority requests to serve before serving one normal
1010  * priority request
1011  */
1012 #define PTLRPC_SVC_HP_RATIO 10
1013
1014 /**
1015  * Definition of PortalRPC service.
1016  * The service is listening on a particular portal (like tcp port)
1017  * and perform actions for a specific server like IO service for OST
1018  * or general metadata service for MDS.
1019  */
1020 struct ptlrpc_service {
1021         cfs_list_t       srv_list;              /* chain thru all services */
1022         int              srv_max_req_size;      /* biggest request to receive */
1023         int              srv_max_reply_size;    /* biggest reply to send */
1024         int              srv_buf_size;          /* size of individual buffers */
1025         int              srv_nbuf_per_group;    /* # buffers to allocate in 1 group */
1026         int              srv_nbufs;             /* total # req buffer descs allocated */
1027         int              srv_threads_min;       /* threads to start at SOW */
1028         int              srv_threads_max;       /* thread upper limit */
1029         int              srv_threads_started;   /* index of last started thread */
1030         int              srv_threads_running;   /* # running threads */
1031         cfs_atomic_t     srv_n_difficult_replies; /* # 'difficult' replies */
1032         int              srv_n_active_reqs;     /* # reqs being served */
1033         int              srv_n_hpreq;           /* # HPreqs being served */
1034         cfs_duration_t   srv_rqbd_timeout;      /* timeout before re-posting reqs, in tick */
1035         int              srv_watchdog_factor;   /* soft watchdog timeout multiplier */
1036         unsigned         srv_cpu_affinity:1;    /* bind threads to CPUs */
1037         unsigned         srv_at_check:1;        /* check early replies */
1038         unsigned         srv_is_stopping:1;     /* under unregister_service */
1039         cfs_time_t       srv_at_checktime;      /* debug */
1040
1041         /** Local portal on which to receive requests */
1042         __u32            srv_req_portal;
1043         /** Portal on the client to send replies to */
1044         __u32            srv_rep_portal;
1045
1046         /** AT stuff */
1047         /** @{ */
1048         struct adaptive_timeout srv_at_estimate;/* estimated rpc service time */
1049         cfs_spinlock_t   srv_at_lock;
1050         struct ptlrpc_at_array  srv_at_array;   /* reqs waiting for replies */
1051         cfs_timer_t      srv_at_timer;      /* early reply timer */
1052         /** @} */
1053
1054         int              srv_n_queued_reqs; /* # reqs in either of the queues below */
1055         int              srv_hpreq_count;   /* # hp requests handled */
1056         int              srv_hpreq_ratio;   /* # hp per lp reqs to handle */
1057         cfs_list_t       srv_req_in_queue;  /* incoming reqs */
1058         cfs_list_t       srv_request_queue; /* reqs waiting for service */
1059         cfs_list_t       srv_request_hpq;   /* high priority queue */
1060
1061         cfs_list_t       srv_request_history;  /* request history */
1062         __u64            srv_request_seq;      /* next request sequence # */
1063         __u64            srv_request_max_cull_seq; /* highest seq culled from history */
1064         svcreq_printfn_t srv_request_history_print_fn; /* service-specific print fn */
1065
1066         cfs_list_t       srv_idle_rqbds;    /* request buffers to be reposted */
1067         cfs_list_t       srv_active_rqbds;  /* req buffers receiving */
1068         cfs_list_t       srv_history_rqbds; /* request buffer history */
1069         int              srv_nrqbd_receiving; /* # posted request buffers */
1070         int              srv_n_history_rqbds;  /* # request buffers in history */
1071         int              srv_max_history_rqbds;/* max # request buffers in history */
1072
1073         cfs_atomic_t     srv_outstanding_replies;
1074         cfs_list_t       srv_active_replies;   /* all the active replies */
1075 #ifndef __KERNEL__
1076         cfs_list_t       srv_reply_queue;  /* replies waiting for service */
1077 #endif
1078         cfs_waitq_t      srv_waitq; /* all threads sleep on this. This
1079                                      * wait-queue is signalled when new
1080                                      * incoming request arrives and when
1081                                      * difficult reply has to be handled. */
1082
1083         cfs_list_t       srv_threads;       /* service thread list */
1084         /** Handler function for incoming requests for this service */
1085         svc_handler_t    srv_handler;
1086         svc_hpreq_handler_t  srv_hpreq_handler; /* hp request handler */
1087
1088         char *srv_name; /* only statically allocated strings here; we don't clean them */
1089         char *srv_thread_name; /* only statically allocated strings here; we don't clean them */
1090
1091         cfs_spinlock_t        srv_lock;
1092
1093         /** Root of /proc dir tree for this service */
1094         cfs_proc_dir_entry_t *srv_procroot;
1095         /** Pointer to statistic data for this service */
1096         struct lprocfs_stats *srv_stats;
1097
1098         /** List of free reply_states */
1099         cfs_list_t           srv_free_rs_list;
1100         /** waitq to run, when adding stuff to srv_free_rs_list */
1101         cfs_waitq_t          srv_free_rs_waitq;
1102
1103         /**
1104          * Tags for lu_context associated with this thread, see struct
1105          * lu_context.
1106          */
1107         __u32                srv_ctx_tags;
1108         /**
1109          * if non-NULL called during thread creation (ptlrpc_start_thread())
1110          * to initialize service specific per-thread state.
1111          */
1112         int (*srv_init)(struct ptlrpc_thread *thread);
1113         /**
1114          * if non-NULL called during thread shutdown (ptlrpc_main()) to
1115          * destruct state created by ->srv_init().
1116          */
1117         void (*srv_done)(struct ptlrpc_thread *thread);
1118
1119         //struct ptlrpc_srv_ni srv_interfaces[0];
1120 };
1121
1122 /**
1123  * Declaration of ptlrpcd control structure
1124  */
1125 struct ptlrpcd_ctl {
1126         /**
1127          * Ptlrpc thread control flags (LIOD_START, LIOD_STOP, LIOD_FORCE)
1128          */
1129         unsigned long               pc_flags;
1130         /**
1131          * Thread lock protecting structure fields.
1132          */
1133         cfs_spinlock_t              pc_lock;
1134         /**
1135          * Start completion.
1136          */
1137         cfs_completion_t            pc_starting;
1138         /**
1139          * Stop completion.
1140          */
1141         cfs_completion_t            pc_finishing;
1142         /**
1143          * Thread requests set.
1144          */
1145         struct ptlrpc_request_set  *pc_set;
1146         /**
1147          * Thread name used in cfs_daemonize()
1148          */
1149         char                        pc_name[16];
1150         /**
1151          * Environment for request interpreters to run in.
1152          */
1153         struct lu_env               pc_env;
1154 #ifndef __KERNEL__
1155         /**
1156          * Async rpcs flag to make sure that ptlrpcd_check() is called only
1157          * once.
1158          */
1159         int                         pc_recurred;
1160         /**
1161          * Currently not used.
1162          */
1163         void                       *pc_callback;
1164         /**
1165          * User-space async rpcs callback.
1166          */
1167         void                       *pc_wait_callback;
1168         /**
1169          * User-space check idle rpcs callback.
1170          */
1171         void                       *pc_idle_callback;
1172 #endif
1173 };
1174
1175 /* Bits for pc_flags */
1176 enum ptlrpcd_ctl_flags {
1177         /**
1178          * Ptlrpc thread start flag.
1179          */
1180         LIOD_START       = 1 << 0,
1181         /**
1182          * Ptlrpc thread stop flag.
1183          */
1184         LIOD_STOP        = 1 << 1,
1185         /**
1186          * Ptlrpc thread force flag (only stop force so far).
1187          * This will cause aborting any inflight rpcs handled
1188          * by thread if LIOD_STOP is specified.
1189          */
1190         LIOD_FORCE       = 1 << 2,
1191         /**
1192          * This is a recovery ptlrpc thread.
1193          */
1194         LIOD_RECOVERY    = 1 << 3
1195 };
1196
1197 /* ptlrpc/events.c */
1198 extern lnet_handle_eq_t ptlrpc_eq_h;
1199 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
1200                                lnet_process_id_t *peer, lnet_nid_t *self);
1201 /**
1202  * These callbacks are invoked by LNet when something happened to
1203  * underlying buffer
1204  * @{
1205  */
1206 extern void request_out_callback (lnet_event_t *ev);
1207 extern void reply_in_callback(lnet_event_t *ev);
1208 extern void client_bulk_callback (lnet_event_t *ev);
1209 extern void request_in_callback(lnet_event_t *ev);
1210 extern void reply_out_callback(lnet_event_t *ev);
1211 extern void server_bulk_callback (lnet_event_t *ev);
1212 /** @} */
1213
1214 /* ptlrpc/connection.c */
1215 struct ptlrpc_connection *ptlrpc_connection_get(lnet_process_id_t peer,
1216                                                 lnet_nid_t self,
1217                                                 struct obd_uuid *uuid);
1218 int ptlrpc_connection_put(struct ptlrpc_connection *c);
1219 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
1220 int ptlrpc_connection_init(void);
1221 void ptlrpc_connection_fini(void);
1222 extern lnet_pid_t ptl_get_pid(void);
1223
1224 /* ptlrpc/niobuf.c */
1225 /**
1226  * Actual interfacing with LNet to put/get/register/unregister stuff
1227  * @{
1228  */
1229 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
1230 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
1231 int ptlrpc_register_bulk(struct ptlrpc_request *req);
1232 int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async);
1233
1234 static inline int ptlrpc_server_bulk_active(struct ptlrpc_bulk_desc *desc)
1235 {
1236         int rc;
1237
1238         LASSERT(desc != NULL);
1239
1240         cfs_spin_lock(&desc->bd_lock);
1241         rc = desc->bd_network_rw;
1242         cfs_spin_unlock(&desc->bd_lock);
1243         return rc;
1244 }
1245
1246 static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req)
1247 {
1248         struct ptlrpc_bulk_desc *desc = req->rq_bulk;
1249         int                      rc;
1250
1251         LASSERT(req != NULL);
1252
1253         if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) &&
1254             req->rq_bulk_deadline > cfs_time_current_sec())
1255                 return 1;
1256
1257         if (!desc)
1258                 return 0;
1259
1260         cfs_spin_lock(&desc->bd_lock);
1261         rc = desc->bd_network_rw;
1262         cfs_spin_unlock(&desc->bd_lock);
1263         return rc;
1264 }
1265
1266 #define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
1267 #define PTLRPC_REPLY_EARLY           0x02
1268 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
1269 int ptlrpc_reply(struct ptlrpc_request *req);
1270 int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
1271 int ptlrpc_error(struct ptlrpc_request *req);
1272 void ptlrpc_resend_req(struct ptlrpc_request *request);
1273 int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
1274 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
1275 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
1276 /** @} */
1277
1278 /* ptlrpc/client.c */
1279 /**
1280  * Client-side portals API. Everything to send requests, receive replies,
1281  * request queues, request management, etc.
1282  * @{
1283  */
1284 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
1285                         struct ptlrpc_client *);
1286 void ptlrpc_cleanup_client(struct obd_import *imp);
1287 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
1288
1289 int ptlrpc_queue_wait(struct ptlrpc_request *req);
1290 int ptlrpc_replay_req(struct ptlrpc_request *req);
1291 int ptlrpc_unregister_reply(struct ptlrpc_request *req, int async);
1292 void ptlrpc_restart_req(struct ptlrpc_request *req);
1293 void ptlrpc_abort_inflight(struct obd_import *imp);
1294 void ptlrpc_cleanup_imp(struct obd_import *imp);
1295 void ptlrpc_abort_set(struct ptlrpc_request_set *set);
1296
1297 struct ptlrpc_request_set *ptlrpc_prep_set(void);
1298 int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
1299                       set_interpreter_func fn, void *data);
1300 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
1301 int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set);
1302 int ptlrpc_set_wait(struct ptlrpc_request_set *);
1303 int ptlrpc_expired_set(void *data);
1304 void ptlrpc_interrupted_set(void *data);
1305 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
1306 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
1307 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
1308 int ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
1309                            struct ptlrpc_request *req);
1310
1311 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
1312 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
1313
1314 struct ptlrpc_request_pool *
1315 ptlrpc_init_rq_pool(int, int,
1316                     void (*populate_pool)(struct ptlrpc_request_pool *, int));
1317
1318 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
1319 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
1320                                             const struct req_format *format);
1321 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
1322                                             struct ptlrpc_request_pool *,
1323                                             const struct req_format *format);
1324 void ptlrpc_request_free(struct ptlrpc_request *request);
1325 int ptlrpc_request_pack(struct ptlrpc_request *request,
1326                         __u32 version, int opcode);
1327 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
1328                                                 const struct req_format *format,
1329                                                 __u32 version, int opcode);
1330 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
1331                              __u32 version, int opcode, char **bufs,
1332                              struct ptlrpc_cli_ctx *ctx);
1333 struct ptlrpc_request *ptlrpc_prep_fakereq(struct obd_import *imp,
1334                                            unsigned int timeout,
1335                                            ptlrpc_interpterer_t interpreter);
1336 void ptlrpc_fakereq_finished(struct ptlrpc_request *req);
1337
1338 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
1339                                        int opcode, int count, __u32 *lengths,
1340                                        char **bufs);
1341 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
1342                                              __u32 version, int opcode,
1343                                             int count, __u32 *lengths, char **bufs,
1344                                             struct ptlrpc_request_pool *pool);
1345 void ptlrpc_req_finished(struct ptlrpc_request *request);
1346 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
1347 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
1348 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
1349                                                int npages, int type, int portal);
1350 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
1351                                               int npages, int type, int portal);
1352 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
1353 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
1354                            cfs_page_t *page, int pageoffset, int len);
1355 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
1356                                       struct obd_import *imp);
1357 __u64 ptlrpc_next_xid(void);
1358 __u64 ptlrpc_sample_next_xid(void);
1359 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
1360
1361 /** @} */
1362
1363 struct ptlrpc_service_conf {
1364         int psc_nbufs;
1365         int psc_bufsize;
1366         int psc_max_req_size;
1367         int psc_max_reply_size;
1368         int psc_req_portal;
1369         int psc_rep_portal;
1370         int psc_watchdog_factor;
1371         int psc_min_threads;
1372         int psc_max_threads;
1373         __u32 psc_ctx_tags;
1374 };
1375
1376 /* ptlrpc/service.c */
1377 /**
1378  * Server-side services API. Register/unregister service, request state
1379  * management, service thread management
1380  *
1381  * @{
1382  */
1383 void ptlrpc_save_lock (struct ptlrpc_request *req,
1384                        struct lustre_handle *lock, int mode, int no_ack);
1385 void ptlrpc_commit_replies(struct obd_export *exp);
1386 void ptlrpc_dispatch_difficult_reply (struct ptlrpc_reply_state *rs);
1387 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
1388 struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
1389                                             svc_handler_t h, char *name,
1390                                             struct proc_dir_entry *proc_entry,
1391                                             svcreq_printfn_t prntfn,
1392                                             char *threadname);
1393
1394 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
1395                                        int max_reply_size,
1396                                        int req_portal, int rep_portal,
1397                                        int watchdog_factor,
1398                                        svc_handler_t, char *name,
1399                                        cfs_proc_dir_entry_t *proc_entry,
1400                                        svcreq_printfn_t,
1401                                        int min_threads, int max_threads,
1402                                        char *threadname, __u32 ctx_tags,
1403                                        svc_hpreq_handler_t);
1404 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
1405
1406 int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc);
1407 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc);
1408 int ptlrpc_unregister_service(struct ptlrpc_service *service);
1409 int liblustre_check_services (void *arg);
1410 void ptlrpc_daemonize(char *name);
1411 int ptlrpc_service_health_check(struct ptlrpc_service *);
1412 void ptlrpc_hpreq_reorder(struct ptlrpc_request *req);
1413 void ptlrpc_server_active_request_inc(struct ptlrpc_request *req);
1414 void ptlrpc_server_active_request_dec(struct ptlrpc_request *req);
1415 void ptlrpc_server_drop_request(struct ptlrpc_request *req);
1416
1417 #ifdef __KERNEL__
1418 int ptlrpc_hr_init(void);
1419 void ptlrpc_hr_fini(void);
1420 #else
1421 # define ptlrpc_hr_init() (0)
1422 # define ptlrpc_hr_fini() do {} while(0)
1423 #endif
1424
1425 struct ptlrpc_svc_data {
1426         char *name;
1427         struct ptlrpc_service *svc;
1428         struct ptlrpc_thread *thread;
1429         struct obd_device *dev;
1430 };
1431 /** @} */
1432
1433 /* ptlrpc/import.c */
1434 /**
1435  * Import API
1436  * @{
1437  */
1438 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
1439 int ptlrpc_init_import(struct obd_import *imp);
1440 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
1441 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
1442
1443 /* ptlrpc/pack_generic.c */
1444 int ptlrpc_reconnect_import(struct obd_import *imp);
1445 /** @} */
1446
1447 /**
1448  * ptlrpc msg buffer and swab interface 
1449  *
1450  * @{
1451  */
1452 int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
1453                          int index);
1454 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
1455                                 int index);
1456 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len);
1457 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len);
1458
1459 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
1460 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
1461                         char **bufs);
1462 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
1463                         __u32 *lens, char **bufs);
1464 int lustre_pack_reply(struct ptlrpc_request *, int count, __u32 *lens,
1465                       char **bufs);
1466 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
1467                          __u32 *lens, char **bufs, int flags);
1468 #define LPRFL_EARLY_REPLY 1
1469 int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens,
1470                             char **bufs, int flags);
1471 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
1472                       unsigned int newlen, int move_data);
1473 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
1474 int __lustre_unpack_msg(struct lustre_msg *m, int len);
1475 int lustre_msg_hdr_size(__u32 magic, int count);
1476 int lustre_msg_size(__u32 magic, int count, __u32 *lengths);
1477 int lustre_msg_size_v2(int count, __u32 *lengths);
1478 int lustre_packed_msg_size(struct lustre_msg *msg);
1479 int lustre_msg_early_size(void);
1480 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
1481 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
1482 int lustre_msg_buflen(struct lustre_msg *m, int n);
1483 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
1484 int lustre_msg_bufcount(struct lustre_msg *m);
1485 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
1486 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
1487 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
1488 __u32 lustre_msg_get_flags(struct lustre_msg *msg);
1489 void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
1490 void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
1491 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
1492 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
1493 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
1494 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
1495 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
1496 __u32 lustre_msg_get_type(struct lustre_msg *msg);
1497 __u32 lustre_msg_get_version(struct lustre_msg *msg);
1498 void lustre_msg_add_version(struct lustre_msg *msg, int version);
1499 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
1500 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
1501 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
1502 __u64 *lustre_msg_get_versions(struct lustre_msg *msg);
1503 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
1504 __u64 lustre_msg_get_slv(struct lustre_msg *msg);
1505 __u32 lustre_msg_get_limit(struct lustre_msg *msg);
1506 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
1507 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
1508 int lustre_msg_get_status(struct lustre_msg *msg);
1509 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
1510 int lustre_msg_is_v1(struct lustre_msg *msg);
1511 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
1512 __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
1513 __u32 lustre_msg_get_service_time(struct lustre_msg *msg);
1514 __u32 lustre_msg_get_cksum(struct lustre_msg *msg);
1515 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 0, 0)
1516 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg, int compat18);
1517 #else
1518 # warning "remove checksum compatibility support for b1_8"
1519 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
1520 #endif
1521 void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
1522 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
1523 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
1524 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
1525 void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed);
1526 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions);
1527 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
1528 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
1529 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
1530 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *sizes);
1531 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
1532 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
1533 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
1534 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
1535
1536 static inline void
1537 lustre_shrink_reply(struct ptlrpc_request *req, int segment,
1538                     unsigned int newlen, int move_data)
1539 {
1540         LASSERT(req->rq_reply_state);
1541         LASSERT(req->rq_repmsg);
1542         req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
1543                                            newlen, move_data);
1544 }
1545 /** @} */
1546
1547 /** Change request phase of \a req to \a new_phase */
1548 static inline void
1549 ptlrpc_rqphase_move(struct ptlrpc_request *req, enum rq_phase new_phase)
1550 {
1551         if (req->rq_phase == new_phase)
1552                 return;
1553
1554         if (new_phase == RQ_PHASE_UNREGISTERING) {
1555                 req->rq_next_phase = req->rq_phase;
1556                 if (req->rq_import)
1557                         cfs_atomic_inc(&req->rq_import->imp_unregistering);
1558         }
1559
1560         if (req->rq_phase == RQ_PHASE_UNREGISTERING) {
1561                 if (req->rq_import)
1562                         cfs_atomic_dec(&req->rq_import->imp_unregistering);
1563         }
1564
1565         DEBUG_REQ(D_INFO, req, "move req \"%s\" -> \"%s\"",
1566                   ptlrpc_rqphase2str(req), ptlrpc_phase2str(new_phase));
1567
1568         req->rq_phase = new_phase;
1569 }
1570
1571 /**
1572  * Returns true if request \a req got early reply and hard deadline is not met 
1573  */
1574 static inline int
1575 ptlrpc_client_early(struct ptlrpc_request *req)
1576 {
1577         if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1578             req->rq_reply_deadline > cfs_time_current_sec())
1579                 return 0;
1580         return req->rq_early;
1581 }
1582
1583 /**
1584  * Returns true if we got real reply from server for this request
1585  */
1586 static inline int
1587 ptlrpc_client_replied(struct ptlrpc_request *req)
1588 {
1589         if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1590             req->rq_reply_deadline > cfs_time_current_sec())
1591                 return 0;
1592         return req->rq_replied;
1593 }
1594
1595 /** Returns true if request \a req is in process of receiving server reply */
1596 static inline int
1597 ptlrpc_client_recv(struct ptlrpc_request *req)
1598 {
1599         if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1600             req->rq_reply_deadline > cfs_time_current_sec())
1601                 return 1;
1602         return req->rq_receiving_reply;
1603 }
1604
1605 static inline int
1606 ptlrpc_client_recv_or_unlink(struct ptlrpc_request *req)
1607 {
1608         int rc;
1609
1610         cfs_spin_lock(&req->rq_lock);
1611         if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1612             req->rq_reply_deadline > cfs_time_current_sec()) {
1613                 cfs_spin_unlock(&req->rq_lock);
1614                 return 1;
1615         }
1616         rc = req->rq_receiving_reply || req->rq_must_unlink;
1617         cfs_spin_unlock(&req->rq_lock);
1618         return rc;
1619 }
1620
1621 static inline void
1622 ptlrpc_client_wake_req(struct ptlrpc_request *req)
1623 {
1624         if (req->rq_set == NULL)
1625                 cfs_waitq_signal(&req->rq_reply_waitq);
1626         else
1627                 cfs_waitq_signal(&req->rq_set->set_waitq);
1628 }
1629
1630 static inline void
1631 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
1632 {
1633         LASSERT(cfs_atomic_read(&rs->rs_refcount) > 0);
1634         cfs_atomic_inc(&rs->rs_refcount);
1635 }
1636
1637 static inline void
1638 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
1639 {
1640         LASSERT(cfs_atomic_read(&rs->rs_refcount) > 0);
1641         if (cfs_atomic_dec_and_test(&rs->rs_refcount))
1642                 lustre_free_reply_state(rs);
1643 }
1644
1645 /* Should only be called once per req */
1646 static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
1647 {
1648         if (req->rq_reply_state == NULL)
1649                 return; /* shouldn't occur */
1650         ptlrpc_rs_decref(req->rq_reply_state);
1651         req->rq_reply_state = NULL;
1652         req->rq_repmsg = NULL;
1653 }
1654
1655 static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
1656 {
1657         return lustre_msg_get_magic(req->rq_reqmsg);
1658 }
1659
1660 static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
1661 {
1662         switch (req->rq_reqmsg->lm_magic) {
1663         case LUSTRE_MSG_MAGIC_V2:
1664                 return req->rq_reqmsg->lm_repsize;
1665         default:
1666                 LASSERTF(0, "incorrect message magic: %08x\n",
1667                          req->rq_reqmsg->lm_magic);
1668                 return -EFAULT;
1669         }
1670 }
1671
1672 static inline int ptlrpc_send_limit_expired(struct ptlrpc_request *req)
1673 {
1674         if (req->rq_delay_limit != 0 &&
1675             cfs_time_before(cfs_time_add(req->rq_queued_time,
1676                                          cfs_time_seconds(req->rq_delay_limit)),
1677                             cfs_time_current())) {
1678                 return 1;
1679         }
1680         return 0;
1681 }
1682
1683 static inline int ptlrpc_no_resend(struct ptlrpc_request *req)
1684 {
1685         if (!req->rq_no_resend && ptlrpc_send_limit_expired(req)) {
1686                 cfs_spin_lock(&req->rq_lock);
1687                 req->rq_no_resend = 1;
1688                 cfs_spin_unlock(&req->rq_lock);
1689         }
1690         return req->rq_no_resend;
1691 }
1692
1693 /* ldlm/ldlm_lib.c */
1694 /**
1695  * Target client logic
1696  * @{
1697  */
1698 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
1699 int client_obd_cleanup(struct obd_device *obddev);
1700 int client_connect_import(const struct lu_env *env,
1701                           struct obd_export **exp, struct obd_device *obd,
1702                           struct obd_uuid *cluuid, struct obd_connect_data *,
1703                           void *localdata);
1704 int client_disconnect_export(struct obd_export *exp);
1705 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
1706                            int priority);
1707 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
1708 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
1709 void client_destroy_import(struct obd_import *imp);
1710 /** @} */
1711
1712 int server_disconnect_export(struct obd_export *exp);
1713
1714 /* ptlrpc/pinger.c */
1715 /**
1716  * Pinger API (client side only)
1717  * @{
1718  */
1719 enum timeout_event {
1720         TIMEOUT_GRANT = 1
1721 };
1722 struct timeout_item;
1723 typedef int (*timeout_cb_t)(struct timeout_item *, void *);
1724 int ptlrpc_pinger_add_import(struct obd_import *imp);
1725 int ptlrpc_pinger_del_import(struct obd_import *imp);
1726 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
1727                               timeout_cb_t cb, void *data,
1728                               cfs_list_t *obd_list);
1729 int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
1730                               enum timeout_event event);
1731 struct ptlrpc_request * ptlrpc_prep_ping(struct obd_import *imp);
1732 int ptlrpc_obd_ping(struct obd_device *obd);
1733 cfs_time_t ptlrpc_suspend_wakeup_time(void);
1734 #ifdef __KERNEL__
1735 void ping_evictor_start(void);
1736 void ping_evictor_stop(void);
1737 #else
1738 #define ping_evictor_start()    do {} while (0)
1739 #define ping_evictor_stop()     do {} while (0)
1740 #endif
1741 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req);
1742 /** @} */
1743
1744 /* ptlrpc/ptlrpcd.c */
1745
1746 /**
1747  * Ptlrpcd scope is a set of two threads: ptlrpcd-foo and ptlrpcd-foo-rcv,
1748  * these threads are used to asynchronously send requests queued with
1749  * ptlrpcd_add_req(req, PCSOPE_FOO), and to handle completion call-backs for
1750  * such requests. Multiple scopes are needed to avoid dead-locks.
1751  */
1752 enum ptlrpcd_scope {
1753         /** Scope of bulk read-write rpcs. */
1754         PSCOPE_BRW,
1755         /** Everything else. */
1756         PSCOPE_OTHER,
1757         PSCOPE_NR
1758 };
1759
1760 int ptlrpcd_start(const char *name, struct ptlrpcd_ctl *pc);
1761 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force);
1762 void ptlrpcd_wake(struct ptlrpc_request *req);
1763 int ptlrpcd_add_req(struct ptlrpc_request *req, enum ptlrpcd_scope scope);
1764 void ptlrpcd_add_rqset(struct ptlrpc_request_set *set);
1765 int ptlrpcd_addref(void);
1766 void ptlrpcd_decref(void);
1767
1768 /* ptlrpc/lproc_ptlrpc.c */
1769 /**
1770  * procfs output related functions
1771  * @{
1772  */
1773 const char* ll_opcode2str(__u32 opcode);
1774 #ifdef LPROCFS
1775 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
1776 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
1777 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes);
1778 #else
1779 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
1780 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
1781 static inline void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes) {}
1782 #endif
1783 /** @} */
1784
1785 /* ptlrpc/llog_server.c */
1786 int llog_origin_handle_create(struct ptlrpc_request *req);
1787 int llog_origin_handle_destroy(struct ptlrpc_request *req);
1788 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
1789 int llog_origin_handle_next_block(struct ptlrpc_request *req);
1790 int llog_origin_handle_read_header(struct ptlrpc_request *req);
1791 int llog_origin_handle_close(struct ptlrpc_request *req);
1792 int llog_origin_handle_cancel(struct ptlrpc_request *req);
1793 int llog_catinfo(struct ptlrpc_request *req);
1794
1795 /* ptlrpc/llog_client.c */
1796 extern struct llog_operations llog_client_ops;
1797
1798 /** @} net */
1799
1800 #endif
1801 /** @} PtlRPC */