GNU Linux-libre 4.14.332-gnu1
[releases.git] / drivers / staging / lustre / lustre / include / lustre_net.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2010, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 /** \defgroup PtlRPC Portal RPC and networking module.
33  *
34  * PortalRPC is the layer used by rest of lustre code to achieve network
35  * communications: establish connections with corresponding export and import
36  * states, listen for a service, send and receive RPCs.
37  * PortalRPC also includes base recovery framework: packet resending and
38  * replaying, reconnections, pinger.
39  *
40  * PortalRPC utilizes LNet as its transport layer.
41  *
42  * @{
43  */
44
45 #ifndef _LUSTRE_NET_H
46 #define _LUSTRE_NET_H
47
48 /** \defgroup net net
49  *
50  * @{
51  */
52
53 #include <linux/uio.h>
54 #include <linux/libcfs/libcfs.h>
55 #include <uapi/linux/lnet/nidstr.h>
56 #include <linux/lnet/api.h>
57 #include <uapi/linux/lustre/lustre_idl.h>
58 #include <lustre_errno.h>
59 #include <lustre_ha.h>
60 #include <lustre_sec.h>
61 #include <lustre_import.h>
62 #include <lprocfs_status.h>
63 #include <lu_object.h>
64 #include <lustre_req_layout.h>
65
66 #include <obd_support.h>
67 #include <uapi/linux/lustre/lustre_ver.h>
68
69 /* MD flags we _always_ use */
70 #define PTLRPC_MD_OPTIONS  0
71
72 /**
73  * log2 max # of bulk operations in one request: 2=4MB/RPC, 5=32MB/RPC, ...
74  * In order for the client and server to properly negotiate the maximum
75  * possible transfer size, PTLRPC_BULK_OPS_COUNT must be a power-of-two
76  * value.  The client is free to limit the actual RPC size for any bulk
77  * transfer via cl_max_pages_per_rpc to some non-power-of-two value.
78  * NOTE: This is limited to 16 (=64GB RPCs) by IOOBJ_MAX_BRW_BITS.
79  */
80 #define PTLRPC_BULK_OPS_BITS    4
81 #if PTLRPC_BULK_OPS_BITS > 16
82 #error "More than 65536 BRW RPCs not allowed by IOOBJ_MAX_BRW_BITS."
83 #endif
84 #define PTLRPC_BULK_OPS_COUNT   (1U << PTLRPC_BULK_OPS_BITS)
85 /**
86  * PTLRPC_BULK_OPS_MASK is for the convenience of the client only, and
87  * should not be used on the server at all.  Otherwise, it imposes a
88  * protocol limitation on the maximum RPC size that can be used by any
89  * RPC sent to that server in the future.  Instead, the server should
90  * use the negotiated per-client ocd_brw_size to determine the bulk
91  * RPC count.
92  */
93 #define PTLRPC_BULK_OPS_MASK    (~((__u64)PTLRPC_BULK_OPS_COUNT - 1))
94
95 /**
96  * Define maxima for bulk I/O.
97  *
98  * A single PTLRPC BRW request is sent via up to PTLRPC_BULK_OPS_COUNT
99  * of LNET_MTU sized RDMA transfers.  Clients and servers negotiate the
100  * currently supported maximum between peers at connect via ocd_brw_size.
101  */
102 #define PTLRPC_MAX_BRW_BITS     (LNET_MTU_BITS + PTLRPC_BULK_OPS_BITS)
103 #define PTLRPC_MAX_BRW_SIZE     (1 << PTLRPC_MAX_BRW_BITS)
104 #define PTLRPC_MAX_BRW_PAGES    (PTLRPC_MAX_BRW_SIZE >> PAGE_SHIFT)
105
106 #define ONE_MB_BRW_SIZE         (1 << LNET_MTU_BITS)
107 #define MD_MAX_BRW_SIZE         (1 << LNET_MTU_BITS)
108 #define MD_MAX_BRW_PAGES        (MD_MAX_BRW_SIZE >> PAGE_SHIFT)
109 #define DT_MAX_BRW_SIZE         PTLRPC_MAX_BRW_SIZE
110 #define DT_MAX_BRW_PAGES        (DT_MAX_BRW_SIZE >> PAGE_SHIFT)
111 #define OFD_MAX_BRW_SIZE        (1 << LNET_MTU_BITS)
112
113 /* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
114 # if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
115 #  error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
116 # endif
117 # if (PTLRPC_MAX_BRW_SIZE != (PTLRPC_MAX_BRW_PAGES * PAGE_SIZE))
118 #  error "PTLRPC_MAX_BRW_SIZE isn't PTLRPC_MAX_BRW_PAGES * PAGE_SIZE"
119 # endif
120 # if (PTLRPC_MAX_BRW_SIZE > LNET_MTU * PTLRPC_BULK_OPS_COUNT)
121 #  error "PTLRPC_MAX_BRW_SIZE too big"
122 # endif
123 # if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV * PTLRPC_BULK_OPS_COUNT)
124 #  error "PTLRPC_MAX_BRW_PAGES too big"
125 # endif
126
127 #define PTLRPC_NTHRS_INIT       2
128
129 /**
130  * Buffer Constants
131  *
132  * Constants determine how memory is used to buffer incoming service requests.
133  *
134  * ?_NBUFS            # buffers to allocate when growing the pool
135  * ?_BUFSIZE        # bytes in a single request buffer
136  * ?_MAXREQSIZE  # maximum request service will receive
137  *
138  * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
139  * of ?_NBUFS is added to the pool.
140  *
141  * Messages larger than ?_MAXREQSIZE are dropped.  Request buffers are
142  * considered full when less than ?_MAXREQSIZE is left in them.
143  */
144 /**
145  * Thread Constants
146  *
147  * Constants determine how threads are created for ptlrpc service.
148  *
149  * ?_NTHRS_INIT         # threads to create for each service partition on
150  *                        initializing. If it's non-affinity service and
151  *                        there is only one partition, it's the overall #
152  *                        threads for the service while initializing.
153  * ?_NTHRS_BASE         # threads should be created at least for each
154  *                        ptlrpc partition to keep the service healthy.
155  *                        It's the low-water mark of threads upper-limit
156  *                        for each partition.
157  * ?_THR_FACTOR  # threads can be added on threads upper-limit for
158  *                        each CPU core. This factor is only for reference,
159  *                        we might decrease value of factor if number of cores
160  *                        per CPT is above a limit.
161  * ?_NTHRS_MAX          # overall threads can be created for a service,
162  *                        it's a soft limit because if service is running
163  *                        on machine with hundreds of cores and tens of
164  *                        CPU partitions, we need to guarantee each partition
165  *                        has ?_NTHRS_BASE threads, which means total threads
166  *                        will be ?_NTHRS_BASE * number_of_cpts which can
167  *                        exceed ?_NTHRS_MAX.
168  *
169  * Examples
170  *
171  * #define MDS_NTHRS_INIT       2
172  * #define MDS_NTHRS_BASE       64
173  * #define MDS_NTHRS_FACTOR     8
174  * #define MDS_NTHRS_MAX        1024
175  *
176  * Example 1):
177  * ---------------------------------------------------------------------
178  * Server(A) has 16 cores, user configured it to 4 partitions so each
179  * partition has 4 cores, then actual number of service threads on each
180  * partition is:
181  *     MDS_NTHRS_BASE(64) + cores(4) * MDS_NTHRS_FACTOR(8) = 96
182  *
183  * Total number of threads for the service is:
184  *     96 * partitions(4) = 384
185  *
186  * Example 2):
187  * ---------------------------------------------------------------------
188  * Server(B) has 32 cores, user configured it to 4 partitions so each
189  * partition has 8 cores, then actual number of service threads on each
190  * partition is:
191  *     MDS_NTHRS_BASE(64) + cores(8) * MDS_NTHRS_FACTOR(8) = 128
192  *
193  * Total number of threads for the service is:
194  *     128 * partitions(4) = 512
195  *
196  * Example 3):
197  * ---------------------------------------------------------------------
198  * Server(B) has 96 cores, user configured it to 8 partitions so each
199  * partition has 12 cores, then actual number of service threads on each
200  * partition is:
201  *     MDS_NTHRS_BASE(64) + cores(12) * MDS_NTHRS_FACTOR(8) = 160
202  *
203  * Total number of threads for the service is:
204  *     160 * partitions(8) = 1280
205  *
206  * However, it's above the soft limit MDS_NTHRS_MAX, so we choose this number
207  * as upper limit of threads number for each partition:
208  *     MDS_NTHRS_MAX(1024) / partitions(8) = 128
209  *
210  * Example 4):
211  * ---------------------------------------------------------------------
212  * Server(C) have a thousand of cores and user configured it to 32 partitions
213  *     MDS_NTHRS_BASE(64) * 32 = 2048
214  *
215  * which is already above soft limit MDS_NTHRS_MAX(1024), but we still need
216  * to guarantee that each partition has at least MDS_NTHRS_BASE(64) threads
217  * to keep service healthy, so total number of threads will just be 2048.
218  *
219  * NB: we don't suggest to choose server with that many cores because backend
220  *     filesystem itself, buffer cache, or underlying network stack might
221  *     have some SMP scalability issues at that large scale.
222  *
223  *     If user already has a fat machine with hundreds or thousands of cores,
224  *     there are two choices for configuration:
225  *     a) create CPU table from subset of all CPUs and run Lustre on
226  *      top of this subset
227  *     b) bind service threads on a few partitions, see modparameters of
228  *      MDS and OSS for details
229 *
230  * NB: these calculations (and examples below) are simplified to help
231  *     understanding, the real implementation is a little more complex,
232  *     please see ptlrpc_server_nthreads_check() for details.
233  *
234  */
235
236  /*
237   * LDLM threads constants:
238   *
239   * Given 8 as factor and 24 as base threads number
240   *
241   * example 1)
242   * On 4-core machine we will have 24 + 8 * 4 = 56 threads.
243   *
244   * example 2)
245   * On 8-core machine with 2 partitions we will have 24 + 4 * 8 = 56
246   * threads for each partition and total threads number will be 112.
247   *
248   * example 3)
249   * On 64-core machine with 8 partitions we will need LDLM_NTHRS_BASE(24)
250   * threads for each partition to keep service healthy, so total threads
251   * number should be 24 * 8 = 192.
252   *
253   * So with these constants, threads number will be at the similar level
254   * of old versions, unless target machine has over a hundred cores
255   */
256 #define LDLM_THR_FACTOR         8
257 #define LDLM_NTHRS_INIT         PTLRPC_NTHRS_INIT
258 #define LDLM_NTHRS_BASE         24
259 #define LDLM_NTHRS_MAX          (num_online_cpus() == 1 ? 64 : 128)
260
261 #define LDLM_BL_THREADS   LDLM_NTHRS_AUTO_INIT
262 #define LDLM_CLIENT_NBUFS 1
263 #define LDLM_SERVER_NBUFS 64
264 #define LDLM_BUFSIZE      (8 * 1024)
265 #define LDLM_MAXREQSIZE   (5 * 1024)
266 #define LDLM_MAXREPSIZE   (1024)
267
268 #define MDS_MAXREQSIZE          (5 * 1024)      /* >= 4736 */
269
270 /**
271  * FIEMAP request can be 4K+ for now
272  */
273 #define OST_MAXREQSIZE          (16 * 1024)
274
275 /* Macro to hide a typecast. */
276 #define ptlrpc_req_async_args(req) ((void *)&req->rq_async_args)
277
278 struct ptlrpc_replay_async_args {
279         int             praa_old_state;
280         int             praa_old_status;
281 };
282
283 /**
284  * Structure to single define portal connection.
285  */
286 struct ptlrpc_connection {
287         /** linkage for connections hash table */
288         struct hlist_node       c_hash;
289         /** Our own lnet nid for this connection */
290         lnet_nid_t            c_self;
291         /** Remote side nid for this connection */
292         struct lnet_process_id  c_peer;
293         /** UUID of the other side */
294         struct obd_uuid  c_remote_uuid;
295         /** reference counter for this connection */
296         atomic_t            c_refcount;
297 };
298
299 /** Client definition for PortalRPC */
300 struct ptlrpc_client {
301         /** What lnet portal does this client send messages to by default */
302         __u32              cli_request_portal;
303         /** What portal do we expect replies on */
304         __u32              cli_reply_portal;
305         /** Name of the client */
306         char               *cli_name;
307 };
308
309 /** state flags of requests */
310 /* XXX only ones left are those used by the bulk descs as well! */
311 #define PTL_RPC_FL_INTR      (1 << 0)  /* reply wait was interrupted by user */
312 #define PTL_RPC_FL_TIMEOUT   (1 << 7)  /* request timed out waiting for reply */
313
314 #define REQ_MAX_ACK_LOCKS 8
315
316 union ptlrpc_async_args {
317         /**
318          * Scratchpad for passing args to completion interpreter. Users
319          * cast to the struct of their choosing, and BUILD_BUG_ON oversized
320          * arguments.  For _tons_ of context, kmalloc a struct and store
321          * a pointer to it here.  The pointer_arg ensures this struct is at
322          * least big enough for that.
323          */
324         void      *pointer_arg[11];
325         __u64      space[7];
326 };
327
328 struct ptlrpc_request_set;
329 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
330 typedef int (*set_producer_func)(struct ptlrpc_request_set *, void *);
331
332 /**
333  * Definition of request set structure.
334  * Request set is a list of requests (not necessary to the same target) that
335  * once populated with RPCs could be sent in parallel.
336  * There are two kinds of request sets. General purpose and with dedicated
337  * serving thread. Example of the latter is ptlrpcd set.
338  * For general purpose sets once request set started sending it is impossible
339  * to add new requests to such set.
340  * Provides a way to call "completion callbacks" when all requests in the set
341  * returned.
342  */
343 struct ptlrpc_request_set {
344         atomic_t          set_refcount;
345         /** number of in queue requests */
346         atomic_t          set_new_count;
347         /** number of uncompleted requests */
348         atomic_t          set_remaining;
349         /** wait queue to wait on for request events */
350         wait_queue_head_t          set_waitq;
351         wait_queue_head_t         *set_wakeup_ptr;
352         /** List of requests in the set */
353         struct list_head            set_requests;
354         /**
355          * List of completion callbacks to be called when the set is completed
356          * This is only used if \a set_interpret is NULL.
357          * Links struct ptlrpc_set_cbdata.
358          */
359         struct list_head            set_cblist;
360         /** Completion callback, if only one. */
361         set_interpreter_func  set_interpret;
362         /** opaq argument passed to completion \a set_interpret callback. */
363         void             *set_arg;
364         /**
365          * Lock for \a set_new_requests manipulations
366          * locked so that any old caller can communicate requests to
367          * the set holder who can then fold them into the lock-free set
368          */
369         spinlock_t              set_new_req_lock;
370         /** List of new yet unsent requests. Only used with ptlrpcd now. */
371         struct list_head            set_new_requests;
372
373         /** rq_status of requests that have been freed already */
374         int                set_rc;
375         /** Additional fields used by the flow control extension */
376         /** Maximum number of RPCs in flight */
377         int                set_max_inflight;
378         /** Callback function used to generate RPCs */
379         set_producer_func     set_producer;
380         /** opaq argument passed to the producer callback */
381         void             *set_producer_arg;
382 };
383
384 /**
385  * Description of a single ptrlrpc_set callback
386  */
387 struct ptlrpc_set_cbdata {
388         /** List linkage item */
389         struct list_head              psc_item;
390         /** Pointer to interpreting function */
391         set_interpreter_func    psc_interpret;
392         /** Opaq argument to pass to the callback */
393         void               *psc_data;
394 };
395
396 struct ptlrpc_bulk_desc;
397 struct ptlrpc_service_part;
398 struct ptlrpc_service;
399
400 /**
401  * ptlrpc callback & work item stuff
402  */
403 struct ptlrpc_cb_id {
404         void   (*cbid_fn)(struct lnet_event *ev); /* specific callback fn */
405         void    *cbid_arg;                    /* additional arg */
406 };
407
408 /** Maximum number of locks to fit into reply state */
409 #define RS_MAX_LOCKS 8
410 #define RS_DEBUG     0
411
412 /**
413  * Structure to define reply state on the server
414  * Reply state holds various reply message information. Also for "difficult"
415  * replies (rep-ack case) we store the state after sending reply and wait
416  * for the client to acknowledge the reception. In these cases locks could be
417  * added to the state for replay/failover consistency guarantees.
418  */
419 struct ptlrpc_reply_state {
420         /** Callback description */
421         struct ptlrpc_cb_id    rs_cb_id;
422         /** Linkage for list of all reply states in a system */
423         struct list_head             rs_list;
424         /** Linkage for list of all reply states on same export */
425         struct list_head             rs_exp_list;
426         /** Linkage for list of all reply states for same obd */
427         struct list_head             rs_obd_list;
428 #if RS_DEBUG
429         struct list_head             rs_debug_list;
430 #endif
431         /** A spinlock to protect the reply state flags */
432         spinlock_t              rs_lock;
433         /** Reply state flags */
434         unsigned long     rs_difficult:1; /* ACK/commit stuff */
435         unsigned long     rs_no_ack:1;    /* no ACK, even for
436                                            * difficult requests
437                                            */
438         unsigned long     rs_scheduled:1;     /* being handled? */
439         unsigned long     rs_scheduled_ever:1;/* any schedule attempts? */
440         unsigned long     rs_handled:1;  /* been handled yet? */
441         unsigned long     rs_on_net:1;   /* reply_out_callback pending? */
442         unsigned long     rs_prealloc:1; /* rs from prealloc list */
443         unsigned long     rs_committed:1;/* the transaction was committed
444                                           * and the rs was dispatched
445                                           */
446         atomic_t                rs_refcount;    /* number of users */
447         /** Number of locks awaiting client ACK */
448         int                     rs_nlocks;
449
450         /** Size of the state */
451         int                 rs_size;
452         /** opcode */
453         __u32             rs_opc;
454         /** Transaction number */
455         __u64             rs_transno;
456         /** xid */
457         __u64             rs_xid;
458         struct obd_export     *rs_export;
459         struct ptlrpc_service_part *rs_svcpt;
460         /** Lnet metadata handle for the reply */
461         struct lnet_handle_md           rs_md_h;
462
463         /** Context for the service thread */
464         struct ptlrpc_svc_ctx *rs_svc_ctx;
465         /** Reply buffer (actually sent to the client), encoded if needed */
466         struct lustre_msg     *rs_repbuf;       /* wrapper */
467         /** Size of the reply buffer */
468         int                 rs_repbuf_len;   /* wrapper buf length */
469         /** Size of the reply message */
470         int                 rs_repdata_len;  /* wrapper msg length */
471         /**
472          * Actual reply message. Its content is encrypted (if needed) to
473          * produce reply buffer for actual sending. In simple case
474          * of no network encryption we just set \a rs_repbuf to \a rs_msg
475          */
476         struct lustre_msg     *rs_msg;    /* reply message */
477
478         /** Handles of locks awaiting client reply ACK */
479         struct lustre_handle   rs_locks[RS_MAX_LOCKS];
480         /** Lock modes of locks in \a rs_locks */
481         enum ldlm_mode      rs_modes[RS_MAX_LOCKS];
482 };
483
484 struct ptlrpc_thread;
485
486 /** RPC stages */
487 enum rq_phase {
488         RQ_PHASE_NEW        = 0xebc0de00,
489         RQ_PHASE_RPC        = 0xebc0de01,
490         RQ_PHASE_BULK      = 0xebc0de02,
491         RQ_PHASE_INTERPRET      = 0xebc0de03,
492         RQ_PHASE_COMPLETE       = 0xebc0de04,
493         RQ_PHASE_UNREG_RPC      = 0xebc0de05,
494         RQ_PHASE_UNREG_BULK     = 0xebc0de06,
495         RQ_PHASE_UNDEFINED      = 0xebc0de07
496 };
497
498 /** Type of request interpreter call-back */
499 typedef int (*ptlrpc_interpterer_t)(const struct lu_env *env,
500                                     struct ptlrpc_request *req,
501                                     void *arg, int rc);
502
503 /**
504  * Definition of request pool structure.
505  * The pool is used to store empty preallocated requests for the case
506  * when we would actually need to send something without performing
507  * any allocations (to avoid e.g. OOM).
508  */
509 struct ptlrpc_request_pool {
510         /** Locks the list */
511         spinlock_t prp_lock;
512         /** list of ptlrpc_request structs */
513         struct list_head prp_req_list;
514         /** Maximum message size that would fit into a request from this pool */
515         int prp_rq_size;
516         /** Function to allocate more requests for this pool */
517         int (*prp_populate)(struct ptlrpc_request_pool *, int);
518 };
519
520 struct lu_context;
521 struct lu_env;
522
523 struct ldlm_lock;
524
525 #include <lustre_nrs.h>
526
527 /**
528  * Basic request prioritization operations structure.
529  * The whole idea is centered around locks and RPCs that might affect locks.
530  * When a lock is contended we try to give priority to RPCs that might lead
531  * to fastest release of that lock.
532  * Currently only implemented for OSTs only in a way that makes all
533  * IO and truncate RPCs that are coming from a locked region where a lock is
534  * contended a priority over other requests.
535  */
536 struct ptlrpc_hpreq_ops {
537         /**
538          * Check if the lock handle of the given lock is the same as
539          * taken from the request.
540          */
541         int  (*hpreq_lock_match)(struct ptlrpc_request *, struct ldlm_lock *);
542         /**
543          * Check if the request is a high priority one.
544          */
545         int  (*hpreq_check)(struct ptlrpc_request *);
546         /**
547          * Called after the request has been handled.
548          */
549         void (*hpreq_fini)(struct ptlrpc_request *);
550 };
551
552 struct ptlrpc_cli_req {
553         /** For bulk requests on client only: bulk descriptor */
554         struct ptlrpc_bulk_desc         *cr_bulk;
555         /** optional time limit for send attempts */
556         long                             cr_delay_limit;
557         /** time request was first queued */
558         time_t                           cr_queued_time;
559         /** request sent timeval */
560         struct timespec64                cr_sent_tv;
561         /** time for request really sent out */
562         time64_t                         cr_sent_out;
563         /** when req reply unlink must finish. */
564         time64_t                         cr_reply_deadline;
565         /** when req bulk unlink must finish. */
566         time64_t                         cr_bulk_deadline;
567         /** when req unlink must finish. */
568         time64_t                         cr_req_deadline;
569         /** Portal to which this request would be sent */
570         short                            cr_req_ptl;
571         /** Portal where to wait for reply and where reply would be sent */
572         short                            cr_rep_ptl;
573         /** request resending number */
574         unsigned int                     cr_resend_nr;
575         /** What was import generation when this request was sent */
576         int                              cr_imp_gen;
577         enum lustre_imp_state            cr_send_state;
578         /** Per-request waitq introduced by bug 21938 for recovery waiting */
579         wait_queue_head_t                cr_set_waitq;
580         /** Link item for request set lists */
581         struct list_head                 cr_set_chain;
582         /** link to waited ctx */
583         struct list_head                 cr_ctx_chain;
584
585         /** client's half ctx */
586         struct ptlrpc_cli_ctx           *cr_cli_ctx;
587         /** Link back to the request set */
588         struct ptlrpc_request_set       *cr_set;
589         /** outgoing request MD handle */
590         struct lnet_handle_md            cr_req_md_h;
591         /** request-out callback parameter */
592         struct ptlrpc_cb_id              cr_req_cbid;
593         /** incoming reply MD handle */
594         struct lnet_handle_md            cr_reply_md_h;
595         wait_queue_head_t                cr_reply_waitq;
596         /** reply callback parameter */
597         struct ptlrpc_cb_id              cr_reply_cbid;
598         /** Async completion handler, called when reply is received */
599         ptlrpc_interpterer_t             cr_reply_interp;
600         /** Async completion context */
601         union ptlrpc_async_args          cr_async_args;
602         /** Opaq data for replay and commit callbacks. */
603         void                            *cr_cb_data;
604         /** Link to the imp->imp_unreplied_list */
605         struct list_head                 cr_unreplied_list;
606         /**
607          * Commit callback, called when request is committed and about to be
608          * freed.
609          */
610         void (*cr_commit_cb)(struct ptlrpc_request *);
611         /** Replay callback, called after request is replayed at recovery */
612         void (*cr_replay_cb)(struct ptlrpc_request *);
613 };
614
615 /** client request member alias */
616 /* NB: these alias should NOT be used by any new code, instead they should
617  * be removed step by step to avoid potential abuse
618  */
619 #define rq_bulk                 rq_cli.cr_bulk
620 #define rq_delay_limit          rq_cli.cr_delay_limit
621 #define rq_queued_time          rq_cli.cr_queued_time
622 #define rq_sent_tv              rq_cli.cr_sent_tv
623 #define rq_real_sent            rq_cli.cr_sent_out
624 #define rq_reply_deadline       rq_cli.cr_reply_deadline
625 #define rq_bulk_deadline        rq_cli.cr_bulk_deadline
626 #define rq_req_deadline         rq_cli.cr_req_deadline
627 #define rq_nr_resend            rq_cli.cr_resend_nr
628 #define rq_request_portal       rq_cli.cr_req_ptl
629 #define rq_reply_portal         rq_cli.cr_rep_ptl
630 #define rq_import_generation    rq_cli.cr_imp_gen
631 #define rq_send_state           rq_cli.cr_send_state
632 #define rq_set_chain            rq_cli.cr_set_chain
633 #define rq_ctx_chain            rq_cli.cr_ctx_chain
634 #define rq_set                  rq_cli.cr_set
635 #define rq_set_waitq            rq_cli.cr_set_waitq
636 #define rq_cli_ctx              rq_cli.cr_cli_ctx
637 #define rq_req_md_h             rq_cli.cr_req_md_h
638 #define rq_req_cbid             rq_cli.cr_req_cbid
639 #define rq_reply_md_h           rq_cli.cr_reply_md_h
640 #define rq_reply_waitq          rq_cli.cr_reply_waitq
641 #define rq_reply_cbid           rq_cli.cr_reply_cbid
642 #define rq_interpret_reply      rq_cli.cr_reply_interp
643 #define rq_async_args           rq_cli.cr_async_args
644 #define rq_cb_data              rq_cli.cr_cb_data
645 #define rq_unreplied_list       rq_cli.cr_unreplied_list
646 #define rq_commit_cb            rq_cli.cr_commit_cb
647 #define rq_replay_cb            rq_cli.cr_replay_cb
648
649 struct ptlrpc_srv_req {
650         /** initial thread servicing this request */
651         struct ptlrpc_thread            *sr_svc_thread;
652         /**
653          * Server side list of incoming unserved requests sorted by arrival
654          * time.  Traversed from time to time to notice about to expire
655          * requests and sent back "early replies" to clients to let them
656          * know server is alive and well, just very busy to service their
657          * requests in time
658          */
659         struct list_head                sr_timed_list;
660         /** server-side per-export list */
661         struct list_head                sr_exp_list;
662         /** server-side history, used for debuging purposes. */
663         struct list_head                sr_hist_list;
664         /** history sequence # */
665         __u64                           sr_hist_seq;
666         /** the index of service's srv_at_array into which request is linked */
667         time64_t                        sr_at_index;
668         /** authed uid */
669         uid_t                           sr_auth_uid;
670         /** authed uid mapped to */
671         uid_t                           sr_auth_mapped_uid;
672         /** RPC is generated from what part of Lustre */
673         enum lustre_sec_part            sr_sp_from;
674         /** request session context */
675         struct lu_context               sr_ses;
676         /** \addtogroup  nrs
677          * @{
678          */
679         /** stub for NRS request */
680         struct ptlrpc_nrs_request       sr_nrq;
681         /** @} nrs */
682         /** request arrival time */
683         struct timespec64               sr_arrival_time;
684         /** server's half ctx */
685         struct ptlrpc_svc_ctx           *sr_svc_ctx;
686         /** (server side), pointed directly into req buffer */
687         struct ptlrpc_user_desc         *sr_user_desc;
688         /** separated reply state */
689         struct ptlrpc_reply_state       *sr_reply_state;
690         /** server-side hp handlers */
691         struct ptlrpc_hpreq_ops         *sr_ops;
692         /** incoming request buffer */
693         struct ptlrpc_request_buffer_desc *sr_rqbd;
694 };
695
696 /** server request member alias */
697 /* NB: these alias should NOT be used by any new code, instead they should
698  * be removed step by step to avoid potential abuse
699  */
700 #define rq_svc_thread           rq_srv.sr_svc_thread
701 #define rq_timed_list           rq_srv.sr_timed_list
702 #define rq_exp_list             rq_srv.sr_exp_list
703 #define rq_history_list         rq_srv.sr_hist_list
704 #define rq_history_seq          rq_srv.sr_hist_seq
705 #define rq_at_index             rq_srv.sr_at_index
706 #define rq_auth_uid             rq_srv.sr_auth_uid
707 #define rq_auth_mapped_uid      rq_srv.sr_auth_mapped_uid
708 #define rq_sp_from              rq_srv.sr_sp_from
709 #define rq_session              rq_srv.sr_ses
710 #define rq_nrq                  rq_srv.sr_nrq
711 #define rq_arrival_time         rq_srv.sr_arrival_time
712 #define rq_reply_state          rq_srv.sr_reply_state
713 #define rq_svc_ctx              rq_srv.sr_svc_ctx
714 #define rq_user_desc            rq_srv.sr_user_desc
715 #define rq_ops                  rq_srv.sr_ops
716 #define rq_rqbd                 rq_srv.sr_rqbd
717
718 /**
719  * Represents remote procedure call.
720  *
721  * This is a staple structure used by everybody wanting to send a request
722  * in Lustre.
723  */
724 struct ptlrpc_request {
725         /* Request type: one of PTL_RPC_MSG_* */
726         int                              rq_type;
727         /** Result of request processing */
728         int                              rq_status;
729         /**
730          * Linkage item through which this request is included into
731          * sending/delayed lists on client and into rqbd list on server
732          */
733         struct list_head                 rq_list;
734         /** Lock to protect request flags and some other important bits, like
735          * rq_list
736          */
737         spinlock_t rq_lock;
738         /** client-side flags are serialized by rq_lock @{ */
739         unsigned int rq_intr:1, rq_replied:1, rq_err:1,
740                 rq_timedout:1, rq_resend:1, rq_restart:1,
741                 /**
742                  * when ->rq_replay is set, request is kept by the client even
743                  * after server commits corresponding transaction. This is
744                  * used for operations that require sequence of multiple
745                  * requests to be replayed. The only example currently is file
746                  * open/close. When last request in such a sequence is
747                  * committed, ->rq_replay is cleared on all requests in the
748                  * sequence.
749                  */
750                 rq_replay:1,
751                 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
752                 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
753                 rq_early:1,
754                 rq_req_unlinked:1,      /* unlinked request buffer from lnet */
755                 rq_reply_unlinked:1,    /* unlinked reply buffer from lnet */
756                 rq_memalloc:1,      /* req originated from "kswapd" */
757                 rq_committed:1,
758                 rq_reply_truncated:1,
759                 /** whether the "rq_set" is a valid one */
760                 rq_invalid_rqset:1,
761                 rq_generation_set:1,
762                 /** do not resend request on -EINPROGRESS */
763                 rq_no_retry_einprogress:1,
764                 /* allow the req to be sent if the import is in recovery
765                  * status
766                  */
767                 rq_allow_replay:1,
768                 /* bulk request, sent to server, but uncommitted */
769                 rq_unstable:1;
770         /** @} */
771
772         /** server-side flags @{ */
773         unsigned int
774                 rq_hp:1,                /**< high priority RPC */
775                 rq_at_linked:1,         /**< link into service's srv_at_array */
776                 rq_packed_final:1;      /**< packed final reply */
777         /** @} */
778
779         /** one of RQ_PHASE_* */
780         enum rq_phase                   rq_phase;
781         /** one of RQ_PHASE_* to be used next */
782         enum rq_phase                   rq_next_phase;
783         /**
784          * client-side refcount for SENT race, server-side refcount
785          * for multiple replies
786          */
787         atomic_t                        rq_refcount;
788         /**
789          * client-side:
790          * !rq_truncate : # reply bytes actually received,
791          *  rq_truncate : required repbuf_len for resend
792          */
793         int rq_nob_received;
794         /** Request length */
795         int rq_reqlen;
796         /** Reply length */
797         int rq_replen;
798         /** Pool if request is from preallocated list */
799         struct ptlrpc_request_pool     *rq_pool;
800         /** Request message - what client sent */
801         struct lustre_msg *rq_reqmsg;
802         /** Reply message - server response */
803         struct lustre_msg *rq_repmsg;
804         /** Transaction number */
805         __u64 rq_transno;
806         /** xid */
807         __u64 rq_xid;
808         /** bulk match bits */
809         u64                             rq_mbits;
810         /**
811          * List item to for replay list. Not yet committed requests get linked
812          * there.
813          * Also see \a rq_replay comment above.
814          * It's also link chain on obd_export::exp_req_replay_queue
815          */
816         struct list_head rq_replay_list;
817         /** non-shared members for client & server request*/
818         union {
819                 struct ptlrpc_cli_req    rq_cli;
820                 struct ptlrpc_srv_req    rq_srv;
821         };
822         /**
823          * security and encryption data
824          * @{
825          */
826         /** description of flavors for client & server */
827         struct sptlrpc_flavor           rq_flvr;
828
829         /* client/server security flags */
830         unsigned int
831                                  rq_ctx_init:1,      /* context initiation */
832                                  rq_ctx_fini:1,      /* context destroy */
833                                  rq_bulk_read:1,     /* request bulk read */
834                                  rq_bulk_write:1,    /* request bulk write */
835                                  /* server authentication flags */
836                                  rq_auth_gss:1,      /* authenticated by gss */
837                                  rq_auth_usr_root:1, /* authed as root */
838                                  rq_auth_usr_mdt:1,  /* authed as mdt */
839                                  rq_auth_usr_ost:1,  /* authed as ost */
840                                  /* security tfm flags */
841                                  rq_pack_udesc:1,
842                                  rq_pack_bulk:1,
843                                  /* doesn't expect reply FIXME */
844                                  rq_no_reply:1,
845                                  rq_pill_init:1, /* pill initialized */
846                                  rq_srv_req:1; /* server request */
847
848         /** various buffer pointers */
849         struct lustre_msg       *rq_reqbuf;     /**< req wrapper */
850         char                    *rq_repbuf;     /**< rep buffer */
851         struct lustre_msg       *rq_repdata;    /**< rep wrapper msg */
852         /** only in priv mode */
853         struct lustre_msg       *rq_clrbuf;
854         int                   rq_reqbuf_len;  /* req wrapper buf len */
855         int                   rq_reqdata_len; /* req wrapper msg len */
856         int                   rq_repbuf_len;  /* rep buffer len */
857         int                   rq_repdata_len; /* rep wrapper msg len */
858         int                   rq_clrbuf_len;  /* only in priv mode */
859         int                   rq_clrdata_len; /* only in priv mode */
860
861         /** early replies go to offset 0, regular replies go after that */
862         unsigned int         rq_reply_off;
863
864         /** @} */
865
866         /** Fields that help to see if request and reply were swabbed or not */
867         __u32 rq_req_swab_mask;
868         __u32 rq_rep_swab_mask;
869
870         /** how many early replies (for stats) */
871         int rq_early_count;
872
873         /** Server-side, export on which request was received */
874         struct obd_export               *rq_export;
875         /** import where request is being sent */
876         struct obd_import               *rq_import;
877         /** our LNet NID */
878         lnet_nid_t         rq_self;
879         /** Peer description (the other side) */
880         struct lnet_process_id  rq_peer;
881         /**
882          * service time estimate (secs)
883          * If the request is not served by this time, it is marked as timed out.
884          */
885         int                     rq_timeout;
886         /**
887          * when request/reply sent (secs), or time when request should be sent
888          */
889         time64_t rq_sent;
890         /** when request must finish. */
891         time64_t                  rq_deadline;
892         /** request format description */
893         struct req_capsule        rq_pill;
894 };
895
896 /**
897  * Call completion handler for rpc if any, return it's status or original
898  * rc if there was no handler defined for this request.
899  */
900 static inline int ptlrpc_req_interpret(const struct lu_env *env,
901                                        struct ptlrpc_request *req, int rc)
902 {
903         if (req->rq_interpret_reply) {
904                 req->rq_status = req->rq_interpret_reply(env, req,
905                                                          &req->rq_async_args,
906                                                          rc);
907                 return req->rq_status;
908         }
909         return rc;
910 }
911
912 /*
913  * Can the request be moved from the regular NRS head to the high-priority NRS
914  * head (of the same PTLRPC service partition), if any?
915  *
916  * For a reliable result, this should be checked under svcpt->scp_req lock.
917  */
918 static inline bool ptlrpc_nrs_req_can_move(struct ptlrpc_request *req)
919 {
920         struct ptlrpc_nrs_request *nrq = &req->rq_nrq;
921
922         /**
923          * LU-898: Check ptlrpc_nrs_request::nr_enqueued to make sure the
924          * request has been enqueued first, and ptlrpc_nrs_request::nr_started
925          * to make sure it has not been scheduled yet (analogous to previous
926          * (non-NRS) checking of !list_empty(&ptlrpc_request::rq_list).
927          */
928         return nrq->nr_enqueued && !nrq->nr_started && !req->rq_hp;
929 }
930
931 /** @} nrs */
932
933 /**
934  * Returns 1 if request buffer at offset \a index was already swabbed
935  */
936 static inline int lustre_req_swabbed(struct ptlrpc_request *req, size_t index)
937 {
938         LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
939         return req->rq_req_swab_mask & (1 << index);
940 }
941
942 /**
943  * Returns 1 if request reply buffer at offset \a index was already swabbed
944  */
945 static inline int lustre_rep_swabbed(struct ptlrpc_request *req, size_t index)
946 {
947         LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
948         return req->rq_rep_swab_mask & (1 << index);
949 }
950
951 /**
952  * Returns 1 if request needs to be swabbed into local cpu byteorder
953  */
954 static inline int ptlrpc_req_need_swab(struct ptlrpc_request *req)
955 {
956         return lustre_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
957 }
958
959 /**
960  * Returns 1 if request reply needs to be swabbed into local cpu byteorder
961  */
962 static inline int ptlrpc_rep_need_swab(struct ptlrpc_request *req)
963 {
964         return lustre_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
965 }
966
967 /**
968  * Mark request buffer at offset \a index that it was already swabbed
969  */
970 static inline void lustre_set_req_swabbed(struct ptlrpc_request *req,
971                                           size_t index)
972 {
973         LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
974         LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
975         req->rq_req_swab_mask |= 1 << index;
976 }
977
978 /**
979  * Mark request reply buffer at offset \a index that it was already swabbed
980  */
981 static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req,
982                                           size_t index)
983 {
984         LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
985         LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
986         req->rq_rep_swab_mask |= 1 << index;
987 }
988
989 /**
990  * Convert numerical request phase value \a phase into text string description
991  */
992 static inline const char *
993 ptlrpc_phase2str(enum rq_phase phase)
994 {
995         switch (phase) {
996         case RQ_PHASE_NEW:
997                 return "New";
998         case RQ_PHASE_RPC:
999                 return "Rpc";
1000         case RQ_PHASE_BULK:
1001                 return "Bulk";
1002         case RQ_PHASE_INTERPRET:
1003                 return "Interpret";
1004         case RQ_PHASE_COMPLETE:
1005                 return "Complete";
1006         case RQ_PHASE_UNREG_RPC:
1007                 return "UnregRPC";
1008         case RQ_PHASE_UNREG_BULK:
1009                 return "UnregBULK";
1010         default:
1011                 return "?Phase?";
1012         }
1013 }
1014
1015 /**
1016  * Convert numerical request phase of the request \a req into text stringi
1017  * description
1018  */
1019 static inline const char *
1020 ptlrpc_rqphase2str(struct ptlrpc_request *req)
1021 {
1022         return ptlrpc_phase2str(req->rq_phase);
1023 }
1024
1025 /**
1026  * Debugging functions and helpers to print request structure into debug log
1027  * @{
1028  */
1029 /* Spare the preprocessor, spoil the bugs. */
1030 #define FLAG(field, str) (field ? str : "")
1031
1032 /** Convert bit flags into a string */
1033 #define DEBUG_REQ_FLAGS(req)                                                \
1034         ptlrpc_rqphase2str(req),                                                \
1035         FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"),                \
1036         FLAG(req->rq_err, "E"), FLAG(req->rq_net_err, "e"),                 \
1037         FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"),   \
1038         FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"),            \
1039         FLAG(req->rq_no_resend, "N"),                                      \
1040         FLAG(req->rq_waiting, "W"),                                          \
1041         FLAG(req->rq_wait_ctx, "C"), FLAG(req->rq_hp, "H"),                  \
1042         FLAG(req->rq_committed, "M")
1043
1044 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s%s%s%s"
1045
1046 void _debug_req(struct ptlrpc_request *req,
1047                 struct libcfs_debug_msg_data *data, const char *fmt, ...)
1048         __printf(3, 4);
1049
1050 /**
1051  * Helper that decides if we need to print request according to current debug
1052  * level settings
1053  */
1054 #define debug_req(msgdata, mask, cdls, req, fmt, a...)                  \
1055 do {                                                                      \
1056         CFS_CHECK_STACK(msgdata, mask, cdls);                            \
1057                                                                               \
1058         if (((mask) & D_CANTMASK) != 0 ||                                    \
1059             ((libcfs_debug & (mask)) != 0 &&                              \
1060              (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0))          \
1061                 _debug_req((req), msgdata, fmt, ##a);                    \
1062 } while (0)
1063
1064 /**
1065  * This is the debug print function you need to use to print request structure
1066  * content into lustre debug log.
1067  * for most callers (level is a constant) this is resolved at compile time
1068  */
1069 #define DEBUG_REQ(level, req, fmt, args...)                                \
1070 do {                                                                      \
1071         if ((level) & (D_ERROR | D_WARNING)) {                          \
1072                 static struct cfs_debug_limit_state cdls;                         \
1073                 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, level, &cdls);          \
1074                 debug_req(&msgdata, level, &cdls, req, "@@@ "fmt" ", ## args);\
1075         } else {                                                              \
1076                 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, level, NULL);            \
1077                 debug_req(&msgdata, level, NULL, req, "@@@ "fmt" ", ## args); \
1078         }                                                                    \
1079 } while (0)
1080 /** @} */
1081
1082 /**
1083  * Structure that defines a single page of a bulk transfer
1084  */
1085 struct ptlrpc_bulk_page {
1086         /** Linkage to list of pages in a bulk */
1087         struct list_head       bp_link;
1088         /**
1089          * Number of bytes in a page to transfer starting from \a bp_pageoffset
1090          */
1091         int           bp_buflen;
1092         /** offset within a page */
1093         int           bp_pageoffset;
1094         /** The page itself */
1095         struct page     *bp_page;
1096 };
1097
1098 enum ptlrpc_bulk_op_type {
1099         PTLRPC_BULK_OP_ACTIVE   = 0x00000001,
1100         PTLRPC_BULK_OP_PASSIVE  = 0x00000002,
1101         PTLRPC_BULK_OP_PUT      = 0x00000004,
1102         PTLRPC_BULK_OP_GET      = 0x00000008,
1103         PTLRPC_BULK_BUF_KVEC    = 0x00000010,
1104         PTLRPC_BULK_BUF_KIOV    = 0x00000020,
1105         PTLRPC_BULK_GET_SOURCE  = PTLRPC_BULK_OP_PASSIVE | PTLRPC_BULK_OP_GET,
1106         PTLRPC_BULK_PUT_SINK    = PTLRPC_BULK_OP_PASSIVE | PTLRPC_BULK_OP_PUT,
1107         PTLRPC_BULK_GET_SINK    = PTLRPC_BULK_OP_ACTIVE | PTLRPC_BULK_OP_GET,
1108         PTLRPC_BULK_PUT_SOURCE  = PTLRPC_BULK_OP_ACTIVE | PTLRPC_BULK_OP_PUT,
1109 };
1110
1111 static inline bool ptlrpc_is_bulk_op_get(enum ptlrpc_bulk_op_type type)
1112 {
1113         return (type & PTLRPC_BULK_OP_GET) == PTLRPC_BULK_OP_GET;
1114 }
1115
1116 static inline bool ptlrpc_is_bulk_get_source(enum ptlrpc_bulk_op_type type)
1117 {
1118         return (type & PTLRPC_BULK_GET_SOURCE) == PTLRPC_BULK_GET_SOURCE;
1119 }
1120
1121 static inline bool ptlrpc_is_bulk_put_sink(enum ptlrpc_bulk_op_type type)
1122 {
1123         return (type & PTLRPC_BULK_PUT_SINK) == PTLRPC_BULK_PUT_SINK;
1124 }
1125
1126 static inline bool ptlrpc_is_bulk_get_sink(enum ptlrpc_bulk_op_type type)
1127 {
1128         return (type & PTLRPC_BULK_GET_SINK) == PTLRPC_BULK_GET_SINK;
1129 }
1130
1131 static inline bool ptlrpc_is_bulk_put_source(enum ptlrpc_bulk_op_type type)
1132 {
1133         return (type & PTLRPC_BULK_PUT_SOURCE) == PTLRPC_BULK_PUT_SOURCE;
1134 }
1135
1136 static inline bool ptlrpc_is_bulk_desc_kvec(enum ptlrpc_bulk_op_type type)
1137 {
1138         return ((type & PTLRPC_BULK_BUF_KVEC) | (type & PTLRPC_BULK_BUF_KIOV))
1139                 == PTLRPC_BULK_BUF_KVEC;
1140 }
1141
1142 static inline bool ptlrpc_is_bulk_desc_kiov(enum ptlrpc_bulk_op_type type)
1143 {
1144         return ((type & PTLRPC_BULK_BUF_KVEC) | (type & PTLRPC_BULK_BUF_KIOV))
1145                 == PTLRPC_BULK_BUF_KIOV;
1146 }
1147
1148 static inline bool ptlrpc_is_bulk_op_active(enum ptlrpc_bulk_op_type type)
1149 {
1150         return ((type & PTLRPC_BULK_OP_ACTIVE) |
1151                 (type & PTLRPC_BULK_OP_PASSIVE)) == PTLRPC_BULK_OP_ACTIVE;
1152 }
1153
1154 static inline bool ptlrpc_is_bulk_op_passive(enum ptlrpc_bulk_op_type type)
1155 {
1156         return ((type & PTLRPC_BULK_OP_ACTIVE) |
1157                 (type & PTLRPC_BULK_OP_PASSIVE)) == PTLRPC_BULK_OP_PASSIVE;
1158 }
1159
1160 struct ptlrpc_bulk_frag_ops {
1161         /**
1162          * Add a page \a page to the bulk descriptor \a desc
1163          * Data to transfer in the page starts at offset \a pageoffset and
1164          * amount of data to transfer from the page is \a len
1165          */
1166         void (*add_kiov_frag)(struct ptlrpc_bulk_desc *desc,
1167                               struct page *page, int pageoffset, int len);
1168
1169         /*
1170          * Add a \a fragment to the bulk descriptor \a desc.
1171          * Data to transfer in the fragment is pointed to by \a frag
1172          * The size of the fragment is \a len
1173          */
1174         int (*add_iov_frag)(struct ptlrpc_bulk_desc *desc, void *frag, int len);
1175
1176         /**
1177          * Uninitialize and free bulk descriptor \a desc.
1178          * Works on bulk descriptors both from server and client side.
1179          */
1180         void (*release_frags)(struct ptlrpc_bulk_desc *desc);
1181 };
1182
1183 extern const struct ptlrpc_bulk_frag_ops ptlrpc_bulk_kiov_pin_ops;
1184 extern const struct ptlrpc_bulk_frag_ops ptlrpc_bulk_kiov_nopin_ops;
1185
1186 /**
1187  * Definition of bulk descriptor.
1188  * Bulks are special "Two phase" RPCs where initial request message
1189  * is sent first and it is followed bt a transfer (o receiving) of a large
1190  * amount of data to be settled into pages referenced from the bulk descriptors.
1191  * Bulks transfers (the actual data following the small requests) are done
1192  * on separate LNet portals.
1193  * In lustre we use bulk transfers for READ and WRITE transfers from/to OSTs.
1194  *  Another user is readpage for MDT.
1195  */
1196 struct ptlrpc_bulk_desc {
1197         /** completed with failure */
1198         unsigned long bd_failure:1;
1199         /** client side */
1200         unsigned long bd_registered:1;
1201         /** For serialization with callback */
1202         spinlock_t bd_lock;
1203         /** Import generation when request for this bulk was sent */
1204         int bd_import_generation;
1205         /** {put,get}{source,sink}{kvec,kiov} */
1206         enum ptlrpc_bulk_op_type bd_type;
1207         /** LNet portal for this bulk */
1208         __u32 bd_portal;
1209         /** Server side - export this bulk created for */
1210         struct obd_export *bd_export;
1211         /** Client side - import this bulk was sent on */
1212         struct obd_import *bd_import;
1213         /** Back pointer to the request */
1214         struct ptlrpc_request *bd_req;
1215         struct ptlrpc_bulk_frag_ops *bd_frag_ops;
1216         wait_queue_head_t           bd_waitq;   /* server side only WQ */
1217         int                 bd_iov_count;    /* # entries in bd_iov */
1218         int                 bd_max_iov;      /* allocated size of bd_iov */
1219         int                 bd_nob;       /* # bytes covered */
1220         int                 bd_nob_transferred; /* # bytes GOT/PUT */
1221
1222         u64                     bd_last_mbits;
1223
1224         struct ptlrpc_cb_id    bd_cbid;  /* network callback info */
1225         lnet_nid_t           bd_sender;       /* stash event::sender */
1226         int                     bd_md_count;    /* # valid entries in bd_mds */
1227         int                     bd_md_max_brw;  /* max entries in bd_mds */
1228         /** array of associated MDs */
1229         struct lnet_handle_md   bd_mds[PTLRPC_BULK_OPS_COUNT];
1230
1231         union {
1232                 struct {
1233                         /*
1234                          * encrypt iov, size is either 0 or bd_iov_count.
1235                          */
1236                         struct bio_vec *bd_enc_vec;
1237                         struct bio_vec *bd_vec; /* Array of bio_vecs */
1238                 } bd_kiov;
1239
1240                 struct {
1241                         struct kvec *bd_enc_kvec;
1242                         struct kvec *bd_kvec;   /* Array of kvecs */
1243                 } bd_kvec;
1244         } bd_u;
1245 };
1246
1247 #define GET_KIOV(desc)                  ((desc)->bd_u.bd_kiov.bd_vec)
1248 #define BD_GET_KIOV(desc, i)            ((desc)->bd_u.bd_kiov.bd_vec[i])
1249 #define GET_ENC_KIOV(desc)              ((desc)->bd_u.bd_kiov.bd_enc_vec)
1250 #define BD_GET_ENC_KIOV(desc, i)        ((desc)->bd_u.bd_kiov.bd_enc_vec[i])
1251 #define GET_KVEC(desc)                  ((desc)->bd_u.bd_kvec.bd_kvec)
1252 #define BD_GET_KVEC(desc, i)            ((desc)->bd_u.bd_kvec.bd_kvec[i])
1253 #define GET_ENC_KVEC(desc)              ((desc)->bd_u.bd_kvec.bd_enc_kvec)
1254 #define BD_GET_ENC_KVEC(desc, i)        ((desc)->bd_u.bd_kvec.bd_enc_kvec[i])
1255
1256 enum {
1257         SVC_STOPPED     = 1 << 0,
1258         SVC_STOPPING    = 1 << 1,
1259         SVC_STARTING    = 1 << 2,
1260         SVC_RUNNING     = 1 << 3,
1261         SVC_EVENT       = 1 << 4,
1262         SVC_SIGNAL      = 1 << 5,
1263 };
1264
1265 #define PTLRPC_THR_NAME_LEN             32
1266 /**
1267  * Definition of server service thread structure
1268  */
1269 struct ptlrpc_thread {
1270         /**
1271          * List of active threads in svc->srv_threads
1272          */
1273         struct list_head t_link;
1274         /**
1275          * thread-private data (preallocated memory)
1276          */
1277         void *t_data;
1278         __u32 t_flags;
1279         /**
1280          * service thread index, from ptlrpc_start_threads
1281          */
1282         unsigned int t_id;
1283         /**
1284          * service thread pid
1285          */
1286         pid_t t_pid;
1287         /**
1288          * put watchdog in the structure per thread b=14840
1289          *
1290          * Lustre watchdog is removed for client in the hope
1291          * of a generic watchdog can be merged in kernel.
1292          * When that happens, we should add below back.
1293          *
1294          * struct lc_watchdog *t_watchdog;
1295          */
1296         /**
1297          * the svc this thread belonged to b=18582
1298          */
1299         struct ptlrpc_service_part      *t_svcpt;
1300         wait_queue_head_t                       t_ctl_waitq;
1301         struct lu_env                   *t_env;
1302         char                            t_name[PTLRPC_THR_NAME_LEN];
1303 };
1304
1305 static inline int thread_is_init(struct ptlrpc_thread *thread)
1306 {
1307         return thread->t_flags == 0;
1308 }
1309
1310 static inline int thread_is_stopped(struct ptlrpc_thread *thread)
1311 {
1312         return !!(thread->t_flags & SVC_STOPPED);
1313 }
1314
1315 static inline int thread_is_stopping(struct ptlrpc_thread *thread)
1316 {
1317         return !!(thread->t_flags & SVC_STOPPING);
1318 }
1319
1320 static inline int thread_is_starting(struct ptlrpc_thread *thread)
1321 {
1322         return !!(thread->t_flags & SVC_STARTING);
1323 }
1324
1325 static inline int thread_is_running(struct ptlrpc_thread *thread)
1326 {
1327         return !!(thread->t_flags & SVC_RUNNING);
1328 }
1329
1330 static inline int thread_is_event(struct ptlrpc_thread *thread)
1331 {
1332         return !!(thread->t_flags & SVC_EVENT);
1333 }
1334
1335 static inline int thread_is_signal(struct ptlrpc_thread *thread)
1336 {
1337         return !!(thread->t_flags & SVC_SIGNAL);
1338 }
1339
1340 static inline void thread_clear_flags(struct ptlrpc_thread *thread, __u32 flags)
1341 {
1342         thread->t_flags &= ~flags;
1343 }
1344
1345 static inline void thread_set_flags(struct ptlrpc_thread *thread, __u32 flags)
1346 {
1347         thread->t_flags = flags;
1348 }
1349
1350 static inline void thread_add_flags(struct ptlrpc_thread *thread, __u32 flags)
1351 {
1352         thread->t_flags |= flags;
1353 }
1354
1355 static inline int thread_test_and_clear_flags(struct ptlrpc_thread *thread,
1356                                               __u32 flags)
1357 {
1358         if (thread->t_flags & flags) {
1359                 thread->t_flags &= ~flags;
1360                 return 1;
1361         }
1362         return 0;
1363 }
1364
1365 /**
1366  * Request buffer descriptor structure.
1367  * This is a structure that contains one posted request buffer for service.
1368  * Once data land into a buffer, event callback creates actual request and
1369  * notifies wakes one of the service threads to process new incoming request.
1370  * More than one request can fit into the buffer.
1371  */
1372 struct ptlrpc_request_buffer_desc {
1373         /** Link item for rqbds on a service */
1374         struct list_head             rqbd_list;
1375         /** History of requests for this buffer */
1376         struct list_head             rqbd_reqs;
1377         /** Back pointer to service for which this buffer is registered */
1378         struct ptlrpc_service_part *rqbd_svcpt;
1379         /** LNet descriptor */
1380         struct lnet_handle_md           rqbd_md_h;
1381         int                 rqbd_refcount;
1382         /** The buffer itself */
1383         char              *rqbd_buffer;
1384         struct ptlrpc_cb_id    rqbd_cbid;
1385         /**
1386          * This "embedded" request structure is only used for the
1387          * last request to fit into the buffer
1388          */
1389         struct ptlrpc_request  rqbd_req;
1390 };
1391
1392 typedef int  (*svc_handler_t)(struct ptlrpc_request *req);
1393
1394 struct ptlrpc_service_ops {
1395         /**
1396          * if non-NULL called during thread creation (ptlrpc_start_thread())
1397          * to initialize service specific per-thread state.
1398          */
1399         int             (*so_thr_init)(struct ptlrpc_thread *thr);
1400         /**
1401          * if non-NULL called during thread shutdown (ptlrpc_main()) to
1402          * destruct state created by ->srv_init().
1403          */
1404         void            (*so_thr_done)(struct ptlrpc_thread *thr);
1405         /**
1406          * Handler function for incoming requests for this service
1407          */
1408         int             (*so_req_handler)(struct ptlrpc_request *req);
1409         /**
1410          * function to determine priority of the request, it's called
1411          * on every new request
1412          */
1413         int             (*so_hpreq_handler)(struct ptlrpc_request *);
1414         /**
1415          * service-specific print fn
1416          */
1417         void            (*so_req_printer)(void *, struct ptlrpc_request *);
1418 };
1419
1420 #ifndef __cfs_cacheline_aligned
1421 /* NB: put it here for reducing patche dependence */
1422 # define __cfs_cacheline_aligned
1423 #endif
1424
1425 /**
1426  * How many high priority requests to serve before serving one normal
1427  * priority request
1428  */
1429 #define PTLRPC_SVC_HP_RATIO 10
1430
1431 /**
1432  * Definition of PortalRPC service.
1433  * The service is listening on a particular portal (like tcp port)
1434  * and perform actions for a specific server like IO service for OST
1435  * or general metadata service for MDS.
1436  */
1437 struct ptlrpc_service {
1438         /** serialize sysfs operations */
1439         spinlock_t                      srv_lock;
1440         /** most often accessed fields */
1441         /** chain thru all services */
1442         struct list_head                      srv_list;
1443         /** service operations table */
1444         struct ptlrpc_service_ops       srv_ops;
1445         /** only statically allocated strings here; we don't clean them */
1446         char                       *srv_name;
1447         /** only statically allocated strings here; we don't clean them */
1448         char                       *srv_thread_name;
1449         /** service thread list */
1450         struct list_head                      srv_threads;
1451         /** threads # should be created for each partition on initializing */
1452         int                             srv_nthrs_cpt_init;
1453         /** limit of threads number for each partition */
1454         int                             srv_nthrs_cpt_limit;
1455         /** Root of debugfs dir tree for this service */
1456         struct dentry              *srv_debugfs_entry;
1457         /** Pointer to statistic data for this service */
1458         struct lprocfs_stats       *srv_stats;
1459         /** # hp per lp reqs to handle */
1460         int                          srv_hpreq_ratio;
1461         /** biggest request to receive */
1462         int                          srv_max_req_size;
1463         /** biggest reply to send */
1464         int                          srv_max_reply_size;
1465         /** size of individual buffers */
1466         int                          srv_buf_size;
1467         /** # buffers to allocate in 1 group */
1468         int                          srv_nbuf_per_group;
1469         /** Local portal on which to receive requests */
1470         __u32                      srv_req_portal;
1471         /** Portal on the client to send replies to */
1472         __u32                      srv_rep_portal;
1473         /**
1474          * Tags for lu_context associated with this thread, see struct
1475          * lu_context.
1476          */
1477         __u32                      srv_ctx_tags;
1478         /** soft watchdog timeout multiplier */
1479         int                          srv_watchdog_factor;
1480         /** under unregister_service */
1481         unsigned                        srv_is_stopping:1;
1482
1483         /** max # request buffers in history per partition */
1484         int                             srv_hist_nrqbds_cpt_max;
1485         /** number of CPTs this service bound on */
1486         int                             srv_ncpts;
1487         /** CPTs array this service bound on */
1488         __u32                           *srv_cpts;
1489         /** 2^srv_cptab_bits >= cfs_cpt_numbert(srv_cptable) */
1490         int                             srv_cpt_bits;
1491         /** CPT table this service is running over */
1492         struct cfs_cpt_table            *srv_cptable;
1493
1494         /* sysfs object */
1495         struct kobject                   srv_kobj;
1496         struct completion                srv_kobj_unregister;
1497         /**
1498          * partition data for ptlrpc service
1499          */
1500         struct ptlrpc_service_part      *srv_parts[0];
1501 };
1502
1503 /**
1504  * Definition of PortalRPC service partition data.
1505  * Although a service only has one instance of it right now, but we
1506  * will have multiple instances very soon (instance per CPT).
1507  *
1508  * it has four locks:
1509  * \a scp_lock
1510  *    serialize operations on rqbd and requests waiting for preprocess
1511  * \a scp_req_lock
1512  *    serialize operations active requests sent to this portal
1513  * \a scp_at_lock
1514  *    serialize adaptive timeout stuff
1515  * \a scp_rep_lock
1516  *    serialize operations on RS list (reply states)
1517  *
1518  * We don't have any use-case to take two or more locks at the same time
1519  * for now, so there is no lock order issue.
1520  */
1521 struct ptlrpc_service_part {
1522         /** back reference to owner */
1523         struct ptlrpc_service           *scp_service __cfs_cacheline_aligned;
1524         /* CPT id, reserved */
1525         int                             scp_cpt;
1526         /** always increasing number */
1527         int                             scp_thr_nextid;
1528         /** # of starting threads */
1529         int                             scp_nthrs_starting;
1530         /** # of stopping threads, reserved for shrinking threads */
1531         int                             scp_nthrs_stopping;
1532         /** # running threads */
1533         int                             scp_nthrs_running;
1534         /** service threads list */
1535         struct list_head                        scp_threads;
1536
1537         /**
1538          * serialize the following fields, used for protecting
1539          * rqbd list and incoming requests waiting for preprocess,
1540          * threads starting & stopping are also protected by this lock.
1541          */
1542         spinlock_t scp_lock __cfs_cacheline_aligned;
1543         /** total # req buffer descs allocated */
1544         int                             scp_nrqbds_total;
1545         /** # posted request buffers for receiving */
1546         int                             scp_nrqbds_posted;
1547         /** in progress of allocating rqbd */
1548         int                             scp_rqbd_allocating;
1549         /** # incoming reqs */
1550         int                             scp_nreqs_incoming;
1551         /** request buffers to be reposted */
1552         struct list_head                        scp_rqbd_idle;
1553         /** req buffers receiving */
1554         struct list_head                        scp_rqbd_posted;
1555         /** incoming reqs */
1556         struct list_head                        scp_req_incoming;
1557         /** timeout before re-posting reqs, in tick */
1558         long                    scp_rqbd_timeout;
1559         /**
1560          * all threads sleep on this. This wait-queue is signalled when new
1561          * incoming request arrives and when difficult reply has to be handled.
1562          */
1563         wait_queue_head_t                       scp_waitq;
1564
1565         /** request history */
1566         struct list_head                        scp_hist_reqs;
1567         /** request buffer history */
1568         struct list_head                        scp_hist_rqbds;
1569         /** # request buffers in history */
1570         int                             scp_hist_nrqbds;
1571         /** sequence number for request */
1572         __u64                           scp_hist_seq;
1573         /** highest seq culled from history */
1574         __u64                           scp_hist_seq_culled;
1575
1576         /**
1577          * serialize the following fields, used for processing requests
1578          * sent to this portal
1579          */
1580         spinlock_t                      scp_req_lock __cfs_cacheline_aligned;
1581         /** # reqs in either of the NRS heads below */
1582         /** # reqs being served */
1583         int                             scp_nreqs_active;
1584         /** # HPreqs being served */
1585         int                             scp_nhreqs_active;
1586         /** # hp requests handled */
1587         int                             scp_hreq_count;
1588
1589         /** NRS head for regular requests */
1590         struct ptlrpc_nrs               scp_nrs_reg;
1591         /** NRS head for HP requests; this is only valid for services that can
1592          *  handle HP requests
1593          */
1594         struct ptlrpc_nrs              *scp_nrs_hp;
1595
1596         /** AT stuff */
1597         /** @{ */
1598         /**
1599          * serialize the following fields, used for changes on
1600          * adaptive timeout
1601          */
1602         spinlock_t                      scp_at_lock __cfs_cacheline_aligned;
1603         /** estimated rpc service time */
1604         struct adaptive_timeout         scp_at_estimate;
1605         /** reqs waiting for replies */
1606         struct ptlrpc_at_array          scp_at_array;
1607         /** early reply timer */
1608         struct timer_list               scp_at_timer;
1609         /** debug */
1610         unsigned long                   scp_at_checktime;
1611         /** check early replies */
1612         unsigned                        scp_at_check;
1613         /** @} */
1614
1615         /**
1616          * serialize the following fields, used for processing
1617          * replies for this portal
1618          */
1619         spinlock_t                      scp_rep_lock __cfs_cacheline_aligned;
1620         /** all the active replies */
1621         struct list_head                        scp_rep_active;
1622         /** List of free reply_states */
1623         struct list_head                        scp_rep_idle;
1624         /** waitq to run, when adding stuff to srv_free_rs_list */
1625         wait_queue_head_t                       scp_rep_waitq;
1626         /** # 'difficult' replies */
1627         atomic_t                        scp_nreps_difficult;
1628 };
1629
1630 #define ptlrpc_service_for_each_part(part, i, svc)                      \
1631         for (i = 0;                                                     \
1632              i < (svc)->srv_ncpts &&                                    \
1633              (svc)->srv_parts &&                                        \
1634              ((part) = (svc)->srv_parts[i]); i++)
1635
1636 /**
1637  * Declaration of ptlrpcd control structure
1638  */
1639 struct ptlrpcd_ctl {
1640         /**
1641          * Ptlrpc thread control flags (LIOD_START, LIOD_STOP, LIOD_FORCE)
1642          */
1643         unsigned long                   pc_flags;
1644         /**
1645          * Thread lock protecting structure fields.
1646          */
1647         spinlock_t                      pc_lock;
1648         /**
1649          * Start completion.
1650          */
1651         struct completion               pc_starting;
1652         /**
1653          * Stop completion.
1654          */
1655         struct completion               pc_finishing;
1656         /**
1657          * Thread requests set.
1658          */
1659         struct ptlrpc_request_set  *pc_set;
1660         /**
1661          * Thread name used in kthread_run()
1662          */
1663         char                    pc_name[16];
1664         /**
1665          * CPT the thread is bound on.
1666          */
1667         int                             pc_cpt;
1668         /**
1669          * Index of ptlrpcd thread in the array.
1670          */
1671         int                             pc_index;
1672         /**
1673          * Pointer to the array of partners' ptlrpcd_ctl structure.
1674          */
1675         struct ptlrpcd_ctl      **pc_partners;
1676         /**
1677          * Number of the ptlrpcd's partners.
1678          */
1679         int                             pc_npartners;
1680         /**
1681          * Record the partner index to be processed next.
1682          */
1683         int                      pc_cursor;
1684         /**
1685          * Error code if the thread failed to fully start.
1686          */
1687         int                             pc_error;
1688 };
1689
1690 /* Bits for pc_flags */
1691 enum ptlrpcd_ctl_flags {
1692         /**
1693          * Ptlrpc thread start flag.
1694          */
1695         LIOD_START       = 1 << 0,
1696         /**
1697          * Ptlrpc thread stop flag.
1698          */
1699         LIOD_STOP       = 1 << 1,
1700         /**
1701          * Ptlrpc thread force flag (only stop force so far).
1702          * This will cause aborting any inflight rpcs handled
1703          * by thread if LIOD_STOP is specified.
1704          */
1705         LIOD_FORCE       = 1 << 2,
1706         /**
1707          * This is a recovery ptlrpc thread.
1708          */
1709         LIOD_RECOVERY    = 1 << 3,
1710 };
1711
1712 /**
1713  * \addtogroup nrs
1714  * @{
1715  *
1716  * Service compatibility function; the policy is compatible with all services.
1717  *
1718  * \param[in] svc  The service the policy is attempting to register with.
1719  * \param[in] desc The policy descriptor
1720  *
1721  * \retval true The policy is compatible with the service
1722  *
1723  * \see ptlrpc_nrs_pol_desc::pd_compat()
1724  */
1725 static inline bool nrs_policy_compat_all(const struct ptlrpc_service *svc,
1726                                          const struct ptlrpc_nrs_pol_desc *desc)
1727 {
1728         return true;
1729 }
1730
1731 /**
1732  * Service compatibility function; the policy is compatible with only a specific
1733  * service which is identified by its human-readable name at
1734  * ptlrpc_service::srv_name.
1735  *
1736  * \param[in] svc  The service the policy is attempting to register with.
1737  * \param[in] desc The policy descriptor
1738  *
1739  * \retval false The policy is not compatible with the service
1740  * \retval true  The policy is compatible with the service
1741  *
1742  * \see ptlrpc_nrs_pol_desc::pd_compat()
1743  */
1744 static inline bool nrs_policy_compat_one(const struct ptlrpc_service *svc,
1745                                          const struct ptlrpc_nrs_pol_desc *desc)
1746 {
1747         return strcmp(svc->srv_name, desc->pd_compat_svc_name) == 0;
1748 }
1749
1750 /** @} nrs */
1751
1752 /* ptlrpc/events.c */
1753 extern struct lnet_handle_eq ptlrpc_eq_h;
1754 int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
1755                         struct lnet_process_id *peer, lnet_nid_t *self);
1756 /**
1757  * These callbacks are invoked by LNet when something happened to
1758  * underlying buffer
1759  * @{
1760  */
1761 void request_out_callback(struct lnet_event *ev);
1762 void reply_in_callback(struct lnet_event *ev);
1763 void client_bulk_callback(struct lnet_event *ev);
1764 void request_in_callback(struct lnet_event *ev);
1765 void reply_out_callback(struct lnet_event *ev);
1766 /** @} */
1767
1768 /* ptlrpc/connection.c */
1769 struct ptlrpc_connection *ptlrpc_connection_get(struct lnet_process_id peer,
1770                                                 lnet_nid_t self,
1771                                                 struct obd_uuid *uuid);
1772 int ptlrpc_connection_put(struct ptlrpc_connection *c);
1773 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
1774 int ptlrpc_connection_init(void);
1775 void ptlrpc_connection_fini(void);
1776
1777 /* ptlrpc/niobuf.c */
1778 /**
1779  * Actual interfacing with LNet to put/get/register/unregister stuff
1780  * @{
1781  */
1782
1783 int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async);
1784
1785 static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req)
1786 {
1787         struct ptlrpc_bulk_desc *desc;
1788         int                   rc;
1789
1790         desc = req->rq_bulk;
1791
1792         if (req->rq_bulk_deadline > ktime_get_real_seconds())
1793                 return 1;
1794
1795         if (!desc)
1796                 return 0;
1797
1798         spin_lock(&desc->bd_lock);
1799         rc = desc->bd_md_count;
1800         spin_unlock(&desc->bd_lock);
1801         return rc;
1802 }
1803
1804 #define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
1805 #define PTLRPC_REPLY_EARLY         0x02
1806 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
1807 int ptlrpc_reply(struct ptlrpc_request *req);
1808 int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
1809 int ptlrpc_error(struct ptlrpc_request *req);
1810 int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
1811 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
1812 int ptlrpc_register_rqbd(struct ptlrpc_request_buffer_desc *rqbd);
1813 /** @} */
1814
1815 /* ptlrpc/client.c */
1816 /**
1817  * Client-side portals API. Everything to send requests, receive replies,
1818  * request queues, request management, etc.
1819  * @{
1820  */
1821 void ptlrpc_request_committed(struct ptlrpc_request *req, int force);
1822
1823 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
1824                         struct ptlrpc_client *);
1825 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
1826
1827 int ptlrpc_queue_wait(struct ptlrpc_request *req);
1828 int ptlrpc_replay_req(struct ptlrpc_request *req);
1829 void ptlrpc_abort_inflight(struct obd_import *imp);
1830 void ptlrpc_abort_set(struct ptlrpc_request_set *set);
1831
1832 struct ptlrpc_request_set *ptlrpc_prep_set(void);
1833 struct ptlrpc_request_set *ptlrpc_prep_fcset(int max, set_producer_func func,
1834                                              void *arg);
1835 int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set);
1836 int ptlrpc_set_wait(struct ptlrpc_request_set *);
1837 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
1838 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
1839 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
1840
1841 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
1842 int ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
1843
1844 struct ptlrpc_request_pool *
1845 ptlrpc_init_rq_pool(int, int,
1846                     int (*populate_pool)(struct ptlrpc_request_pool *, int));
1847
1848 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
1849 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
1850                                             const struct req_format *format);
1851 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
1852                                                  struct ptlrpc_request_pool *,
1853                                                  const struct req_format *);
1854 void ptlrpc_request_free(struct ptlrpc_request *request);
1855 int ptlrpc_request_pack(struct ptlrpc_request *request,
1856                         __u32 version, int opcode);
1857 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *,
1858                                                  const struct req_format *,
1859                                                  __u32, int);
1860 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
1861                              __u32 version, int opcode, char **bufs,
1862                              struct ptlrpc_cli_ctx *ctx);
1863 void ptlrpc_req_finished(struct ptlrpc_request *request);
1864 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
1865 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp(struct ptlrpc_request *req,
1866                                               unsigned int nfrags,
1867                                               unsigned int max_brw,
1868                                               unsigned int type,
1869                                               unsigned int portal,
1870                                               const struct ptlrpc_bulk_frag_ops *ops);
1871
1872 int ptlrpc_prep_bulk_frag(struct ptlrpc_bulk_desc *desc,
1873                           void *frag, int len);
1874 void __ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
1875                              struct page *page, int pageoffset, int len,
1876                              int pin);
1877 static inline void ptlrpc_prep_bulk_page_pin(struct ptlrpc_bulk_desc *desc,
1878                                              struct page *page, int pageoffset,
1879                                              int len)
1880 {
1881         __ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 1);
1882 }
1883
1884 static inline void ptlrpc_prep_bulk_page_nopin(struct ptlrpc_bulk_desc *desc,
1885                                                struct page *page, int pageoffset,
1886                                                int len)
1887 {
1888         __ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 0);
1889 }
1890
1891 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
1892
1893 static inline void ptlrpc_release_bulk_page_pin(struct ptlrpc_bulk_desc *desc)
1894 {
1895         int i;
1896
1897         for (i = 0; i < desc->bd_iov_count ; i++)
1898                 put_page(BD_GET_KIOV(desc, i).bv_page);
1899 }
1900
1901 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
1902                                       struct obd_import *imp);
1903 __u64 ptlrpc_next_xid(void);
1904 __u64 ptlrpc_sample_next_xid(void);
1905 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
1906
1907 /* Set of routines to run a function in ptlrpcd context */
1908 void *ptlrpcd_alloc_work(struct obd_import *imp,
1909                          int (*cb)(const struct lu_env *, void *), void *data);
1910 void ptlrpcd_destroy_work(void *handler);
1911 int ptlrpcd_queue_work(void *handler);
1912
1913 /** @} */
1914 struct ptlrpc_service_buf_conf {
1915         /* nbufs is buffers # to allocate when growing the pool */
1916         unsigned int                    bc_nbufs;
1917         /* buffer size to post */
1918         unsigned int                    bc_buf_size;
1919         /* portal to listed for requests on */
1920         unsigned int                    bc_req_portal;
1921         /* portal of where to send replies to */
1922         unsigned int                    bc_rep_portal;
1923         /* maximum request size to be accepted for this service */
1924         unsigned int                    bc_req_max_size;
1925         /* maximum reply size this service can ever send */
1926         unsigned int                    bc_rep_max_size;
1927 };
1928
1929 struct ptlrpc_service_thr_conf {
1930         /* threadname should be 8 characters or less - 6 will be added on */
1931         char                            *tc_thr_name;
1932         /* threads increasing factor for each CPU */
1933         unsigned int                    tc_thr_factor;
1934         /* service threads # to start on each partition while initializing */
1935         unsigned int                    tc_nthrs_init;
1936         /*
1937          * low water of threads # upper-limit on each partition while running,
1938          * service availability may be impacted if threads number is lower
1939          * than this value. It can be ZERO if the service doesn't require
1940          * CPU affinity or there is only one partition.
1941          */
1942         unsigned int                    tc_nthrs_base;
1943         /* "soft" limit for total threads number */
1944         unsigned int                    tc_nthrs_max;
1945         /* user specified threads number, it will be validated due to
1946          * other members of this structure.
1947          */
1948         unsigned int                    tc_nthrs_user;
1949         /* set NUMA node affinity for service threads */
1950         unsigned int                    tc_cpu_affinity;
1951         /* Tags for lu_context associated with service thread */
1952         __u32                           tc_ctx_tags;
1953 };
1954
1955 struct ptlrpc_service_cpt_conf {
1956         struct cfs_cpt_table            *cc_cptable;
1957         /* string pattern to describe CPTs for a service */
1958         char                            *cc_pattern;
1959 };
1960
1961 struct ptlrpc_service_conf {
1962         /* service name */
1963         char                            *psc_name;
1964         /* soft watchdog timeout multiplifier to print stuck service traces */
1965         unsigned int                    psc_watchdog_factor;
1966         /* buffer information */
1967         struct ptlrpc_service_buf_conf  psc_buf;
1968         /* thread information */
1969         struct ptlrpc_service_thr_conf  psc_thr;
1970         /* CPU partition information */
1971         struct ptlrpc_service_cpt_conf  psc_cpt;
1972         /* function table */
1973         struct ptlrpc_service_ops       psc_ops;
1974 };
1975
1976 /* ptlrpc/service.c */
1977 /**
1978  * Server-side services API. Register/unregister service, request state
1979  * management, service thread management
1980  *
1981  * @{
1982  */
1983 void ptlrpc_dispatch_difficult_reply(struct ptlrpc_reply_state *rs);
1984 void ptlrpc_schedule_difficult_reply(struct ptlrpc_reply_state *rs);
1985 struct ptlrpc_service *ptlrpc_register_service(struct ptlrpc_service_conf *conf,
1986                                                struct kset *parent,
1987                                                struct dentry *debugfs_entry);
1988
1989 int ptlrpc_start_threads(struct ptlrpc_service *svc);
1990 int ptlrpc_unregister_service(struct ptlrpc_service *service);
1991
1992 int ptlrpc_hr_init(void);
1993 void ptlrpc_hr_fini(void);
1994
1995 /** @} */
1996
1997 /* ptlrpc/import.c */
1998 /**
1999  * Import API
2000  * @{
2001  */
2002 int ptlrpc_connect_import(struct obd_import *imp);
2003 int ptlrpc_init_import(struct obd_import *imp);
2004 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
2005 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
2006
2007 /* ptlrpc/pack_generic.c */
2008 int ptlrpc_reconnect_import(struct obd_import *imp);
2009 /** @} */
2010
2011 /**
2012  * ptlrpc msg buffer and swab interface
2013  *
2014  * @{
2015  */
2016 int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
2017                          u32 index);
2018 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
2019                             u32 index);
2020 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len);
2021 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len);
2022
2023 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
2024                         char **bufs);
2025 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
2026                         __u32 *lens, char **bufs);
2027 int lustre_pack_reply(struct ptlrpc_request *, int count, __u32 *lens,
2028                       char **bufs);
2029 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
2030                          __u32 *lens, char **bufs, int flags);
2031 #define LPRFL_EARLY_REPLY 1
2032 int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens,
2033                             char **bufs, int flags);
2034 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
2035                       unsigned int newlen, int move_data);
2036 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
2037 int __lustre_unpack_msg(struct lustre_msg *m, int len);
2038 u32 lustre_msg_hdr_size(__u32 magic, u32 count);
2039 u32 lustre_msg_size(__u32 magic, int count, __u32 *lengths);
2040 u32 lustre_msg_size_v2(int count, __u32 *lengths);
2041 u32 lustre_packed_msg_size(struct lustre_msg *msg);
2042 u32 lustre_msg_early_size(void);
2043 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, u32 n, u32 min_size);
2044 void *lustre_msg_buf(struct lustre_msg *m, u32 n, u32 minlen);
2045 u32 lustre_msg_buflen(struct lustre_msg *m, u32 n);
2046 u32 lustre_msg_bufcount(struct lustre_msg *m);
2047 char *lustre_msg_string(struct lustre_msg *m, u32 n, u32 max_len);
2048 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
2049 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
2050 __u32 lustre_msg_get_flags(struct lustre_msg *msg);
2051 void lustre_msg_add_flags(struct lustre_msg *msg, u32 flags);
2052 void lustre_msg_set_flags(struct lustre_msg *msg, u32 flags);
2053 void lustre_msg_clear_flags(struct lustre_msg *msg, u32 flags);
2054 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
2055 void lustre_msg_add_op_flags(struct lustre_msg *msg, u32 flags);
2056 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
2057 __u32 lustre_msg_get_type(struct lustre_msg *msg);
2058 void lustre_msg_add_version(struct lustre_msg *msg, u32 version);
2059 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
2060 __u16 lustre_msg_get_tag(struct lustre_msg *msg);
2061 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
2062 __u64 *lustre_msg_get_versions(struct lustre_msg *msg);
2063 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
2064 __u64 lustre_msg_get_slv(struct lustre_msg *msg);
2065 __u32 lustre_msg_get_limit(struct lustre_msg *msg);
2066 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
2067 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
2068 int lustre_msg_get_status(struct lustre_msg *msg);
2069 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
2070 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
2071 __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
2072 __u32 lustre_msg_get_service_time(struct lustre_msg *msg);
2073 __u32 lustre_msg_get_cksum(struct lustre_msg *msg);
2074 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
2075 void lustre_msg_set_handle(struct lustre_msg *msg,
2076                            struct lustre_handle *handle);
2077 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
2078 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
2079 void lustre_msg_set_last_xid(struct lustre_msg *msg, u64 last_xid);
2080 void lustre_msg_set_tag(struct lustre_msg *msg, __u16 tag);
2081 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions);
2082 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
2083 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
2084 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
2085 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
2086 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
2087 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
2088 void lustre_msg_set_jobid(struct lustre_msg *msg, char *jobid);
2089 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
2090 void lustre_msg_set_mbits(struct lustre_msg *msg, u64 mbits);
2091
2092 static inline void
2093 lustre_shrink_reply(struct ptlrpc_request *req, int segment,
2094                     unsigned int newlen, int move_data)
2095 {
2096         LASSERT(req->rq_reply_state);
2097         LASSERT(req->rq_repmsg);
2098         req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
2099                                            newlen, move_data);
2100 }
2101
2102 #ifdef CONFIG_LUSTRE_TRANSLATE_ERRNOS
2103
2104 static inline int ptlrpc_status_hton(int h)
2105 {
2106         /*
2107          * Positive errnos must be network errnos, such as LUSTRE_EDEADLK,
2108          * ELDLM_LOCK_ABORTED, etc.
2109          */
2110         if (h < 0)
2111                 return -lustre_errno_hton(-h);
2112         else
2113                 return h;
2114 }
2115
2116 static inline int ptlrpc_status_ntoh(int n)
2117 {
2118         /*
2119          * See the comment in ptlrpc_status_hton().
2120          */
2121         if (n < 0)
2122                 return -lustre_errno_ntoh(-n);
2123         else
2124                 return n;
2125 }
2126
2127 #else
2128
2129 #define ptlrpc_status_hton(h) (h)
2130 #define ptlrpc_status_ntoh(n) (n)
2131
2132 #endif
2133 /** @} */
2134
2135 /** Change request phase of \a req to \a new_phase */
2136 static inline void
2137 ptlrpc_rqphase_move(struct ptlrpc_request *req, enum rq_phase new_phase)
2138 {
2139         if (req->rq_phase == new_phase)
2140                 return;
2141
2142         if (new_phase == RQ_PHASE_UNREG_RPC ||
2143             new_phase == RQ_PHASE_UNREG_BULK) {
2144                 /* No embedded unregistering phases */
2145                 if (req->rq_phase == RQ_PHASE_UNREG_RPC ||
2146                     req->rq_phase == RQ_PHASE_UNREG_BULK)
2147                         return;
2148
2149                 req->rq_next_phase = req->rq_phase;
2150                 if (req->rq_import)
2151                         atomic_inc(&req->rq_import->imp_unregistering);
2152         }
2153
2154         if (req->rq_phase == RQ_PHASE_UNREG_RPC ||
2155             req->rq_phase == RQ_PHASE_UNREG_BULK) {
2156                 if (req->rq_import)
2157                         atomic_dec(&req->rq_import->imp_unregistering);
2158         }
2159
2160         DEBUG_REQ(D_INFO, req, "move req \"%s\" -> \"%s\"",
2161                   ptlrpc_rqphase2str(req), ptlrpc_phase2str(new_phase));
2162
2163         req->rq_phase = new_phase;
2164 }
2165
2166 /**
2167  * Returns true if request \a req got early reply and hard deadline is not met
2168  */
2169 static inline int
2170 ptlrpc_client_early(struct ptlrpc_request *req)
2171 {
2172         return req->rq_early;
2173 }
2174
2175 /**
2176  * Returns true if we got real reply from server for this request
2177  */
2178 static inline int
2179 ptlrpc_client_replied(struct ptlrpc_request *req)
2180 {
2181         if (req->rq_reply_deadline > ktime_get_real_seconds())
2182                 return 0;
2183         return req->rq_replied;
2184 }
2185
2186 /** Returns true if request \a req is in process of receiving server reply */
2187 static inline int
2188 ptlrpc_client_recv(struct ptlrpc_request *req)
2189 {
2190         if (req->rq_reply_deadline > ktime_get_real_seconds())
2191                 return 1;
2192         return req->rq_receiving_reply;
2193 }
2194
2195 static inline int
2196 ptlrpc_client_recv_or_unlink(struct ptlrpc_request *req)
2197 {
2198         int rc;
2199
2200         spin_lock(&req->rq_lock);
2201         if (req->rq_reply_deadline > ktime_get_real_seconds()) {
2202                 spin_unlock(&req->rq_lock);
2203                 return 1;
2204         }
2205         if (req->rq_req_deadline > ktime_get_real_seconds()) {
2206                 spin_unlock(&req->rq_lock);
2207                 return 1;
2208         }
2209         rc = !req->rq_req_unlinked || !req->rq_reply_unlinked ||
2210              req->rq_receiving_reply;
2211         spin_unlock(&req->rq_lock);
2212         return rc;
2213 }
2214
2215 static inline void
2216 ptlrpc_client_wake_req(struct ptlrpc_request *req)
2217 {
2218         if (!req->rq_set)
2219                 wake_up(&req->rq_reply_waitq);
2220         else
2221                 wake_up(&req->rq_set->set_waitq);
2222 }
2223
2224 static inline void
2225 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
2226 {
2227         LASSERT(atomic_read(&rs->rs_refcount) > 0);
2228         atomic_inc(&rs->rs_refcount);
2229 }
2230
2231 static inline void
2232 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
2233 {
2234         LASSERT(atomic_read(&rs->rs_refcount) > 0);
2235         if (atomic_dec_and_test(&rs->rs_refcount))
2236                 lustre_free_reply_state(rs);
2237 }
2238
2239 /* Should only be called once per req */
2240 static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
2241 {
2242         if (!req->rq_reply_state)
2243                 return; /* shouldn't occur */
2244         ptlrpc_rs_decref(req->rq_reply_state);
2245         req->rq_reply_state = NULL;
2246         req->rq_repmsg = NULL;
2247 }
2248
2249 static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
2250 {
2251         return lustre_msg_get_magic(req->rq_reqmsg);
2252 }
2253
2254 static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
2255 {
2256         switch (req->rq_reqmsg->lm_magic) {
2257         case LUSTRE_MSG_MAGIC_V2:
2258                 return req->rq_reqmsg->lm_repsize;
2259         default:
2260                 LASSERTF(0, "incorrect message magic: %08x\n",
2261                          req->rq_reqmsg->lm_magic);
2262                 return -EFAULT;
2263         }
2264 }
2265
2266 static inline int ptlrpc_send_limit_expired(struct ptlrpc_request *req)
2267 {
2268         if (req->rq_delay_limit != 0 &&
2269             time_before(cfs_time_add(req->rq_queued_time,
2270                                      cfs_time_seconds(req->rq_delay_limit)),
2271                         cfs_time_current())) {
2272                 return 1;
2273         }
2274         return 0;
2275 }
2276
2277 static inline int ptlrpc_no_resend(struct ptlrpc_request *req)
2278 {
2279         if (!req->rq_no_resend && ptlrpc_send_limit_expired(req)) {
2280                 spin_lock(&req->rq_lock);
2281                 req->rq_no_resend = 1;
2282                 spin_unlock(&req->rq_lock);
2283         }
2284         return req->rq_no_resend;
2285 }
2286
2287 static inline int
2288 ptlrpc_server_get_timeout(struct ptlrpc_service_part *svcpt)
2289 {
2290         int at = AT_OFF ? 0 : at_get(&svcpt->scp_at_estimate);
2291
2292         return svcpt->scp_service->srv_watchdog_factor *
2293                max_t(int, at, obd_timeout);
2294 }
2295
2296 static inline struct ptlrpc_service *
2297 ptlrpc_req2svc(struct ptlrpc_request *req)
2298 {
2299         return req->rq_rqbd->rqbd_svcpt->scp_service;
2300 }
2301
2302 /* ldlm/ldlm_lib.c */
2303 /**
2304  * Target client logic
2305  * @{
2306  */
2307 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
2308 int client_obd_cleanup(struct obd_device *obddev);
2309 int client_connect_import(const struct lu_env *env,
2310                           struct obd_export **exp, struct obd_device *obd,
2311                           struct obd_uuid *cluuid, struct obd_connect_data *,
2312                           void *localdata);
2313 int client_disconnect_export(struct obd_export *exp);
2314 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
2315                            int priority);
2316 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
2317 int client_import_find_conn(struct obd_import *imp, lnet_nid_t peer,
2318                             struct obd_uuid *uuid);
2319 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
2320 void client_destroy_import(struct obd_import *imp);
2321 /** @} */
2322
2323 /* ptlrpc/pinger.c */
2324 /**
2325  * Pinger API (client side only)
2326  * @{
2327  */
2328 enum timeout_event {
2329         TIMEOUT_GRANT = 1
2330 };
2331
2332 struct timeout_item;
2333 typedef int (*timeout_cb_t)(struct timeout_item *, void *);
2334 int ptlrpc_pinger_add_import(struct obd_import *imp);
2335 int ptlrpc_pinger_del_import(struct obd_import *imp);
2336 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
2337                               timeout_cb_t cb, void *data,
2338                               struct list_head *obd_list);
2339 int ptlrpc_del_timeout_client(struct list_head *obd_list,
2340                               enum timeout_event event);
2341 struct ptlrpc_request *ptlrpc_prep_ping(struct obd_import *imp);
2342 int ptlrpc_obd_ping(struct obd_device *obd);
2343 void ptlrpc_pinger_ir_up(void);
2344 void ptlrpc_pinger_ir_down(void);
2345 /** @} */
2346 int ptlrpc_pinger_suppress_pings(void);
2347
2348 /* ptlrpc/ptlrpcd.c */
2349 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force);
2350 void ptlrpcd_free(struct ptlrpcd_ctl *pc);
2351 void ptlrpcd_wake(struct ptlrpc_request *req);
2352 void ptlrpcd_add_req(struct ptlrpc_request *req);
2353 int ptlrpcd_addref(void);
2354 void ptlrpcd_decref(void);
2355
2356 /* ptlrpc/lproc_ptlrpc.c */
2357 /**
2358  * procfs output related functions
2359  * @{
2360  */
2361 const char *ll_opcode2str(__u32 opcode);
2362 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
2363 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
2364 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes);
2365 /** @} */
2366
2367 /* ptlrpc/llog_client.c */
2368 extern struct llog_operations llog_client_ops;
2369 /** @} net */
2370
2371 #endif
2372 /** @} PtlRPC */