4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2010, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 /** \defgroup PtlRPC Portal RPC and networking module.
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.
44 * PortalRPC utilizes LNet as its transport layer.
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>
65 #error Unsupported operating system.
68 #include <libcfs/libcfs.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>
79 #include <obd_support.h>
80 #include <lustre_ver.h>
82 /* MD flags we _always_ use */
83 #define PTLRPC_MD_OPTIONS 0
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)
93 /* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
95 # if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
96 # error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
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"
101 # if (PTLRPC_MAX_BRW_SIZE > LNET_MTU)
102 # error "PTLRPC_MAX_BRW_SIZE too big"
104 # if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV)
105 # error "PTLRPC_MAX_BRW_PAGES too big"
107 #endif /* __KERNEL__ */
109 #define PTLRPC_NTHRS_INIT 2
114 * Constants determine how memory is used to buffer incoming service requests.
116 * ?_NBUFS # buffers to allocate when growing the pool
117 * ?_BUFSIZE # bytes in a single request buffer
118 * ?_MAXREQSIZE # maximum request service will receive
120 * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
121 * of ?_NBUFS is added to the pool.
123 * Messages larger than ?_MAXREQSIZE are dropped. Request buffers are
124 * considered full when less than ?_MAXREQSIZE is left in them.
129 * Constants determine how threads are created for ptlrpc service.
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.
153 * #define MDS_NTHRS_INIT 2
154 * #define MDS_NTHRS_BASE 64
155 * #define MDS_NTHRS_FACTOR 8
156 * #define MDS_NTHRS_MAX 1024
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
163 * MDS_NTHRS_BASE(64) + cores(4) * MDS_NTHRS_FACTOR(8) = 96
165 * Total number of threads for the service is:
166 * 96 * partitions(4) = 384
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
173 * MDS_NTHRS_BASE(64) + cores(8) * MDS_NTHRS_FACTOR(8) = 128
175 * Total number of threads for the service is:
176 * 128 * partitions(4) = 512
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
183 * MDS_NTHRS_BASE(64) + cores(12) * MDS_NTHRS_FACTOR(8) = 160
185 * Total number of threads for the service is:
186 * 160 * partitions(8) = 1280
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
193 * ---------------------------------------------------------------------
194 * Server(C) have a thousand of cores and user configured it to 32 partitions
195 * MDS_NTHRS_BASE(64) * 32 = 2048
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.
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.
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
209 * b) bind service threads on a few partitions, see modparameters of
210 * MDS and OSS for details
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.
219 * LDLM threads constants:
221 * Given 8 as factor and 24 as base threads number
224 * On 4-core machine we will have 24 + 8 * 4 = 56 threads.
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.
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.
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
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)
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)
250 * MDS threads constants:
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.
255 #ifndef MDS_MAX_THREADS
256 #define MDS_MAX_THREADS 1024
257 #define MDS_MAX_OTHR_THREADS 256
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
264 #define MDS_MAX_OTHR_THREADS max(PTLRPC_NTHRS_INIT, MDS_MAX_THREADS / 2)
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)
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)
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)
285 /* non-affinity threads */
286 #define MDS_OTHR_NTHRS_INIT PTLRPC_NTHRS_INIT
287 #define MDS_OTHR_NTHRS_MAX MDS_MAX_OTHR_THREADS
289 #define MDS_NBUFS (64 * cfs_num_online_cpus())
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
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)
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.
308 #define MDS_MAXREPSIZE max(10 * 1024, 362 + LOV_MAX_STRIPE_COUNT * 56)
309 #define MDS_MAXREQSIZE MDS_MAXREPSIZE
311 /** MDS_BUFSIZE = max_reqsize + max sptlrpc payload size */
312 #define MDS_BUFSIZE (MDS_MAXREQSIZE + 1024)
314 /** FLD_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc */
315 #define FLD_MAXREQSIZE (160)
317 /** FLD_MAXREPSIZE == lustre_msg + ptlrpc_body */
318 #define FLD_MAXREPSIZE (152)
321 * SEQ_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + lu_range +
323 #define SEQ_MAXREQSIZE (160)
325 /** SEQ_MAXREPSIZE == lustre_msg + ptlrpc_body + lu_range */
326 #define SEQ_MAXREPSIZE (152)
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
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)
338 * OSS threads constants:
340 * Given 8 as factor and 64 as base threads number
343 * On 8-core server configured to 2 partitions, we will have
344 * 64 + 8 * 4 = 96 threads for each partition, 192 total threads.
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.
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.
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.
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
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
374 #define OST_NBUFS (64 * cfs_num_online_cpus())
375 #define OST_BUFSIZE (8 * 1024)
378 * OST_MAXREQSIZE ~= 4768 bytes =
379 * lustre_msg + obdo + 16 * obd_ioobj + 256 * niobuf_remote
381 * - single object with 16 pages is 512 bytes
382 * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
384 #define OST_MAXREQSIZE (5 * 1024)
385 #define OST_MAXREPSIZE (9 * 1024)
387 /* Macro to hide a typecast. */
388 #define ptlrpc_req_async_args(req) ((void *)&req->rq_async_args)
391 * Structure to single define portal connection.
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 */
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;
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 */
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 */
421 #define REQ_MAX_ACK_LOCKS 8
423 union ptlrpc_async_args {
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.
431 void *pointer_arg[11];
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 *);
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
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;
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.
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. */
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
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;
480 /** rq_status of requests that have been freed already */
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;
492 * Description of a single ptrlrpc_set callback
494 struct ptlrpc_set_cbdata {
495 /** List linkage item */
497 /** Pointer to interpreting function */
498 set_interpreter_func psc_interpret;
499 /** Opaq argument to pass to the callback */
503 struct ptlrpc_bulk_desc;
504 struct ptlrpc_service_part;
505 struct ptlrpc_service;
508 * ptlrpc callback & work item stuff
510 struct ptlrpc_cb_id {
511 void (*cbid_fn)(lnet_event_t *ev); /* specific callback fn */
512 void *cbid_arg; /* additional arg */
515 /** Maximum number of locks to fit into reply state */
516 #define RS_MAX_LOCKS 8
520 * Structure to define reply state on the server
521 * Reply state holds various reply message information. Also for "difficult"
522 * replies (rep-ack case) we store the state after sending reply and wait
523 * for the client to acknowledge the reception. In these cases locks could be
524 * added to the state for replay/failover consistency guarantees.
526 struct ptlrpc_reply_state {
527 /** Callback description */
528 struct ptlrpc_cb_id rs_cb_id;
529 /** Linkage for list of all reply states in a system */
531 /** Linkage for list of all reply states on same export */
532 cfs_list_t rs_exp_list;
533 /** Linkage for list of all reply states for same obd */
534 cfs_list_t rs_obd_list;
536 cfs_list_t rs_debug_list;
538 /** A spinlock to protect the reply state flags */
540 /** Reply state flags */
541 unsigned long rs_difficult:1; /* ACK/commit stuff */
542 unsigned long rs_no_ack:1; /* no ACK, even for
543 difficult requests */
544 unsigned long rs_scheduled:1; /* being handled? */
545 unsigned long rs_scheduled_ever:1;/* any schedule attempts? */
546 unsigned long rs_handled:1; /* been handled yet? */
547 unsigned long rs_on_net:1; /* reply_out_callback pending? */
548 unsigned long rs_prealloc:1; /* rs from prealloc list */
549 unsigned long rs_committed:1;/* the transaction was committed
550 and the rs was dispatched
551 by ptlrpc_commit_replies */
552 /** Size of the state */
556 /** Transaction number */
560 struct obd_export *rs_export;
561 struct ptlrpc_service_part *rs_svcpt;
562 /** Lnet metadata handle for the reply */
563 lnet_handle_md_t rs_md_h;
564 cfs_atomic_t rs_refcount;
566 /** Context for the sevice thread */
567 struct ptlrpc_svc_ctx *rs_svc_ctx;
568 /** Reply buffer (actually sent to the client), encoded if needed */
569 struct lustre_msg *rs_repbuf; /* wrapper */
570 /** Size of the reply buffer */
571 int rs_repbuf_len; /* wrapper buf length */
572 /** Size of the reply message */
573 int rs_repdata_len; /* wrapper msg length */
575 * Actual reply message. Its content is encrupted (if needed) to
576 * produce reply buffer for actual sending. In simple case
577 * of no network encryption we jus set \a rs_repbuf to \a rs_msg
579 struct lustre_msg *rs_msg; /* reply message */
581 /** Number of locks awaiting client ACK */
583 /** Handles of locks awaiting client reply ACK */
584 struct lustre_handle rs_locks[RS_MAX_LOCKS];
585 /** Lock modes of locks in \a rs_locks */
586 ldlm_mode_t rs_modes[RS_MAX_LOCKS];
589 struct ptlrpc_thread;
593 RQ_PHASE_NEW = 0xebc0de00,
594 RQ_PHASE_RPC = 0xebc0de01,
595 RQ_PHASE_BULK = 0xebc0de02,
596 RQ_PHASE_INTERPRET = 0xebc0de03,
597 RQ_PHASE_COMPLETE = 0xebc0de04,
598 RQ_PHASE_UNREGISTERING = 0xebc0de05,
599 RQ_PHASE_UNDEFINED = 0xebc0de06
602 /** Type of request interpreter call-back */
603 typedef int (*ptlrpc_interpterer_t)(const struct lu_env *env,
604 struct ptlrpc_request *req,
608 * Definition of request pool structure.
609 * The pool is used to store empty preallocated requests for the case
610 * when we would actually need to send something without performing
611 * any allocations (to avoid e.g. OOM).
613 struct ptlrpc_request_pool {
614 /** Locks the list */
616 /** list of ptlrpc_request structs */
617 cfs_list_t prp_req_list;
618 /** Maximum message size that would fit into a rquest from this pool */
620 /** Function to allocate more requests for this pool */
621 void (*prp_populate)(struct ptlrpc_request_pool *, int);
630 * \defgroup nrs Network Request Scheduler
633 struct ptlrpc_nrs_policy;
634 struct ptlrpc_nrs_resource;
635 struct ptlrpc_nrs_request;
638 * NRS control operations.
640 * These are common for all policies.
642 enum ptlrpc_nrs_ctl {
644 * Activate the policy.
646 PTLRPC_NRS_CTL_START,
648 * Reserved for multiple primary policies, which may be a possibility
653 * Recycle resources for inactive policies.
655 PTLRPC_NRS_CTL_SHRINK,
657 * Not a valid opcode.
659 PTLRPC_NRS_CTL_INVALID,
661 * Policies can start using opcodes from this value and onwards for
662 * their own purposes; the assigned value itself is arbitrary.
664 PTLRPC_NRS_CTL_1ST_POL_SPEC = 0x20,
668 * NRS policy operations.
670 * These determine the behaviour of a policy, and are called in response to
673 struct ptlrpc_nrs_pol_ops {
675 * Called during policy registration; this operation is optional.
677 * \param[in] policy The policy being initialized
679 int (*op_policy_init) (struct ptlrpc_nrs_policy *policy);
681 * Called during policy unregistration; this operation is optional.
683 * \param[in] policy The policy being unregistered/finalized
685 void (*op_policy_fini) (struct ptlrpc_nrs_policy *policy);
687 * Called when activating a policy via lprocfs; policies allocate and
688 * initialize their resources here; this operation is optional.
690 * \param[in] policy The policy being started
692 * \see nrs_policy_start_locked()
694 int (*op_policy_start) (struct ptlrpc_nrs_policy *policy);
696 * Called when deactivating a policy via lprocfs; policies deallocate
697 * their resources here; this operation is optional
699 * \param[in] policy The policy being stopped
701 * \see nrs_policy_stop_final()
703 void (*op_policy_stop) (struct ptlrpc_nrs_policy *policy);
705 * Used for policy-specific operations; i.e. not generic ones like
706 * \e PTLRPC_NRS_CTL_START and \e PTLRPC_NRS_CTL_GET_INFO; analogous
707 * to an ioctl; this operation is optional.
709 * \param[in] policy The policy carrying out operation \a opc
710 * \param[in] opc The command operation being carried out
711 * \param[in,out] arg An generic buffer for communication between the
712 * user and the control operation
717 * \see ptlrpc_nrs_policy_control()
719 int (*op_policy_ctl) (struct ptlrpc_nrs_policy *policy,
720 enum ptlrpc_nrs_ctl opc, void *arg);
723 * Called when obtaining references to the resources of the resource
724 * hierarchy for a request that has arrived for handling at the PTLRPC
725 * service. Policies should return -ve for requests they do not wish
726 * to handle. This operation is mandatory.
728 * \param[in] policy The policy we're getting resources for.
729 * \param[in] nrq The request we are getting resources for.
730 * \param[in] parent The parent resource of the resource being
731 * requested; set to NULL if none.
732 * \param[out] resp The resource is to be returned here; the
733 * fallback policy in an NRS head should
734 * \e always return a non-NULL pointer value.
735 * \param[in] moving_req When set, signifies that this is an attempt
736 * to obtain resources for a request being moved
737 * to the high-priority NRS head by
738 * ldlm_lock_reorder_req().
739 * This implies two things:
740 * 1. We are under obd_export::exp_rpc_lock and
741 * so should not sleep.
742 * 2. We should not perform non-idempotent or can
743 * skip performing idempotent operations that
744 * were carried out when resources were first
745 * taken for the request when it was initialized
746 * in ptlrpc_nrs_req_initialize().
748 * \retval 0, +ve The level of the returned resource in the resource
749 * hierarchy; currently only 0 (for a non-leaf resource)
750 * and 1 (for a leaf resource) are supported by the
754 * \see ptlrpc_nrs_req_initialize()
755 * \see ptlrpc_nrs_hpreq_add_nolock()
756 * \see ptlrpc_nrs_req_hp_move()
758 int (*op_res_get) (struct ptlrpc_nrs_policy *policy,
759 struct ptlrpc_nrs_request *nrq,
760 struct ptlrpc_nrs_resource *parent,
761 struct ptlrpc_nrs_resource **resp,
764 * Called when releasing references taken for resources in the resource
765 * hierarchy for the request; this operation is optional.
767 * \param[in] policy The policy the resource belongs to
768 * \param[in] res The resource to be freed
770 * \see ptlrpc_nrs_req_finalize()
771 * \see ptlrpc_nrs_hpreq_add_nolock()
772 * \see ptlrpc_nrs_req_hp_move()
774 void (*op_res_put) (struct ptlrpc_nrs_policy *policy,
775 struct ptlrpc_nrs_resource *res);
778 * Obtain a request for handling from the policy via polling; this
779 * operation is mandatory.
781 * \param[in] policy The policy to poll
783 * \retval NULL No erquest available for handling
784 * \retval valid-pointer The request polled for handling
786 * \see ptlrpc_nrs_req_poll_nolock()
788 struct ptlrpc_nrs_request *
789 (*op_req_poll) (struct ptlrpc_nrs_policy *policy);
791 * Called when attempting to add a request to a policy for later
792 * handling; this operation is mandatory.
794 * \param[in] policy The policy on which to enqueue \a nrq
795 * \param[in] nrq The request to enqueue
800 * \see ptlrpc_nrs_req_add_nolock()
802 int (*op_req_enqueue) (struct ptlrpc_nrs_policy *policy,
803 struct ptlrpc_nrs_request *nrq);
805 * Removes a request from the policy's set of pending requests. Normally
806 * called after a request has been polled successfully from the policy
807 * for handling; this operation is mandatory.
809 * \param[in] policy The policy the request \a nrq belongs to
810 * \param[in] nrq The request to dequeue
812 * \see ptlrpc_nrs_req_del_nolock()
814 void (*op_req_dequeue) (struct ptlrpc_nrs_policy *policy,
815 struct ptlrpc_nrs_request *nrq);
817 * Called before carrying out the request; should not block. Could be
818 * used for job/resource control; this operation is optional.
820 * \param[in] policy The policy which is starting to handle request
822 * \param[in] nrq The request
824 * \pre spin_is_locked(&svcpt->scp_req_lock)
826 * \see ptlrpc_nrs_req_start_nolock()
828 void (*op_req_start) (struct ptlrpc_nrs_policy *policy,
829 struct ptlrpc_nrs_request *nrq);
831 * Called after the request being carried out. Could be used for
832 * job/resource control; this operation is optional.
834 * \param[in] policy The policy which is stopping to handle request
836 * \param[in] nrq The request
838 * \pre spin_is_locked(&svcpt->scp_req_lock)
840 * \see ptlrpc_nrs_req_stop_nolock()
842 void (*op_req_stop) (struct ptlrpc_nrs_policy *policy,
843 struct ptlrpc_nrs_request *nrq);
845 * Registers the policy's lprocfs interface with a PTLRPC service.
847 * \param[in] svc The service
852 int (*op_lprocfs_init) (struct ptlrpc_service *svc);
854 * Unegisters the policy's lprocfs interface with a PTLRPC service.
856 * \param[in] svc The service
858 void (*op_lprocfs_fini) (struct ptlrpc_service *svc);
864 enum nrs_policy_flags {
866 * Fallback policy, use this flag only on a single supported policy per
867 * service. Do not use this flag for policies registering using
868 * ptlrpc_nrs_policy_register() (i.e. ones that are not in
869 * \e nrs_pols_builtin).
871 PTLRPC_NRS_FL_FALLBACK = (1 << 0),
873 * Start policy immediately after registering.
875 PTLRPC_NRS_FL_REG_START = (1 << 1),
877 * This is a polciy registering externally with NRS core, via
878 * ptlrpc_nrs_policy_register(), (i.e. one that is not in
879 * \e nrs_pols_builtin. Used to avoid ptlrpc_nrs_policy_register()
880 * racing with a policy start operation issued by the user via lprocfs.
882 PTLRPC_NRS_FL_REG_EXTERN = (1 << 2),
888 * Denotes whether an NRS instance is for handling normal or high-priority
889 * RPCs, or whether an operation pertains to one or both of the NRS instances
892 enum ptlrpc_nrs_queue_type {
893 PTLRPC_NRS_QUEUE_REG,
895 PTLRPC_NRS_QUEUE_BOTH,
901 * A PTLRPC service has at least one NRS head instance for handling normal
902 * priority RPCs, and may optionally have a second NRS head instance for
903 * handling high-priority RPCs. Each NRS head maintains a list of available
904 * policies, of which one and only one policy is acting as the fallback policy,
905 * and optionally a different policy may be acting as the primary policy. For
906 * all RPCs handled by this NRS head instance, NRS core will first attempt to
907 * enqueue the RPC using the primary policy (if any). The fallback policy is
908 * used in the following cases:
909 * - when there was no primary policy in the
910 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED state at the time the request
912 * - when the primary policy that was at the
913 * ptlrpc_nrs_pol_state::PTLRPC_NRS_POL_STATE_STARTED state at the time the
914 * RPC was initialized, denoted it did not wish, or for some other reason was
915 * not able to handle the request, by returning a non-valid NRS resource
917 * - when the primary policy that was at the
918 * ptlrpc_nrs_pol_state::PTLRPC_NRS_POL_STATE_STARTED state at the time the
919 * RPC was initialized, fails later during the request enqueueing stage.
921 * \see nrs_resource_get_safe()
922 * \see nrs_request_enqueue()
926 /** XXX Possibly replace svcpt->scp_req_lock with another lock here. */
928 * Linkage into nrs_core_heads_list
930 cfs_list_t nrs_heads;
932 * List of registered policies
934 cfs_list_t nrs_policy_list;
936 * List of policies with queued requests. Policies that have any
937 * outstanding requests are queued here, and this list is queried
938 * in a round-robin manner from NRS core when obtaining a request
939 * for handling. This ensures that requests from policies that at some
940 * point transition away from the
941 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED state are drained.
943 cfs_list_t nrs_policy_queued;
945 * Service partition for this NRS head
947 struct ptlrpc_service_part *nrs_svcpt;
949 * Primary policy, which is the preferred policy for handling RPCs
951 struct ptlrpc_nrs_policy *nrs_policy_primary;
953 * Fallback policy, which is the backup policy for handling RPCs
955 struct ptlrpc_nrs_policy *nrs_policy_fallback;
957 * This NRS head handles either HP or regular requests
959 enum ptlrpc_nrs_queue_type nrs_queue_type;
961 * # queued requests from all policies in this NRS head
963 unsigned long nrs_req_queued;
965 * # scheduled requests from all policies in this NRS head
967 unsigned long nrs_req_started;
969 * # policies on this NRS
970 * TODO: Can we avoid having this?
972 unsigned nrs_num_pols;
974 * This NRS head is in progress of starting a policy
976 unsigned nrs_policy_starting:1;
978 * In progress of shutting down the whole NRS head; used during
981 unsigned nrs_stopping:1;
984 #define NRS_POL_NAME_MAX 16
987 * NRS policy registering descriptor
989 * Is used to hold a description of a policy that can be passed to NRS core in
990 * order to register the policy with NRS heads in different PTLRPC services.
992 struct ptlrpc_nrs_pol_desc {
994 * Human-readable policy name
996 char pd_name[NRS_POL_NAME_MAX];
998 * NRS operations for this policy
1000 struct ptlrpc_nrs_pol_ops *pd_ops;
1002 * Service Compatibility function; this determines whether a policy is
1003 * adequate for handling RPCs of a particular PTLRPC service.
1005 * XXX:This should give the same result during policy
1006 * registration and unregistration, and for all partitions of a
1007 * service; so the result should not depend on temporal service
1008 * or other properties, that may influence the result.
1010 bool (*pd_compat) (struct ptlrpc_service *svc,
1011 const struct ptlrpc_nrs_pol_desc *desc);
1013 * Optionally set for policies that support a single ptlrpc service,
1014 * i.e. ones that have \a pd_compat set to nrs_policy_compat_one()
1016 char *pd_compat_svc_name;
1018 * Bitmask of nrs_policy_flags
1022 * Link into nrs_core::nrs_policies
1030 * Policies transition from one state to the other during their lifetime
1032 enum ptlrpc_nrs_pol_state {
1034 * Not a valid policy state.
1036 NRS_POL_STATE_INVALID,
1038 * For now, this state is used exclusively for policies that register
1039 * externally to NRS core, i.e. ones that do so via
1040 * ptlrpc_nrs_policy_register() and are not part of nrs_pols_builtin;
1041 * it is used to prevent a race condition between the policy registering
1042 * with more than one service partition while service is operational,
1043 * and the user starting the policy via lprocfs.
1045 * \see nrs_pol_make_avail()
1047 NRS_POL_STATE_UNAVAIL,
1049 * Policies are at this state either at the start of their life, or
1050 * transition here when the user selects a different policy to act
1051 * as the primary one.
1053 NRS_POL_STATE_STOPPED,
1055 * Policy is progress of stopping
1057 NRS_POL_STATE_STOPPING,
1059 * Policy is in progress of starting
1061 NRS_POL_STATE_STARTING,
1063 * A policy is in this state in two cases:
1064 * - it is the fallback policy, which is always in this state.
1065 * - it has been activated by the user; i.e. it is the primary policy,
1067 NRS_POL_STATE_STARTED,
1071 * NRS policy information
1073 * Used for obtaining information for the status of a policy via lprocfs
1075 struct ptlrpc_nrs_pol_info {
1079 char pi_name[NRS_POL_NAME_MAX];
1081 * Current policy state
1083 enum ptlrpc_nrs_pol_state pi_state;
1085 * # RPCs enqueued for later dispatching by the policy
1089 * # RPCs started for dispatch by the policy
1091 long pi_req_started;
1093 * Is this a fallback policy?
1095 unsigned pi_fallback:1;
1101 * There is one instance of this for each policy in each NRS head of each
1102 * PTLRPC service partition.
1104 struct ptlrpc_nrs_policy {
1106 * Linkage into the NRS head's list of policies,
1107 * ptlrpc_nrs:nrs_policy_list
1109 cfs_list_t pol_list;
1111 * Linkage into the NRS head's list of policies with enqueued
1112 * requests ptlrpc_nrs:nrs_policy_queued
1114 cfs_list_t pol_list_queued;
1116 * Current state of this policy
1118 enum ptlrpc_nrs_pol_state pol_state;
1120 * Bitmask of nrs_policy_flags
1124 * # RPCs enqueued for later dispatching by the policy
1126 long pol_req_queued;
1128 * # RPCs started for dispatch by the policy
1130 long pol_req_started;
1132 * Usage Reference count taken on the policy instance
1136 * The NRS head this policy has been created at
1138 struct ptlrpc_nrs *pol_nrs;
1140 * NRS operations for this policy; points to ptlrpc_nrs_pol_desc::pd_ops
1142 struct ptlrpc_nrs_pol_ops *pol_ops;
1144 * Private policy data; varies by policy type
1148 * Human-readable policy name; point to ptlrpc_nrs_pol_desc::pd_name
1156 * Resources are embedded into two types of NRS entities:
1157 * - Inside NRS policies, in the policy's private data in
1158 * ptlrpc_nrs_policy::pol_private
1159 * - In objects that act as prime-level scheduling entities in different NRS
1160 * policies; e.g. on a policy that performs round robin or similar order
1161 * scheduling across client NIDs, there would be one NRS resource per unique
1162 * client NID. On a policy which performs round robin scheduling across
1163 * backend filesystem objects, there would be one resource associated with
1164 * each of the backend filesystem objects partaking in the scheduling
1165 * performed by the policy.
1167 * NRS resources share a parent-child relationship, in which resources embedded
1168 * in policy instances are the parent entities, with all scheduling entities
1169 * a policy schedules across being the children, thus forming a simple resource
1170 * hierarchy. This hierarchy may be extended with one or more levels in the
1171 * future if the ability to have more than one primary policy is added.
1173 * Upon request initialization, references to the then active NRS policies are
1174 * taken and used to later handle the dispatching of the request with one of
1177 * \see nrs_resource_get_safe()
1178 * \see ptlrpc_nrs_req_add()
1180 struct ptlrpc_nrs_resource {
1182 * This NRS resource's parent; is NULL for resources embedded in NRS
1183 * policy instances; i.e. those are top-level ones.
1185 struct ptlrpc_nrs_resource *res_parent;
1187 * The policy associated with this resource.
1189 struct ptlrpc_nrs_policy *res_policy;
1202 * This policy is a logical wrapper around previous, non-NRS functionality.
1203 * It dispatches RPCs in the same order as they arrive from the network. This
1204 * policy is currently used as the fallback policy, and the only enabled policy
1205 * on all NRS heads of all PTLRPC service partitions.
1210 * Private data structure for the FIFO policy
1212 struct nrs_fifo_head {
1214 * Resource object for policy instance.
1216 struct ptlrpc_nrs_resource fh_res;
1218 * List of queued requests.
1222 * For debugging purposes.
1227 struct nrs_fifo_req {
1228 /** request header, must be the first member of structure */
1238 * Instances of this object exist embedded within ptlrpc_request; the main
1239 * purpose of this object is to hold references to the request's resources
1240 * for the lifetime of the request, and to hold properties that policies use
1241 * use for determining the request's scheduling priority.
1243 struct ptlrpc_nrs_request {
1245 * The request's resource hierarchy.
1247 struct ptlrpc_nrs_resource *nr_res_ptrs[NRS_RES_MAX];
1249 * Index into ptlrpc_nrs_request::nr_res_ptrs of the resource of the
1250 * policy that was used to enqueue the request.
1252 * \see nrs_request_enqueue()
1254 unsigned nr_res_idx;
1255 unsigned nr_initialized:1;
1256 unsigned nr_enqueued:1;
1257 unsigned nr_dequeued:1;
1258 unsigned nr_started:1;
1259 unsigned nr_finalized:1;
1260 cfs_binheap_node_t nr_node;
1263 * Policy-specific fields, used for determining a request's scheduling
1264 * priority, and other supporting functionality.
1268 * Fields for the FIFO policy
1270 struct nrs_fifo_req fifo;
1273 * Externally-registering policies may want to use this to allocate
1274 * their own request properties.
1282 * Basic request prioritization operations structure.
1283 * The whole idea is centered around locks and RPCs that might affect locks.
1284 * When a lock is contended we try to give priority to RPCs that might lead
1285 * to fastest release of that lock.
1286 * Currently only implemented for OSTs only in a way that makes all
1287 * IO and truncate RPCs that are coming from a locked region where a lock is
1288 * contended a priority over other requests.
1290 struct ptlrpc_hpreq_ops {
1292 * Check if the lock handle of the given lock is the same as
1293 * taken from the request.
1295 int (*hpreq_lock_match)(struct ptlrpc_request *, struct ldlm_lock *);
1297 * Check if the request is a high priority one.
1299 int (*hpreq_check)(struct ptlrpc_request *);
1301 * Called after the request has been handled.
1303 void (*hpreq_fini)(struct ptlrpc_request *);
1307 * Represents remote procedure call.
1309 * This is a staple structure used by everybody wanting to send a request
1312 struct ptlrpc_request {
1313 /* Request type: one of PTL_RPC_MSG_* */
1315 /** Result of request processing */
1318 * Linkage item through which this request is included into
1319 * sending/delayed lists on client and into rqbd list on server
1323 * Server side list of incoming unserved requests sorted by arrival
1324 * time. Traversed from time to time to notice about to expire
1325 * requests and sent back "early replies" to clients to let them
1326 * know server is alive and well, just very busy to service their
1329 cfs_list_t rq_timed_list;
1330 /** server-side history, used for debuging purposes. */
1331 cfs_list_t rq_history_list;
1332 /** server-side per-export list */
1333 cfs_list_t rq_exp_list;
1334 /** server-side hp handlers */
1335 struct ptlrpc_hpreq_ops *rq_ops;
1337 /** initial thread servicing this request */
1338 struct ptlrpc_thread *rq_svc_thread;
1340 /** history sequence # */
1341 __u64 rq_history_seq;
1345 /** stub for NRS request */
1346 struct ptlrpc_nrs_request rq_nrq;
1348 /** the index of service's srv_at_array into which request is linked */
1350 /** Lock to protect request flags and some other important bits, like
1354 /** client-side flags are serialized by rq_lock */
1355 unsigned int rq_intr:1, rq_replied:1, rq_err:1,
1356 rq_timedout:1, rq_resend:1, rq_restart:1,
1358 * when ->rq_replay is set, request is kept by the client even
1359 * after server commits corresponding transaction. This is
1360 * used for operations that require sequence of multiple
1361 * requests to be replayed. The only example currently is file
1362 * open/close. When last request in such a sequence is
1363 * committed, ->rq_replay is cleared on all requests in the
1367 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
1368 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
1369 rq_early:1, rq_must_unlink:1,
1370 rq_memalloc:1, /* req originated from "kswapd" */
1371 /* server-side flags */
1372 rq_packed_final:1, /* packed final reply */
1373 rq_hp:1, /* high priority RPC */
1374 rq_at_linked:1, /* link into service's srv_at_array */
1375 rq_reply_truncate:1,
1377 /* whether the "rq_set" is a valid one */
1379 rq_generation_set:1,
1380 /* do not resend request on -EINPROGRESS */
1381 rq_no_retry_einprogress:1,
1382 /* allow the req to be sent if the import is in recovery
1386 unsigned int rq_nr_resend;
1388 enum rq_phase rq_phase; /* one of RQ_PHASE_* */
1389 enum rq_phase rq_next_phase; /* one of RQ_PHASE_* to be used next */
1390 cfs_atomic_t rq_refcount;/* client-side refcount for SENT race,
1391 server-side refcounf for multiple replies */
1393 /** Portal to which this request would be sent */
1394 short rq_request_portal; /* XXX FIXME bug 249 */
1395 /** Portal where to wait for reply and where reply would be sent */
1396 short rq_reply_portal; /* XXX FIXME bug 249 */
1400 * !rq_truncate : # reply bytes actually received,
1401 * rq_truncate : required repbuf_len for resend
1403 int rq_nob_received;
1404 /** Request length */
1408 /** Request message - what client sent */
1409 struct lustre_msg *rq_reqmsg;
1410 /** Reply message - server response */
1411 struct lustre_msg *rq_repmsg;
1412 /** Transaction number */
1417 * List item to for replay list. Not yet commited requests get linked
1419 * Also see \a rq_replay comment above.
1421 cfs_list_t rq_replay_list;
1424 * security and encryption data
1426 struct ptlrpc_cli_ctx *rq_cli_ctx; /**< client's half ctx */
1427 struct ptlrpc_svc_ctx *rq_svc_ctx; /**< server's half ctx */
1428 cfs_list_t rq_ctx_chain; /**< link to waited ctx */
1430 struct sptlrpc_flavor rq_flvr; /**< for client & server */
1431 enum lustre_sec_part rq_sp_from;
1433 /* client/server security flags */
1435 rq_ctx_init:1, /* context initiation */
1436 rq_ctx_fini:1, /* context destroy */
1437 rq_bulk_read:1, /* request bulk read */
1438 rq_bulk_write:1, /* request bulk write */
1439 /* server authentication flags */
1440 rq_auth_gss:1, /* authenticated by gss */
1441 rq_auth_remote:1, /* authed as remote user */
1442 rq_auth_usr_root:1, /* authed as root */
1443 rq_auth_usr_mdt:1, /* authed as mdt */
1444 rq_auth_usr_ost:1, /* authed as ost */
1445 /* security tfm flags */
1448 /* doesn't expect reply FIXME */
1450 rq_pill_init:1; /* pill initialized */
1452 uid_t rq_auth_uid; /* authed uid */
1453 uid_t rq_auth_mapped_uid; /* authed uid mapped to */
1455 /* (server side), pointed directly into req buffer */
1456 struct ptlrpc_user_desc *rq_user_desc;
1458 /* various buffer pointers */
1459 struct lustre_msg *rq_reqbuf; /* req wrapper */
1460 char *rq_repbuf; /* rep buffer */
1461 struct lustre_msg *rq_repdata; /* rep wrapper msg */
1462 struct lustre_msg *rq_clrbuf; /* only in priv mode */
1463 int rq_reqbuf_len; /* req wrapper buf len */
1464 int rq_reqdata_len; /* req wrapper msg len */
1465 int rq_repbuf_len; /* rep buffer len */
1466 int rq_repdata_len; /* rep wrapper msg len */
1467 int rq_clrbuf_len; /* only in priv mode */
1468 int rq_clrdata_len; /* only in priv mode */
1470 /** early replies go to offset 0, regular replies go after that */
1471 unsigned int rq_reply_off;
1475 /** Fields that help to see if request and reply were swabbed or not */
1476 __u32 rq_req_swab_mask;
1477 __u32 rq_rep_swab_mask;
1479 /** What was import generation when this request was sent */
1480 int rq_import_generation;
1481 enum lustre_imp_state rq_send_state;
1483 /** how many early replies (for stats) */
1486 /** client+server request */
1487 lnet_handle_md_t rq_req_md_h;
1488 struct ptlrpc_cb_id rq_req_cbid;
1489 /** optional time limit for send attempts */
1490 cfs_duration_t rq_delay_limit;
1491 /** time request was first queued */
1492 cfs_time_t rq_queued_time;
1494 /* server-side... */
1495 /** request arrival time */
1496 struct timeval rq_arrival_time;
1497 /** separated reply state */
1498 struct ptlrpc_reply_state *rq_reply_state;
1499 /** incoming request buffer */
1500 struct ptlrpc_request_buffer_desc *rq_rqbd;
1502 /** client-only incoming reply */
1503 lnet_handle_md_t rq_reply_md_h;
1504 cfs_waitq_t rq_reply_waitq;
1505 struct ptlrpc_cb_id rq_reply_cbid;
1509 /** Peer description (the other side) */
1510 lnet_process_id_t rq_peer;
1511 /** Server-side, export on which request was received */
1512 struct obd_export *rq_export;
1513 /** Client side, import where request is being sent */
1514 struct obd_import *rq_import;
1516 /** Replay callback, called after request is replayed at recovery */
1517 void (*rq_replay_cb)(struct ptlrpc_request *);
1519 * Commit callback, called when request is committed and about to be
1522 void (*rq_commit_cb)(struct ptlrpc_request *);
1523 /** Opaq data for replay and commit callbacks. */
1526 /** For bulk requests on client only: bulk descriptor */
1527 struct ptlrpc_bulk_desc *rq_bulk;
1529 /** client outgoing req */
1531 * when request/reply sent (secs), or time when request should be sent
1534 /** time for request really sent out */
1535 time_t rq_real_sent;
1537 /** when request must finish. volatile
1538 * so that servers' early reply updates to the deadline aren't
1539 * kept in per-cpu cache */
1540 volatile time_t rq_deadline;
1541 /** when req reply unlink must finish. */
1542 time_t rq_reply_deadline;
1543 /** when req bulk unlink must finish. */
1544 time_t rq_bulk_deadline;
1546 * service time estimate (secs)
1547 * If the requestsis not served by this time, it is marked as timed out.
1551 /** Multi-rpc bits */
1552 /** Per-request waitq introduced by bug 21938 for recovery waiting */
1553 cfs_waitq_t rq_set_waitq;
1554 /** Link item for request set lists */
1555 cfs_list_t rq_set_chain;
1556 /** Link back to the request set */
1557 struct ptlrpc_request_set *rq_set;
1558 /** Async completion handler, called when reply is received */
1559 ptlrpc_interpterer_t rq_interpret_reply;
1560 /** Async completion context */
1561 union ptlrpc_async_args rq_async_args;
1563 /** Pool if request is from preallocated list */
1564 struct ptlrpc_request_pool *rq_pool;
1566 struct lu_context rq_session;
1567 struct lu_context rq_recov_session;
1569 /** request format description */
1570 struct req_capsule rq_pill;
1574 * Call completion handler for rpc if any, return it's status or original
1575 * rc if there was no handler defined for this request.
1577 static inline int ptlrpc_req_interpret(const struct lu_env *env,
1578 struct ptlrpc_request *req, int rc)
1580 if (req->rq_interpret_reply != NULL) {
1581 req->rq_status = req->rq_interpret_reply(env, req,
1582 &req->rq_async_args,
1584 return req->rq_status;
1592 int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_desc *desc);
1593 int ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_desc *desc);
1594 void ptlrpc_nrs_req_hp_move(struct ptlrpc_request *req);
1595 void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy,
1596 struct ptlrpc_nrs_pol_info *info);
1599 * Can the request be moved from the regular NRS head to the high-priority NRS
1600 * head (of the same PTLRPC service partition), if any?
1602 * For a reliable result, this should be checked under svcpt->scp_req lock.
1605 ptlrpc_nrs_req_can_move(struct ptlrpc_request *req)
1607 struct ptlrpc_nrs_request *nrq = &req->rq_nrq;
1610 * LU-898: Check ptlrpc_nrs_request::nr_enqueued to make sure the
1611 * request has been enqueued first, and ptlrpc_nrs_request::nr_started
1612 * to make sure it has not been scheduled yet (analogous to previous
1613 * (non-NRS) checking of !list_empty(&ptlrpc_request::rq_list).
1615 return nrq->nr_enqueued && !nrq->nr_started && !req->rq_hp;
1620 * Returns 1 if request buffer at offset \a index was already swabbed
1622 static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
1624 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
1625 return req->rq_req_swab_mask & (1 << index);
1629 * Returns 1 if request reply buffer at offset \a index was already swabbed
1631 static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
1633 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
1634 return req->rq_rep_swab_mask & (1 << index);
1638 * Returns 1 if request needs to be swabbed into local cpu byteorder
1640 static inline int ptlrpc_req_need_swab(struct ptlrpc_request *req)
1642 return lustre_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
1646 * Returns 1 if request reply needs to be swabbed into local cpu byteorder
1648 static inline int ptlrpc_rep_need_swab(struct ptlrpc_request *req)
1650 return lustre_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
1654 * Mark request buffer at offset \a index that it was already swabbed
1656 static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
1658 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
1659 LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
1660 req->rq_req_swab_mask |= 1 << index;
1664 * Mark request reply buffer at offset \a index that it was already swabbed
1666 static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
1668 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
1669 LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
1670 req->rq_rep_swab_mask |= 1 << index;
1674 * Convert numerical request phase value \a phase into text string description
1676 static inline const char *
1677 ptlrpc_phase2str(enum rq_phase phase)
1686 case RQ_PHASE_INTERPRET:
1688 case RQ_PHASE_COMPLETE:
1690 case RQ_PHASE_UNREGISTERING:
1691 return "Unregistering";
1698 * Convert numerical request phase of the request \a req into text stringi
1701 static inline const char *
1702 ptlrpc_rqphase2str(struct ptlrpc_request *req)
1704 return ptlrpc_phase2str(req->rq_phase);
1708 * Debugging functions and helpers to print request structure into debug log
1711 /* Spare the preprocessor, spoil the bugs. */
1712 #define FLAG(field, str) (field ? str : "")
1714 /** Convert bit flags into a string */
1715 #define DEBUG_REQ_FLAGS(req) \
1716 ptlrpc_rqphase2str(req), \
1717 FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"), \
1718 FLAG(req->rq_err, "E"), \
1719 FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"), \
1720 FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"), \
1721 FLAG(req->rq_no_resend, "N"), \
1722 FLAG(req->rq_waiting, "W"), \
1723 FLAG(req->rq_wait_ctx, "C"), FLAG(req->rq_hp, "H"), \
1724 FLAG(req->rq_committed, "M")
1726 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s%s%s"
1728 void _debug_req(struct ptlrpc_request *req,
1729 struct libcfs_debug_msg_data *data, const char *fmt, ...)
1730 __attribute__ ((format (printf, 3, 4)));
1733 * Helper that decides if we need to print request accordig to current debug
1736 #define debug_req(msgdata, mask, cdls, req, fmt, a...) \
1738 CFS_CHECK_STACK(msgdata, mask, cdls); \
1740 if (((mask) & D_CANTMASK) != 0 || \
1741 ((libcfs_debug & (mask)) != 0 && \
1742 (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) \
1743 _debug_req((req), msgdata, fmt, ##a); \
1747 * This is the debug print function you need to use to print request sturucture
1748 * content into lustre debug log.
1749 * for most callers (level is a constant) this is resolved at compile time */
1750 #define DEBUG_REQ(level, req, fmt, args...) \
1752 if ((level) & (D_ERROR | D_WARNING)) { \
1753 static cfs_debug_limit_state_t cdls; \
1754 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, level, &cdls); \
1755 debug_req(&msgdata, level, &cdls, req, "@@@ "fmt" ", ## args);\
1757 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, level, NULL); \
1758 debug_req(&msgdata, level, NULL, req, "@@@ "fmt" ", ## args); \
1764 * Structure that defines a single page of a bulk transfer
1766 struct ptlrpc_bulk_page {
1767 /** Linkage to list of pages in a bulk */
1770 * Number of bytes in a page to transfer starting from \a bp_pageoffset
1773 /** offset within a page */
1775 /** The page itself */
1776 struct page *bp_page;
1779 #define BULK_GET_SOURCE 0
1780 #define BULK_PUT_SINK 1
1781 #define BULK_GET_SINK 2
1782 #define BULK_PUT_SOURCE 3
1785 * Definition of buk descriptor.
1786 * Bulks are special "Two phase" RPCs where initial request message
1787 * is sent first and it is followed bt a transfer (o receiving) of a large
1788 * amount of data to be settled into pages referenced from the bulk descriptors.
1789 * Bulks transfers (the actual data following the small requests) are done
1790 * on separate LNet portals.
1791 * In lustre we use bulk transfers for READ and WRITE transfers from/to OSTs.
1792 * Another user is readpage for MDT.
1794 struct ptlrpc_bulk_desc {
1795 /** completed successfully */
1796 unsigned long bd_success:1;
1797 /** accessible to the network (network io potentially in progress) */
1798 unsigned long bd_network_rw:1;
1799 /** {put,get}{source,sink} */
1800 unsigned long bd_type:2;
1802 unsigned long bd_registered:1;
1803 /** For serialization with callback */
1805 /** Import generation when request for this bulk was sent */
1806 int bd_import_generation;
1807 /** Server side - export this bulk created for */
1808 struct obd_export *bd_export;
1809 /** Client side - import this bulk was sent on */
1810 struct obd_import *bd_import;
1811 /** LNet portal for this bulk */
1813 /** Back pointer to the request */
1814 struct ptlrpc_request *bd_req;
1815 cfs_waitq_t bd_waitq; /* server side only WQ */
1816 int bd_iov_count; /* # entries in bd_iov */
1817 int bd_max_iov; /* allocated size of bd_iov */
1818 int bd_nob; /* # bytes covered */
1819 int bd_nob_transferred; /* # bytes GOT/PUT */
1823 struct ptlrpc_cb_id bd_cbid; /* network callback info */
1824 lnet_handle_md_t bd_md_h; /* associated MD */
1825 lnet_nid_t bd_sender; /* stash event::sender */
1827 #if defined(__KERNEL__)
1829 * encrypt iov, size is either 0 or bd_iov_count.
1831 lnet_kiov_t *bd_enc_iov;
1833 lnet_kiov_t bd_iov[0];
1835 lnet_md_iovec_t bd_iov[0];
1840 SVC_STOPPED = 1 << 0,
1841 SVC_STOPPING = 1 << 1,
1842 SVC_STARTING = 1 << 2,
1843 SVC_RUNNING = 1 << 3,
1845 SVC_SIGNAL = 1 << 5,
1848 #define PTLRPC_THR_NAME_LEN 32
1850 * Definition of server service thread structure
1852 struct ptlrpc_thread {
1854 * List of active threads in svc->srv_threads
1858 * thread-private data (preallocated memory)
1863 * service thread index, from ptlrpc_start_threads
1867 * service thread pid
1871 * put watchdog in the structure per thread b=14840
1873 struct lc_watchdog *t_watchdog;
1875 * the svc this thread belonged to b=18582
1877 struct ptlrpc_service_part *t_svcpt;
1878 cfs_waitq_t t_ctl_waitq;
1879 struct lu_env *t_env;
1880 char t_name[PTLRPC_THR_NAME_LEN];
1883 static inline int thread_is_init(struct ptlrpc_thread *thread)
1885 return thread->t_flags == 0;
1888 static inline int thread_is_stopped(struct ptlrpc_thread *thread)
1890 return !!(thread->t_flags & SVC_STOPPED);
1893 static inline int thread_is_stopping(struct ptlrpc_thread *thread)
1895 return !!(thread->t_flags & SVC_STOPPING);
1898 static inline int thread_is_starting(struct ptlrpc_thread *thread)
1900 return !!(thread->t_flags & SVC_STARTING);
1903 static inline int thread_is_running(struct ptlrpc_thread *thread)
1905 return !!(thread->t_flags & SVC_RUNNING);
1908 static inline int thread_is_event(struct ptlrpc_thread *thread)
1910 return !!(thread->t_flags & SVC_EVENT);
1913 static inline int thread_is_signal(struct ptlrpc_thread *thread)
1915 return !!(thread->t_flags & SVC_SIGNAL);
1918 static inline void thread_clear_flags(struct ptlrpc_thread *thread, __u32 flags)
1920 thread->t_flags &= ~flags;
1923 static inline void thread_set_flags(struct ptlrpc_thread *thread, __u32 flags)
1925 thread->t_flags = flags;
1928 static inline void thread_add_flags(struct ptlrpc_thread *thread, __u32 flags)
1930 thread->t_flags |= flags;
1933 static inline int thread_test_and_clear_flags(struct ptlrpc_thread *thread,
1936 if (thread->t_flags & flags) {
1937 thread->t_flags &= ~flags;
1944 * Request buffer descriptor structure.
1945 * This is a structure that contains one posted request buffer for service.
1946 * Once data land into a buffer, event callback creates actual request and
1947 * notifies wakes one of the service threads to process new incoming request.
1948 * More than one request can fit into the buffer.
1950 struct ptlrpc_request_buffer_desc {
1951 /** Link item for rqbds on a service */
1952 cfs_list_t rqbd_list;
1953 /** History of requests for this buffer */
1954 cfs_list_t rqbd_reqs;
1955 /** Back pointer to service for which this buffer is registered */
1956 struct ptlrpc_service_part *rqbd_svcpt;
1957 /** LNet descriptor */
1958 lnet_handle_md_t rqbd_md_h;
1960 /** The buffer itself */
1962 struct ptlrpc_cb_id rqbd_cbid;
1964 * This "embedded" request structure is only used for the
1965 * last request to fit into the buffer
1967 struct ptlrpc_request rqbd_req;
1970 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
1972 struct ptlrpc_service_ops {
1974 * if non-NULL called during thread creation (ptlrpc_start_thread())
1975 * to initialize service specific per-thread state.
1977 int (*so_thr_init)(struct ptlrpc_thread *thr);
1979 * if non-NULL called during thread shutdown (ptlrpc_main()) to
1980 * destruct state created by ->srv_init().
1982 void (*so_thr_done)(struct ptlrpc_thread *thr);
1984 * Handler function for incoming requests for this service
1986 int (*so_req_handler)(struct ptlrpc_request *req);
1988 * function to determine priority of the request, it's called
1989 * on every new request
1991 int (*so_hpreq_handler)(struct ptlrpc_request *);
1993 * service-specific print fn
1995 void (*so_req_printer)(void *, struct ptlrpc_request *);
1998 #ifndef __cfs_cacheline_aligned
1999 /* NB: put it here for reducing patche dependence */
2000 # define __cfs_cacheline_aligned
2004 * How many high priority requests to serve before serving one normal
2007 #define PTLRPC_SVC_HP_RATIO 10
2010 * Definition of PortalRPC service.
2011 * The service is listening on a particular portal (like tcp port)
2012 * and perform actions for a specific server like IO service for OST
2013 * or general metadata service for MDS.
2015 struct ptlrpc_service {
2016 /** serialize /proc operations */
2017 spinlock_t srv_lock;
2018 /** most often accessed fields */
2019 /** chain thru all services */
2020 cfs_list_t srv_list;
2021 /** service operations table */
2022 struct ptlrpc_service_ops srv_ops;
2023 /** only statically allocated strings here; we don't clean them */
2025 /** only statically allocated strings here; we don't clean them */
2026 char *srv_thread_name;
2027 /** service thread list */
2028 cfs_list_t srv_threads;
2029 /** threads # should be created for each partition on initializing */
2030 int srv_nthrs_cpt_init;
2031 /** limit of threads number for each partition */
2032 int srv_nthrs_cpt_limit;
2033 /** Root of /proc dir tree for this service */
2034 cfs_proc_dir_entry_t *srv_procroot;
2035 /** Pointer to statistic data for this service */
2036 struct lprocfs_stats *srv_stats;
2037 /** # hp per lp reqs to handle */
2038 int srv_hpreq_ratio;
2039 /** biggest request to receive */
2040 int srv_max_req_size;
2041 /** biggest reply to send */
2042 int srv_max_reply_size;
2043 /** size of individual buffers */
2045 /** # buffers to allocate in 1 group */
2046 int srv_nbuf_per_group;
2047 /** Local portal on which to receive requests */
2048 __u32 srv_req_portal;
2049 /** Portal on the client to send replies to */
2050 __u32 srv_rep_portal;
2052 * Tags for lu_context associated with this thread, see struct
2056 /** soft watchdog timeout multiplier */
2057 int srv_watchdog_factor;
2058 /** under unregister_service */
2059 unsigned srv_is_stopping:1;
2061 /** max # request buffers in history per partition */
2062 int srv_hist_nrqbds_cpt_max;
2063 /** number of CPTs this service bound on */
2065 /** CPTs array this service bound on */
2067 /** 2^srv_cptab_bits >= cfs_cpt_numbert(srv_cptable) */
2069 /** CPT table this service is running over */
2070 struct cfs_cpt_table *srv_cptable;
2072 * partition data for ptlrpc service
2074 struct ptlrpc_service_part *srv_parts[0];
2078 * Definition of PortalRPC service partition data.
2079 * Although a service only has one instance of it right now, but we
2080 * will have multiple instances very soon (instance per CPT).
2082 * it has four locks:
2084 * serialize operations on rqbd and requests waiting for preprocess
2086 * serialize operations active requests sent to this portal
2088 * serialize adaptive timeout stuff
2090 * serialize operations on RS list (reply states)
2092 * We don't have any use-case to take two or more locks at the same time
2093 * for now, so there is no lock order issue.
2095 struct ptlrpc_service_part {
2096 /** back reference to owner */
2097 struct ptlrpc_service *scp_service __cfs_cacheline_aligned;
2098 /* CPT id, reserved */
2100 /** always increasing number */
2102 /** # of starting threads */
2103 int scp_nthrs_starting;
2104 /** # of stopping threads, reserved for shrinking threads */
2105 int scp_nthrs_stopping;
2106 /** # running threads */
2107 int scp_nthrs_running;
2108 /** service threads list */
2109 cfs_list_t scp_threads;
2112 * serialize the following fields, used for protecting
2113 * rqbd list and incoming requests waiting for preprocess,
2114 * threads starting & stopping are also protected by this lock.
2116 spinlock_t scp_lock __cfs_cacheline_aligned;
2117 /** total # req buffer descs allocated */
2118 int scp_nrqbds_total;
2119 /** # posted request buffers for receiving */
2120 int scp_nrqbds_posted;
2121 /** in progress of allocating rqbd */
2122 int scp_rqbd_allocating;
2123 /** # incoming reqs */
2124 int scp_nreqs_incoming;
2125 /** request buffers to be reposted */
2126 cfs_list_t scp_rqbd_idle;
2127 /** req buffers receiving */
2128 cfs_list_t scp_rqbd_posted;
2129 /** incoming reqs */
2130 cfs_list_t scp_req_incoming;
2131 /** timeout before re-posting reqs, in tick */
2132 cfs_duration_t scp_rqbd_timeout;
2134 * all threads sleep on this. This wait-queue is signalled when new
2135 * incoming request arrives and when difficult reply has to be handled.
2137 cfs_waitq_t scp_waitq;
2139 /** request history */
2140 cfs_list_t scp_hist_reqs;
2141 /** request buffer history */
2142 cfs_list_t scp_hist_rqbds;
2143 /** # request buffers in history */
2144 int scp_hist_nrqbds;
2145 /** sequence number for request */
2147 /** highest seq culled from history */
2148 __u64 scp_hist_seq_culled;
2151 * serialize the following fields, used for processing requests
2152 * sent to this portal
2154 spinlock_t scp_req_lock __cfs_cacheline_aligned;
2155 /** # reqs in either of the NRS heads below */
2156 /** # reqs being served */
2157 int scp_nreqs_active;
2158 /** # HPreqs being served */
2159 int scp_nhreqs_active;
2160 /** # hp requests handled */
2163 /** NRS head for regular requests */
2164 struct ptlrpc_nrs scp_nrs_reg;
2165 /** NRS head for HP requests; this is only valid for services that can
2166 * handle HP requests */
2167 struct ptlrpc_nrs *scp_nrs_hp;
2172 * serialize the following fields, used for changes on
2175 spinlock_t scp_at_lock __cfs_cacheline_aligned;
2176 /** estimated rpc service time */
2177 struct adaptive_timeout scp_at_estimate;
2178 /** reqs waiting for replies */
2179 struct ptlrpc_at_array scp_at_array;
2180 /** early reply timer */
2181 cfs_timer_t scp_at_timer;
2183 cfs_time_t scp_at_checktime;
2184 /** check early replies */
2185 unsigned scp_at_check;
2189 * serialize the following fields, used for processing
2190 * replies for this portal
2192 spinlock_t scp_rep_lock __cfs_cacheline_aligned;
2193 /** all the active replies */
2194 cfs_list_t scp_rep_active;
2196 /** replies waiting for service */
2197 cfs_list_t scp_rep_queue;
2199 /** List of free reply_states */
2200 cfs_list_t scp_rep_idle;
2201 /** waitq to run, when adding stuff to srv_free_rs_list */
2202 cfs_waitq_t scp_rep_waitq;
2203 /** # 'difficult' replies */
2204 cfs_atomic_t scp_nreps_difficult;
2207 #define ptlrpc_service_for_each_part(part, i, svc) \
2209 i < (svc)->srv_ncpts && \
2210 (svc)->srv_parts != NULL && \
2211 ((part) = (svc)->srv_parts[i]) != NULL; i++)
2214 * Declaration of ptlrpcd control structure
2216 struct ptlrpcd_ctl {
2218 * Ptlrpc thread control flags (LIOD_START, LIOD_STOP, LIOD_FORCE)
2220 unsigned long pc_flags;
2222 * Thread lock protecting structure fields.
2228 struct completion pc_starting;
2232 struct completion pc_finishing;
2234 * Thread requests set.
2236 struct ptlrpc_request_set *pc_set;
2238 * Thread name used in cfs_daemonize()
2242 * Environment for request interpreters to run in.
2244 struct lu_env pc_env;
2246 * Index of ptlrpcd thread in the array.
2250 * Number of the ptlrpcd's partners.
2254 * Pointer to the array of partners' ptlrpcd_ctl structure.
2256 struct ptlrpcd_ctl **pc_partners;
2258 * Record the partner index to be processed next.
2263 * Async rpcs flag to make sure that ptlrpcd_check() is called only
2268 * Currently not used.
2272 * User-space async rpcs callback.
2274 void *pc_wait_callback;
2276 * User-space check idle rpcs callback.
2278 void *pc_idle_callback;
2282 /* Bits for pc_flags */
2283 enum ptlrpcd_ctl_flags {
2285 * Ptlrpc thread start flag.
2287 LIOD_START = 1 << 0,
2289 * Ptlrpc thread stop flag.
2293 * Ptlrpc thread force flag (only stop force so far).
2294 * This will cause aborting any inflight rpcs handled
2295 * by thread if LIOD_STOP is specified.
2297 LIOD_FORCE = 1 << 2,
2299 * This is a recovery ptlrpc thread.
2301 LIOD_RECOVERY = 1 << 3,
2303 * The ptlrpcd is bound to some CPU core.
2312 * Service compatibility function; policy is compatible with all services.
2314 * \param[in] svc The service the policy is attempting to register with.
2315 * \param[in] desc The policy descriptor
2317 * \retval true The policy is compatible with the NRS head
2319 * \see ptlrpc_nrs_pol_desc::pd_compat()
2322 nrs_policy_compat_all(struct ptlrpc_service *svc,
2323 const struct ptlrpc_nrs_pol_desc *desc)
2329 * Service compatibility function; policy is compatible with only a specific
2330 * service which is identified by its human-readable name at
2331 * ptlrpc_service::srv_name.
2333 * \param[in] svc The service the policy is attempting to register with.
2334 * \param[in] desc The policy descriptor
2336 * \retval false The policy is not compatible with the NRS head
2337 * \retval true The policy is compatible with the NRS head
2339 * \see ptlrpc_nrs_pol_desc::pd_compat()
2342 nrs_policy_compat_one(struct ptlrpc_service *svc,
2343 const struct ptlrpc_nrs_pol_desc *desc)
2345 LASSERT(desc->pd_compat_svc_name != NULL);
2346 return strcmp(svc->srv_name, desc->pd_compat_svc_name) == 0;
2351 /* ptlrpc/events.c */
2352 extern lnet_handle_eq_t ptlrpc_eq_h;
2353 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
2354 lnet_process_id_t *peer, lnet_nid_t *self);
2356 * These callbacks are invoked by LNet when something happened to
2360 extern void request_out_callback(lnet_event_t *ev);
2361 extern void reply_in_callback(lnet_event_t *ev);
2362 extern void client_bulk_callback(lnet_event_t *ev);
2363 extern void request_in_callback(lnet_event_t *ev);
2364 extern void reply_out_callback(lnet_event_t *ev);
2365 #ifdef HAVE_SERVER_SUPPORT
2366 extern void server_bulk_callback(lnet_event_t *ev);
2370 /* ptlrpc/connection.c */
2371 struct ptlrpc_connection *ptlrpc_connection_get(lnet_process_id_t peer,
2373 struct obd_uuid *uuid);
2374 int ptlrpc_connection_put(struct ptlrpc_connection *c);
2375 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
2376 int ptlrpc_connection_init(void);
2377 void ptlrpc_connection_fini(void);
2378 extern lnet_pid_t ptl_get_pid(void);
2380 /* ptlrpc/niobuf.c */
2382 * Actual interfacing with LNet to put/get/register/unregister stuff
2385 #ifdef HAVE_SERVER_SUPPORT
2386 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
2387 int npages, int type, int portal);
2388 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
2389 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
2391 static inline int ptlrpc_server_bulk_active(struct ptlrpc_bulk_desc *desc)
2395 LASSERT(desc != NULL);
2397 spin_lock(&desc->bd_lock);
2398 rc = desc->bd_network_rw;
2399 spin_unlock(&desc->bd_lock);
2404 int ptlrpc_register_bulk(struct ptlrpc_request *req);
2405 int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async);
2407 static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req)
2409 struct ptlrpc_bulk_desc *desc;
2412 LASSERT(req != NULL);
2413 desc = req->rq_bulk;
2415 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) &&
2416 req->rq_bulk_deadline > cfs_time_current_sec())
2422 spin_lock(&desc->bd_lock);
2423 rc = desc->bd_network_rw;
2424 spin_unlock(&desc->bd_lock);
2428 #define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
2429 #define PTLRPC_REPLY_EARLY 0x02
2430 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
2431 int ptlrpc_reply(struct ptlrpc_request *req);
2432 int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
2433 int ptlrpc_error(struct ptlrpc_request *req);
2434 void ptlrpc_resend_req(struct ptlrpc_request *request);
2435 int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
2436 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
2437 int ptlrpc_register_rqbd(struct ptlrpc_request_buffer_desc *rqbd);
2440 /* ptlrpc/client.c */
2442 * Client-side portals API. Everything to send requests, receive replies,
2443 * request queues, request management, etc.
2446 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
2447 struct ptlrpc_client *);
2448 void ptlrpc_cleanup_client(struct obd_import *imp);
2449 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
2451 int ptlrpc_queue_wait(struct ptlrpc_request *req);
2452 int ptlrpc_replay_req(struct ptlrpc_request *req);
2453 int ptlrpc_unregister_reply(struct ptlrpc_request *req, int async);
2454 void ptlrpc_restart_req(struct ptlrpc_request *req);
2455 void ptlrpc_abort_inflight(struct obd_import *imp);
2456 void ptlrpc_cleanup_imp(struct obd_import *imp);
2457 void ptlrpc_abort_set(struct ptlrpc_request_set *set);
2459 struct ptlrpc_request_set *ptlrpc_prep_set(void);
2460 struct ptlrpc_request_set *ptlrpc_prep_fcset(int max, set_producer_func func,
2462 int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
2463 set_interpreter_func fn, void *data);
2464 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
2465 int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set);
2466 int ptlrpc_set_wait(struct ptlrpc_request_set *);
2467 int ptlrpc_expired_set(void *data);
2468 void ptlrpc_interrupted_set(void *data);
2469 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
2470 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
2471 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
2472 void ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
2473 struct ptlrpc_request *req);
2475 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
2476 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
2478 struct ptlrpc_request_pool *
2479 ptlrpc_init_rq_pool(int, int,
2480 void (*populate_pool)(struct ptlrpc_request_pool *, int));
2482 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
2483 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
2484 const struct req_format *format);
2485 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
2486 struct ptlrpc_request_pool *,
2487 const struct req_format *format);
2488 void ptlrpc_request_free(struct ptlrpc_request *request);
2489 int ptlrpc_request_pack(struct ptlrpc_request *request,
2490 __u32 version, int opcode);
2491 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
2492 const struct req_format *format,
2493 __u32 version, int opcode);
2494 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
2495 __u32 version, int opcode, char **bufs,
2496 struct ptlrpc_cli_ctx *ctx);
2497 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
2498 int opcode, int count, __u32 *lengths,
2500 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
2501 __u32 version, int opcode,
2502 int count, __u32 *lengths, char **bufs,
2503 struct ptlrpc_request_pool *pool);
2504 void ptlrpc_req_finished(struct ptlrpc_request *request);
2505 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
2506 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
2507 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp(struct ptlrpc_request *req,
2508 int npages, int type, int portal);
2509 void __ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk, int pin);
2510 static inline void ptlrpc_free_bulk_pin(struct ptlrpc_bulk_desc *bulk)
2512 __ptlrpc_free_bulk(bulk, 1);
2514 static inline void ptlrpc_free_bulk_nopin(struct ptlrpc_bulk_desc *bulk)
2516 __ptlrpc_free_bulk(bulk, 0);
2518 void __ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
2519 cfs_page_t *page, int pageoffset, int len, int);
2520 static inline void ptlrpc_prep_bulk_page_pin(struct ptlrpc_bulk_desc *desc,
2521 cfs_page_t *page, int pageoffset,
2524 __ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 1);
2527 static inline void ptlrpc_prep_bulk_page_nopin(struct ptlrpc_bulk_desc *desc,
2528 cfs_page_t *page, int pageoffset,
2531 __ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 0);
2534 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
2535 struct obd_import *imp);
2536 __u64 ptlrpc_next_xid(void);
2537 __u64 ptlrpc_sample_next_xid(void);
2538 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
2540 /* Set of routines to run a function in ptlrpcd context */
2541 void *ptlrpcd_alloc_work(struct obd_import *imp,
2542 int (*cb)(const struct lu_env *, void *), void *data);
2543 void ptlrpcd_destroy_work(void *handler);
2544 int ptlrpcd_queue_work(void *handler);
2547 struct ptlrpc_service_buf_conf {
2548 /* nbufs is how many buffers to post */
2549 unsigned int bc_nbufs;
2550 /* buffer size to post */
2551 unsigned int bc_buf_size;
2552 /* portal to listed for requests on */
2553 unsigned int bc_req_portal;
2554 /* portal of where to send replies to */
2555 unsigned int bc_rep_portal;
2556 /* maximum request size to be accepted for this service */
2557 unsigned int bc_req_max_size;
2558 /* maximum reply size this service can ever send */
2559 unsigned int bc_rep_max_size;
2562 struct ptlrpc_service_thr_conf {
2563 /* threadname should be 8 characters or less - 6 will be added on */
2565 /* threads increasing factor for each CPU */
2566 unsigned int tc_thr_factor;
2567 /* service threads # to start on each partition while initializing */
2568 unsigned int tc_nthrs_init;
2570 * low water of threads # upper-limit on each partition while running,
2571 * service availability may be impacted if threads number is lower
2572 * than this value. It can be ZERO if the service doesn't require
2573 * CPU affinity or there is only one partition.
2575 unsigned int tc_nthrs_base;
2576 /* "soft" limit for total threads number */
2577 unsigned int tc_nthrs_max;
2578 /* user specified threads number, it will be validated due to
2579 * other members of this structure. */
2580 unsigned int tc_nthrs_user;
2581 /* set NUMA node affinity for service threads */
2582 unsigned int tc_cpu_affinity;
2583 /* Tags for lu_context associated with service thread */
2587 struct ptlrpc_service_cpt_conf {
2588 struct cfs_cpt_table *cc_cptable;
2589 /* string pattern to describe CPTs for a service */
2593 struct ptlrpc_service_conf {
2596 /* soft watchdog timeout multiplifier to print stuck service traces */
2597 unsigned int psc_watchdog_factor;
2598 /* buffer information */
2599 struct ptlrpc_service_buf_conf psc_buf;
2600 /* thread information */
2601 struct ptlrpc_service_thr_conf psc_thr;
2602 /* CPU partition information */
2603 struct ptlrpc_service_cpt_conf psc_cpt;
2604 /* function table */
2605 struct ptlrpc_service_ops psc_ops;
2608 /* ptlrpc/service.c */
2610 * Server-side services API. Register/unregister service, request state
2611 * management, service thread management
2615 void ptlrpc_save_lock(struct ptlrpc_request *req,
2616 struct lustre_handle *lock, int mode, int no_ack);
2617 void ptlrpc_commit_replies(struct obd_export *exp);
2618 void ptlrpc_dispatch_difficult_reply(struct ptlrpc_reply_state *rs);
2619 void ptlrpc_schedule_difficult_reply(struct ptlrpc_reply_state *rs);
2620 int ptlrpc_hpreq_handler(struct ptlrpc_request *req);
2621 struct ptlrpc_service *ptlrpc_register_service(
2622 struct ptlrpc_service_conf *conf,
2623 struct proc_dir_entry *proc_entry);
2624 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
2626 int ptlrpc_start_threads(struct ptlrpc_service *svc);
2627 int ptlrpc_unregister_service(struct ptlrpc_service *service);
2628 int liblustre_check_services(void *arg);
2629 void ptlrpc_daemonize(char *name);
2630 int ptlrpc_service_health_check(struct ptlrpc_service *);
2631 void ptlrpc_server_drop_request(struct ptlrpc_request *req);
2634 int ptlrpc_hr_init(void);
2635 void ptlrpc_hr_fini(void);
2637 # define ptlrpc_hr_init() (0)
2638 # define ptlrpc_hr_fini() do {} while(0)
2643 /* ptlrpc/import.c */
2648 int ptlrpc_connect_import(struct obd_import *imp);
2649 int ptlrpc_init_import(struct obd_import *imp);
2650 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
2651 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
2652 void deuuidify(char *uuid, const char *prefix, char **uuid_start,
2655 /* ptlrpc/pack_generic.c */
2656 int ptlrpc_reconnect_import(struct obd_import *imp);
2660 * ptlrpc msg buffer and swab interface
2664 int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
2666 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
2668 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len);
2669 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len);
2671 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
2672 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
2674 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
2675 __u32 *lens, char **bufs);
2676 int lustre_pack_reply(struct ptlrpc_request *, int count, __u32 *lens,
2678 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
2679 __u32 *lens, char **bufs, int flags);
2680 #define LPRFL_EARLY_REPLY 1
2681 int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens,
2682 char **bufs, int flags);
2683 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
2684 unsigned int newlen, int move_data);
2685 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
2686 int __lustre_unpack_msg(struct lustre_msg *m, int len);
2687 int lustre_msg_hdr_size(__u32 magic, int count);
2688 int lustre_msg_size(__u32 magic, int count, __u32 *lengths);
2689 int lustre_msg_size_v2(int count, __u32 *lengths);
2690 int lustre_packed_msg_size(struct lustre_msg *msg);
2691 int lustre_msg_early_size(void);
2692 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
2693 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
2694 int lustre_msg_buflen(struct lustre_msg *m, int n);
2695 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
2696 int lustre_msg_bufcount(struct lustre_msg *m);
2697 char *lustre_msg_string(struct lustre_msg *m, int n, int max_len);
2698 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
2699 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
2700 __u32 lustre_msg_get_flags(struct lustre_msg *msg);
2701 void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
2702 void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
2703 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
2704 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
2705 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
2706 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
2707 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
2708 __u32 lustre_msg_get_type(struct lustre_msg *msg);
2709 __u32 lustre_msg_get_version(struct lustre_msg *msg);
2710 void lustre_msg_add_version(struct lustre_msg *msg, int version);
2711 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
2712 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
2713 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
2714 __u64 *lustre_msg_get_versions(struct lustre_msg *msg);
2715 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
2716 __u64 lustre_msg_get_slv(struct lustre_msg *msg);
2717 __u32 lustre_msg_get_limit(struct lustre_msg *msg);
2718 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
2719 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
2720 int lustre_msg_get_status(struct lustre_msg *msg);
2721 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
2722 int lustre_msg_is_v1(struct lustre_msg *msg);
2723 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
2724 __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
2725 __u32 lustre_msg_get_service_time(struct lustre_msg *msg);
2726 char *lustre_msg_get_jobid(struct lustre_msg *msg);
2727 __u32 lustre_msg_get_cksum(struct lustre_msg *msg);
2728 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
2729 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg, int compat18);
2731 # warning "remove checksum compatibility support for b1_8"
2732 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
2734 void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
2735 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
2736 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
2737 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
2738 void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed);
2739 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions);
2740 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
2741 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
2742 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
2743 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *sizes);
2744 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
2745 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
2746 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
2747 void lustre_msg_set_jobid(struct lustre_msg *msg, char *jobid);
2748 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
2751 lustre_shrink_reply(struct ptlrpc_request *req, int segment,
2752 unsigned int newlen, int move_data)
2754 LASSERT(req->rq_reply_state);
2755 LASSERT(req->rq_repmsg);
2756 req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
2761 /** Change request phase of \a req to \a new_phase */
2763 ptlrpc_rqphase_move(struct ptlrpc_request *req, enum rq_phase new_phase)
2765 if (req->rq_phase == new_phase)
2768 if (new_phase == RQ_PHASE_UNREGISTERING) {
2769 req->rq_next_phase = req->rq_phase;
2771 cfs_atomic_inc(&req->rq_import->imp_unregistering);
2774 if (req->rq_phase == RQ_PHASE_UNREGISTERING) {
2776 cfs_atomic_dec(&req->rq_import->imp_unregistering);
2779 DEBUG_REQ(D_INFO, req, "move req \"%s\" -> \"%s\"",
2780 ptlrpc_rqphase2str(req), ptlrpc_phase2str(new_phase));
2782 req->rq_phase = new_phase;
2786 * Returns true if request \a req got early reply and hard deadline is not met
2789 ptlrpc_client_early(struct ptlrpc_request *req)
2791 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
2792 req->rq_reply_deadline > cfs_time_current_sec())
2794 return req->rq_early;
2798 * Returns true if we got real reply from server for this request
2801 ptlrpc_client_replied(struct ptlrpc_request *req)
2803 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
2804 req->rq_reply_deadline > cfs_time_current_sec())
2806 return req->rq_replied;
2809 /** Returns true if request \a req is in process of receiving server reply */
2811 ptlrpc_client_recv(struct ptlrpc_request *req)
2813 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
2814 req->rq_reply_deadline > cfs_time_current_sec())
2816 return req->rq_receiving_reply;
2820 ptlrpc_client_recv_or_unlink(struct ptlrpc_request *req)
2824 spin_lock(&req->rq_lock);
2825 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
2826 req->rq_reply_deadline > cfs_time_current_sec()) {
2827 spin_unlock(&req->rq_lock);
2830 rc = req->rq_receiving_reply || req->rq_must_unlink;
2831 spin_unlock(&req->rq_lock);
2836 ptlrpc_client_wake_req(struct ptlrpc_request *req)
2838 if (req->rq_set == NULL)
2839 cfs_waitq_signal(&req->rq_reply_waitq);
2841 cfs_waitq_signal(&req->rq_set->set_waitq);
2845 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
2847 LASSERT(cfs_atomic_read(&rs->rs_refcount) > 0);
2848 cfs_atomic_inc(&rs->rs_refcount);
2852 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
2854 LASSERT(cfs_atomic_read(&rs->rs_refcount) > 0);
2855 if (cfs_atomic_dec_and_test(&rs->rs_refcount))
2856 lustre_free_reply_state(rs);
2859 /* Should only be called once per req */
2860 static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
2862 if (req->rq_reply_state == NULL)
2863 return; /* shouldn't occur */
2864 ptlrpc_rs_decref(req->rq_reply_state);
2865 req->rq_reply_state = NULL;
2866 req->rq_repmsg = NULL;
2869 static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
2871 return lustre_msg_get_magic(req->rq_reqmsg);
2874 static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
2876 switch (req->rq_reqmsg->lm_magic) {
2877 case LUSTRE_MSG_MAGIC_V2:
2878 return req->rq_reqmsg->lm_repsize;
2880 LASSERTF(0, "incorrect message magic: %08x\n",
2881 req->rq_reqmsg->lm_magic);
2886 static inline int ptlrpc_send_limit_expired(struct ptlrpc_request *req)
2888 if (req->rq_delay_limit != 0 &&
2889 cfs_time_before(cfs_time_add(req->rq_queued_time,
2890 cfs_time_seconds(req->rq_delay_limit)),
2891 cfs_time_current())) {
2897 static inline int ptlrpc_no_resend(struct ptlrpc_request *req)
2899 if (!req->rq_no_resend && ptlrpc_send_limit_expired(req)) {
2900 spin_lock(&req->rq_lock);
2901 req->rq_no_resend = 1;
2902 spin_unlock(&req->rq_lock);
2904 return req->rq_no_resend;
2908 ptlrpc_server_get_timeout(struct ptlrpc_service_part *svcpt)
2910 int at = AT_OFF ? 0 : at_get(&svcpt->scp_at_estimate);
2912 return svcpt->scp_service->srv_watchdog_factor *
2913 max_t(int, at, obd_timeout);
2916 static inline struct ptlrpc_service *
2917 ptlrpc_req2svc(struct ptlrpc_request *req)
2919 LASSERT(req->rq_rqbd != NULL);
2920 return req->rq_rqbd->rqbd_svcpt->scp_service;
2923 /* ldlm/ldlm_lib.c */
2925 * Target client logic
2928 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
2929 int client_obd_cleanup(struct obd_device *obddev);
2930 int client_connect_import(const struct lu_env *env,
2931 struct obd_export **exp, struct obd_device *obd,
2932 struct obd_uuid *cluuid, struct obd_connect_data *,
2934 int client_disconnect_export(struct obd_export *exp);
2935 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
2937 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
2938 int client_import_find_conn(struct obd_import *imp, lnet_nid_t peer,
2939 struct obd_uuid *uuid);
2940 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
2941 void client_destroy_import(struct obd_import *imp);
2944 #ifdef HAVE_SERVER_SUPPORT
2945 int server_disconnect_export(struct obd_export *exp);
2948 /* ptlrpc/pinger.c */
2950 * Pinger API (client side only)
2953 enum timeout_event {
2956 struct timeout_item;
2957 typedef int (*timeout_cb_t)(struct timeout_item *, void *);
2958 int ptlrpc_pinger_add_import(struct obd_import *imp);
2959 int ptlrpc_pinger_del_import(struct obd_import *imp);
2960 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
2961 timeout_cb_t cb, void *data,
2962 cfs_list_t *obd_list);
2963 int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
2964 enum timeout_event event);
2965 struct ptlrpc_request * ptlrpc_prep_ping(struct obd_import *imp);
2966 int ptlrpc_obd_ping(struct obd_device *obd);
2967 cfs_time_t ptlrpc_suspend_wakeup_time(void);
2969 void ping_evictor_start(void);
2970 void ping_evictor_stop(void);
2972 #define ping_evictor_start() do {} while (0)
2973 #define ping_evictor_stop() do {} while (0)
2975 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req);
2978 /* ptlrpc daemon bind policy */
2980 /* all ptlrpcd threads are free mode */
2981 PDB_POLICY_NONE = 1,
2982 /* all ptlrpcd threads are bound mode */
2983 PDB_POLICY_FULL = 2,
2984 /* <free1 bound1> <free2 bound2> ... <freeN boundN> */
2985 PDB_POLICY_PAIR = 3,
2986 /* <free1 bound1> <bound1 free2> ... <freeN boundN> <boundN free1>,
2987 * means each ptlrpcd[X] has two partners: thread[X-1] and thread[X+1].
2988 * If kernel supports NUMA, pthrpcd threads are binded and
2989 * grouped by NUMA node */
2990 PDB_POLICY_NEIGHBOR = 4,
2993 /* ptlrpc daemon load policy
2994 * It is caller's duty to specify how to push the async RPC into some ptlrpcd
2995 * queue, but it is not enforced, affected by "ptlrpcd_bind_policy". If it is
2996 * "PDB_POLICY_FULL", then the RPC will be processed by the selected ptlrpcd,
2997 * Otherwise, the RPC may be processed by the selected ptlrpcd or its partner,
2998 * depends on which is scheduled firstly, to accelerate the RPC processing. */
3000 /* on the same CPU core as the caller */
3001 PDL_POLICY_SAME = 1,
3002 /* within the same CPU partition, but not the same core as the caller */
3003 PDL_POLICY_LOCAL = 2,
3004 /* round-robin on all CPU cores, but not the same core as the caller */
3005 PDL_POLICY_ROUND = 3,
3006 /* the specified CPU core is preferred, but not enforced */
3007 PDL_POLICY_PREFERRED = 4,
3010 /* ptlrpc/ptlrpcd.c */
3011 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force);
3012 void ptlrpcd_wake(struct ptlrpc_request *req);
3013 void ptlrpcd_add_req(struct ptlrpc_request *req, pdl_policy_t policy, int idx);
3014 void ptlrpcd_add_rqset(struct ptlrpc_request_set *set);
3015 int ptlrpcd_addref(void);
3016 void ptlrpcd_decref(void);
3018 /* ptlrpc/lproc_ptlrpc.c */
3020 * procfs output related functions
3023 const char* ll_opcode2str(__u32 opcode);
3025 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
3026 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
3027 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes);
3029 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
3030 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
3031 static inline void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes) {}
3035 /* ptlrpc/llog_server.c */
3036 int llog_origin_handle_open(struct ptlrpc_request *req);
3037 int llog_origin_handle_destroy(struct ptlrpc_request *req);
3038 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
3039 int llog_origin_handle_next_block(struct ptlrpc_request *req);
3040 int llog_origin_handle_read_header(struct ptlrpc_request *req);
3041 int llog_origin_handle_close(struct ptlrpc_request *req);
3042 int llog_origin_handle_cancel(struct ptlrpc_request *req);
3044 /* ptlrpc/llog_client.c */
3045 extern struct llog_operations llog_client_ops;