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