1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
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 /* Size over which to OBD_VMALLOC() rather than OBD_ALLOC() service request
111 #define SVC_BUF_VMALLOC_THRESHOLD (2 * CFS_PAGE_SIZE)
114 * The following constants determine how memory is used to buffer incoming
117 * ?_NBUFS # buffers to allocate when growing the pool
118 * ?_BUFSIZE # bytes in a single request buffer
119 * ?_MAXREQSIZE # maximum request service will receive
121 * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
122 * of ?_NBUFS is added to the pool.
124 * Messages larger than ?_MAXREQSIZE are dropped. Request buffers are
125 * considered full when less than ?_MAXREQSIZE is left in them.
127 #define LDLM_THREADS_AUTO_MIN (2)
128 #define LDLM_THREADS_AUTO_MAX min_t(unsigned, cfs_num_online_cpus() * \
129 cfs_num_online_cpus() * 32, 128)
130 #define LDLM_BL_THREADS LDLM_THREADS_AUTO_MIN
131 #define LDLM_NBUFS (64 * cfs_num_online_cpus())
132 #define LDLM_BUFSIZE (8 * 1024)
133 #define LDLM_MAXREQSIZE (5 * 1024)
134 #define LDLM_MAXREPSIZE (1024)
136 #define MDT_MIN_THREADS 2UL
137 #define MDT_MAX_THREADS 512UL
138 #define MDT_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
139 cfs_num_physpages >> (25 - CFS_PAGE_SHIFT)), \
142 /** Absolute limits */
143 #define MDS_THREADS_MIN 2
144 #define MDS_THREADS_MAX 512
145 #define MDS_THREADS_MIN_READPAGE 2
146 #define MDS_NBUFS (64 * cfs_num_online_cpus())
147 #define MDS_BUFSIZE (8 * 1024)
149 * Assume file name length = FNAME_MAX = 256 (true for ext3).
150 * path name length = PATH_MAX = 4096
151 * LOV MD size max = EA_MAX = 4000
152 * symlink: FNAME_MAX + PATH_MAX <- largest
153 * link: FNAME_MAX + PATH_MAX (mds_rec_link < mds_rec_create)
154 * rename: FNAME_MAX + FNAME_MAX
155 * open: FNAME_MAX + EA_MAX
157 * MDS_MAXREQSIZE ~= 4736 bytes =
158 * lustre_msg + ldlm_request + mds_body + mds_rec_create + FNAME_MAX + PATH_MAX
159 * MDS_MAXREPSIZE ~= 8300 bytes = lustre_msg + llog_header
160 * or, for mds_close() and mds_reint_unlink() on a many-OST filesystem:
161 * = 9210 bytes = lustre_msg + mds_body + 160 * (easize + cookiesize)
163 * Realistic size is about 512 bytes (20 character name + 128 char symlink),
164 * except in the open case where there are a large number of OSTs in a LOV.
166 #define MDS_MAXREQSIZE (5 * 1024)
167 #define MDS_MAXREPSIZE max(9 * 1024, 362 + LOV_MAX_STRIPE_COUNT * 56)
169 /** FLD_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + md_fld */
170 #define FLD_MAXREQSIZE (160)
172 /** FLD_MAXREPSIZE == lustre_msg + ptlrpc_body + md_fld */
173 #define FLD_MAXREPSIZE (152)
176 * SEQ_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + lu_range +
178 #define SEQ_MAXREQSIZE (160)
180 /** SEQ_MAXREPSIZE == lustre_msg + ptlrpc_body + lu_range */
181 #define SEQ_MAXREPSIZE (152)
183 /** MGS threads must be >= 3, see bug 22458 comment #28 */
184 #define MGS_THREADS_AUTO_MIN 3
185 #define MGS_THREADS_AUTO_MAX 32
186 #define MGS_NBUFS (64 * cfs_num_online_cpus())
187 #define MGS_BUFSIZE (8 * 1024)
188 #define MGS_MAXREQSIZE (7 * 1024)
189 #define MGS_MAXREPSIZE (9 * 1024)
191 /** Absolute OSS limits */
192 #define OSS_THREADS_MIN 3 /* difficult replies, HPQ, others */
193 #define OSS_THREADS_MAX 512
194 #define OST_NBUFS (64 * cfs_num_online_cpus())
195 #define OST_BUFSIZE (8 * 1024)
198 * OST_MAXREQSIZE ~= 4768 bytes =
199 * lustre_msg + obdo + 16 * obd_ioobj + 256 * niobuf_remote
201 * - single object with 16 pages is 512 bytes
202 * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
204 #define OST_MAXREQSIZE (5 * 1024)
205 #define OST_MAXREPSIZE (9 * 1024)
207 /* Macro to hide a typecast. */
208 #define ptlrpc_req_async_args(req) ((void *)&req->rq_async_args)
211 * Structure to single define portal connection.
213 struct ptlrpc_connection {
214 /** linkage for connections hash table */
215 cfs_hlist_node_t c_hash;
216 /** Our own lnet nid for this connection */
218 /** Remote side nid for this connection */
219 lnet_process_id_t c_peer;
220 /** UUID of the other side */
221 struct obd_uuid c_remote_uuid;
222 /** reference counter for this connection */
223 cfs_atomic_t c_refcount;
226 /** Client definition for PortalRPC */
227 struct ptlrpc_client {
228 /** What lnet portal does this client send messages to by default */
229 __u32 cli_request_portal;
230 /** What portal do we expect replies on */
231 __u32 cli_reply_portal;
232 /** Name of the client */
236 /** state flags of requests */
237 /* XXX only ones left are those used by the bulk descs as well! */
238 #define PTL_RPC_FL_INTR (1 << 0) /* reply wait was interrupted by user */
239 #define PTL_RPC_FL_TIMEOUT (1 << 7) /* request timed out waiting for reply */
241 #define REQ_MAX_ACK_LOCKS 8
243 union ptlrpc_async_args {
245 * Scratchpad for passing args to completion interpreter. Users
246 * cast to the struct of their choosing, and LASSERT that this is
247 * big enough. For _tons_ of context, OBD_ALLOC a struct and store
248 * a pointer to it here. The pointer_arg ensures this struct is at
249 * least big enough for that.
251 void *pointer_arg[11];
255 struct ptlrpc_request_set;
256 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
259 * Definition of request set structure.
260 * Request set is a list of requests (not necessary to the same target) that
261 * once populated with RPCs could be sent in parallel.
262 * There are two kinds of request sets. General purpose and with dedicated
263 * serving thread. Example of the latter is ptlrpcd set.
264 * For general purpose sets once request set started sending it is impossible
265 * to add new requests to such set.
266 * Provides a way to call "completion callbacks" when all requests in the set
269 struct ptlrpc_request_set {
270 /** number of uncompleted requests */
271 cfs_atomic_t set_remaining;
272 /** wait queue to wait on for request events */
273 cfs_waitq_t set_waitq;
274 cfs_waitq_t *set_wakeup_ptr;
275 /** List of requests in the set */
276 cfs_list_t set_requests;
278 * List of completion callbacks to be called when the set is completed
279 * This is only used if \a set_interpret is NULL.
280 * Links struct ptlrpc_set_cbdata.
282 cfs_list_t set_cblist;
283 /** Completion callback, if only one. */
284 set_interpreter_func set_interpret;
285 /** opaq argument passed to completion \a set_interpret callback. */
288 * Lock for \a set_new_requests manipulations
289 * locked so that any old caller can communicate requests to
290 * the set holder who can then fold them into the lock-free set
292 cfs_spinlock_t set_new_req_lock;
293 /** List of new yet unsent requests. Only used with ptlrpcd now. */
294 cfs_list_t set_new_requests;
298 * Description of a single ptrlrpc_set callback
300 struct ptlrpc_set_cbdata {
301 /** List linkage item */
303 /** Pointer to interpreting function */
304 set_interpreter_func psc_interpret;
305 /** Opaq argument to pass to the callback */
309 struct ptlrpc_bulk_desc;
312 * ptlrpc callback & work item stuff
314 struct ptlrpc_cb_id {
315 void (*cbid_fn)(lnet_event_t *ev); /* specific callback fn */
316 void *cbid_arg; /* additional arg */
319 /** Maximum number of locks to fit into reply state */
320 #define RS_MAX_LOCKS 8
324 * Structure to define reply state on the server
325 * Reply state holds various reply message information. Also for "difficult"
326 * replies (rep-ack case) we store the state after sending reply and wait
327 * for the client to acknowledge the reception. In these cases locks could be
328 * added to the state for replay/failover consistency guarantees.
330 struct ptlrpc_reply_state {
331 /** Callback description */
332 struct ptlrpc_cb_id rs_cb_id;
333 /** Linkage for list of all reply states in a system */
335 /** Linkage for list of all reply states on same export */
336 cfs_list_t rs_exp_list;
337 /** Linkage for list of all reply states for same obd */
338 cfs_list_t rs_obd_list;
340 cfs_list_t rs_debug_list;
342 /** A spinlock to protect the reply state flags */
343 cfs_spinlock_t rs_lock;
344 /** Reply state flags */
345 unsigned long rs_difficult:1; /* ACK/commit stuff */
346 unsigned long rs_no_ack:1; /* no ACK, even for
347 difficult requests */
348 unsigned long rs_scheduled:1; /* being handled? */
349 unsigned long rs_scheduled_ever:1;/* any schedule attempts? */
350 unsigned long rs_handled:1; /* been handled yet? */
351 unsigned long rs_on_net:1; /* reply_out_callback pending? */
352 unsigned long rs_prealloc:1; /* rs from prealloc list */
353 unsigned long rs_committed:1;/* the transaction was committed
354 and the rs was dispatched
355 by ptlrpc_commit_replies */
356 /** Size of the state */
360 /** Transaction number */
364 struct obd_export *rs_export;
365 struct ptlrpc_service *rs_service;
366 /** Lnet metadata handle for the reply */
367 lnet_handle_md_t rs_md_h;
368 cfs_atomic_t rs_refcount;
370 /** Context for the sevice thread */
371 struct ptlrpc_svc_ctx *rs_svc_ctx;
372 /** Reply buffer (actually sent to the client), encoded if needed */
373 struct lustre_msg *rs_repbuf; /* wrapper */
374 /** Size of the reply buffer */
375 int rs_repbuf_len; /* wrapper buf length */
376 /** Size of the reply message */
377 int rs_repdata_len; /* wrapper msg length */
379 * Actual reply message. Its content is encrupted (if needed) to
380 * produce reply buffer for actual sending. In simple case
381 * of no network encryption we jus set \a rs_repbuf to \a rs_msg
383 struct lustre_msg *rs_msg; /* reply message */
385 /** Number of locks awaiting client ACK */
387 /** Handles of locks awaiting client reply ACK */
388 struct lustre_handle rs_locks[RS_MAX_LOCKS];
389 /** Lock modes of locks in \a rs_locks */
390 ldlm_mode_t rs_modes[RS_MAX_LOCKS];
393 struct ptlrpc_thread;
397 RQ_PHASE_NEW = 0xebc0de00,
398 RQ_PHASE_RPC = 0xebc0de01,
399 RQ_PHASE_BULK = 0xebc0de02,
400 RQ_PHASE_INTERPRET = 0xebc0de03,
401 RQ_PHASE_COMPLETE = 0xebc0de04,
402 RQ_PHASE_UNREGISTERING = 0xebc0de05,
403 RQ_PHASE_UNDEFINED = 0xebc0de06
406 /** Type of request interpreter call-back */
407 typedef int (*ptlrpc_interpterer_t)(const struct lu_env *env,
408 struct ptlrpc_request *req,
412 * Definition of request pool structure.
413 * The pool is used to store empty preallocated requests for the case
414 * when we would actually need to send something without performing
415 * any allocations (to avoid e.g. OOM).
417 struct ptlrpc_request_pool {
418 /** Locks the list */
419 cfs_spinlock_t prp_lock;
420 /** list of ptlrpc_request structs */
421 cfs_list_t prp_req_list;
422 /** Maximum message size that would fit into a rquest from this pool */
424 /** Function to allocate more requests for this pool */
425 void (*prp_populate)(struct ptlrpc_request_pool *, int);
434 * Basic request prioritization operations structure.
435 * The whole idea is centered around locks and RPCs that might affect locks.
436 * When a lock is contended we try to give priority to RPCs that might lead
437 * to fastest release of that lock.
438 * Currently only implemented for OSTs only in a way that makes all
439 * IO and truncate RPCs that are coming from a locked region where a lock is
440 * contended a priority over other requests.
442 struct ptlrpc_hpreq_ops {
444 * Check if the lock handle of the given lock is the same as
445 * taken from the request.
447 int (*hpreq_lock_match)(struct ptlrpc_request *, struct ldlm_lock *);
449 * Check if the request is a high priority one.
451 int (*hpreq_check)(struct ptlrpc_request *);
455 * Represents remote procedure call.
457 * This is a staple structure used by everybody wanting to send a request
460 struct ptlrpc_request {
461 /* Request type: one of PTL_RPC_MSG_* */
464 * Linkage item through which this request is included into
465 * sending/delayed lists on client and into rqbd list on server
469 * Server side list of incoming unserved requests sorted by arrival
470 * time. Traversed from time to time to notice about to expire
471 * requests and sent back "early replies" to clients to let them
472 * know server is alive and well, just very busy to service their
475 cfs_list_t rq_timed_list;
476 /** server-side history, used for debuging purposes. */
477 cfs_list_t rq_history_list;
478 /** server-side per-export list */
479 cfs_list_t rq_exp_list;
480 /** server-side hp handlers */
481 struct ptlrpc_hpreq_ops *rq_ops;
482 /** history sequence # */
483 __u64 rq_history_seq;
484 /** the index of service's srv_at_array into which request is linked */
486 /** Result of request processing */
488 /** Lock to protect request flags and some other important bits, like
491 cfs_spinlock_t rq_lock;
492 /** client-side flags are serialized by rq_lock */
493 unsigned long rq_intr:1, rq_replied:1, rq_err:1,
494 rq_timedout:1, rq_resend:1, rq_restart:1,
496 * when ->rq_replay is set, request is kept by the client even
497 * after server commits corresponding transaction. This is
498 * used for operations that require sequence of multiple
499 * requests to be replayed. The only example currently is file
500 * open/close. When last request in such a sequence is
501 * committed, ->rq_replay is cleared on all requests in the
505 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
506 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
507 rq_early:1, rq_must_unlink:1,
508 rq_fake:1, /* this fake req */
509 rq_memalloc:1, /* req originated from "kswapd" */
510 /* server-side flags */
511 rq_packed_final:1, /* packed final reply */
512 rq_hp:1, /* high priority RPC */
513 rq_at_linked:1, /* link into service's srv_at_array */
516 /* whether the "rq_set" is a valid one */
519 enum rq_phase rq_phase; /* one of RQ_PHASE_* */
520 enum rq_phase rq_next_phase; /* one of RQ_PHASE_* to be used next */
521 cfs_atomic_t rq_refcount;/* client-side refcount for SENT race,
522 server-side refcounf for multiple replies */
524 /** initial thread servicing this request */
525 struct ptlrpc_thread *rq_svc_thread;
527 /** Portal to which this request would be sent */
528 int rq_request_portal; /* XXX FIXME bug 249 */
529 /** Portal where to wait for reply and where reply would be sent */
530 int rq_reply_portal; /* XXX FIXME bug 249 */
534 * !rq_truncate : # reply bytes actually received,
535 * rq_truncate : required repbuf_len for resend
538 /** Request length */
540 /** Request message - what client sent */
541 struct lustre_msg *rq_reqmsg;
545 /** Reply message - server response */
546 struct lustre_msg *rq_repmsg;
547 /** Transaction number */
552 * List item to for replay list. Not yet commited requests get linked
554 * Also see \a rq_replay comment above.
556 cfs_list_t rq_replay_list;
559 * security and encryption data
561 struct ptlrpc_cli_ctx *rq_cli_ctx; /**< client's half ctx */
562 struct ptlrpc_svc_ctx *rq_svc_ctx; /**< server's half ctx */
563 cfs_list_t rq_ctx_chain; /**< link to waited ctx */
565 struct sptlrpc_flavor rq_flvr; /**< for client & server */
566 enum lustre_sec_part rq_sp_from;
568 unsigned long /* client/server security flags */
569 rq_ctx_init:1, /* context initiation */
570 rq_ctx_fini:1, /* context destroy */
571 rq_bulk_read:1, /* request bulk read */
572 rq_bulk_write:1, /* request bulk write */
573 /* server authentication flags */
574 rq_auth_gss:1, /* authenticated by gss */
575 rq_auth_remote:1, /* authed as remote user */
576 rq_auth_usr_root:1, /* authed as root */
577 rq_auth_usr_mdt:1, /* authed as mdt */
578 /* security tfm flags */
581 /* doesn't expect reply FIXME */
583 rq_pill_init:1; /* pill initialized */
585 uid_t rq_auth_uid; /* authed uid */
586 uid_t rq_auth_mapped_uid; /* authed uid mapped to */
588 /* (server side), pointed directly into req buffer */
589 struct ptlrpc_user_desc *rq_user_desc;
591 /** early replies go to offset 0, regular replies go after that */
592 unsigned int rq_reply_off;
594 /* various buffer pointers */
595 struct lustre_msg *rq_reqbuf; /* req wrapper */
596 int rq_reqbuf_len; /* req wrapper buf len */
597 int rq_reqdata_len; /* req wrapper msg len */
598 char *rq_repbuf; /* rep buffer */
599 int rq_repbuf_len; /* rep buffer len */
600 struct lustre_msg *rq_repdata; /* rep wrapper msg */
601 int rq_repdata_len; /* rep wrapper msg len */
602 struct lustre_msg *rq_clrbuf; /* only in priv mode */
603 int rq_clrbuf_len; /* only in priv mode */
604 int rq_clrdata_len; /* only in priv mode */
608 /** Fields that help to see if request and reply were swabbed or not */
609 __u32 rq_req_swab_mask;
610 __u32 rq_rep_swab_mask;
612 /** What was import generation when this request was sent */
613 int rq_import_generation;
614 enum lustre_imp_state rq_send_state;
616 /** how many early replies (for stats) */
619 /** client+server request */
620 lnet_handle_md_t rq_req_md_h;
621 struct ptlrpc_cb_id rq_req_cbid;
622 /** optional time limit for send attempts */
623 cfs_duration_t rq_delay_limit;
624 /** time request was first queued */
625 cfs_time_t rq_queued_time;
628 /** request arrival time */
629 struct timeval rq_arrival_time;
630 /** separated reply state */
631 struct ptlrpc_reply_state *rq_reply_state;
632 /** incoming request buffer */
633 struct ptlrpc_request_buffer_desc *rq_rqbd;
635 __u32 rq_uid; /* peer uid, used in MDS only */
638 /** client-only incoming reply */
639 lnet_handle_md_t rq_reply_md_h;
640 cfs_waitq_t rq_reply_waitq;
641 struct ptlrpc_cb_id rq_reply_cbid;
645 /** Peer description (the other side) */
646 lnet_process_id_t rq_peer;
647 /** Server-side, export on which request was received */
648 struct obd_export *rq_export;
649 /** Client side, import where request is being sent */
650 struct obd_import *rq_import;
652 /** Replay callback, called after request is replayed at recovery */
653 void (*rq_replay_cb)(struct ptlrpc_request *);
655 * Commit callback, called when request is committed and about to be
658 void (*rq_commit_cb)(struct ptlrpc_request *);
659 /** Opaq data for replay and commit callbacks. */
662 /** For bulk requests on client only: bulk descriptor */
663 struct ptlrpc_bulk_desc *rq_bulk;
665 /** client outgoing req */
667 * when request/reply sent (secs), or time when request should be sent
670 /** time for request really sent out */
673 /** when request must finish. volatile
674 * so that servers' early reply updates to the deadline aren't
675 * kept in per-cpu cache */
676 volatile time_t rq_deadline;
677 /** when req reply unlink must finish. */
678 time_t rq_reply_deadline;
679 /** when req bulk unlink must finish. */
680 time_t rq_bulk_deadline;
682 * service time estimate (secs)
683 * If the requestsis not served by this time, it is marked as timed out.
687 /** Multi-rpc bits */
688 /** Link item for request set lists */
689 cfs_list_t rq_set_chain;
690 /** Per-request waitq introduced by bug 21938 for recovery waiting */
691 cfs_waitq_t rq_set_waitq;
692 /** Link back to the request set */
693 struct ptlrpc_request_set *rq_set;
694 /** Async completion handler, called when reply is received */
695 ptlrpc_interpterer_t rq_interpret_reply;
696 /** Async completion context */
697 union ptlrpc_async_args rq_async_args;
699 /** Pool if request is from preallocated list */
700 struct ptlrpc_request_pool *rq_pool;
702 struct lu_context rq_session;
703 struct lu_context rq_recov_session;
705 /** request format description */
706 struct req_capsule rq_pill;
710 * Call completion handler for rpc if any, return it's status or original
711 * rc if there was no handler defined for this request.
713 static inline int ptlrpc_req_interpret(const struct lu_env *env,
714 struct ptlrpc_request *req, int rc)
716 if (req->rq_interpret_reply != NULL) {
717 req->rq_status = req->rq_interpret_reply(env, req,
720 return req->rq_status;
726 * Returns 1 if request buffer at offset \a index was already swabbed
728 static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
730 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
731 return req->rq_req_swab_mask & (1 << index);
735 * Returns 1 if request reply buffer at offset \a index was already swabbed
737 static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
739 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
740 return req->rq_rep_swab_mask & (1 << index);
744 * Returns 1 if request needs to be swabbed into local cpu byteorder
746 static inline int ptlrpc_req_need_swab(struct ptlrpc_request *req)
748 return lustre_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
752 * Returns 1 if request reply needs to be swabbed into local cpu byteorder
754 static inline int ptlrpc_rep_need_swab(struct ptlrpc_request *req)
756 return lustre_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
760 * Mark request buffer at offset \a index that it was already swabbed
762 static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
764 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
765 LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
766 req->rq_req_swab_mask |= 1 << index;
770 * Mark request reply buffer at offset \a index that it was already swabbed
772 static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
774 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
775 LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
776 req->rq_rep_swab_mask |= 1 << index;
780 * Convert numerical request phase value \a phase into text string description
782 static inline const char *
783 ptlrpc_phase2str(enum rq_phase phase)
792 case RQ_PHASE_INTERPRET:
794 case RQ_PHASE_COMPLETE:
796 case RQ_PHASE_UNREGISTERING:
797 return "Unregistering";
804 * Convert numerical request phase of the request \a req into text stringi
807 static inline const char *
808 ptlrpc_rqphase2str(struct ptlrpc_request *req)
810 return ptlrpc_phase2str(req->rq_phase);
814 * Debugging functions and helpers to print request structure into debug log
817 /* Spare the preprocessor, spoil the bugs. */
818 #define FLAG(field, str) (field ? str : "")
820 /** Convert bit flags into a string */
821 #define DEBUG_REQ_FLAGS(req) \
822 ptlrpc_rqphase2str(req), \
823 FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"), \
824 FLAG(req->rq_err, "E"), \
825 FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"), \
826 FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"), \
827 FLAG(req->rq_no_resend, "N"), \
828 FLAG(req->rq_waiting, "W"), \
829 FLAG(req->rq_wait_ctx, "C"), FLAG(req->rq_hp, "H"), \
830 FLAG(req->rq_committed, "M")
832 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s%s%s"
834 void _debug_req(struct ptlrpc_request *req, __u32 mask,
835 struct libcfs_debug_msg_data *data, const char *fmt, ...)
836 __attribute__ ((format (printf, 4, 5)));
839 * Helper that decides if we need to print request accordig to current debug
842 #define debug_req(cdls, level, req, file, func, line, fmt, a...) \
846 if (((level) & D_CANTMASK) != 0 || \
847 ((libcfs_debug & (level)) != 0 && \
848 (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) { \
849 static struct libcfs_debug_msg_data _req_dbg_data = \
850 DEBUG_MSG_DATA_INIT(cdls, DEBUG_SUBSYSTEM, file, func, line); \
851 _debug_req((req), (level), &_req_dbg_data, fmt, ##a); \
856 * This is the debug print function you need to use to print request sturucture
857 * content into lustre debug log.
858 * for most callers (level is a constant) this is resolved at compile time */
859 #define DEBUG_REQ(level, req, fmt, args...) \
861 if ((level) & (D_ERROR | D_WARNING)) { \
862 static cfs_debug_limit_state_t cdls; \
863 debug_req(&cdls, level, req, __FILE__, __func__, __LINE__, \
864 "@@@ "fmt" ", ## args); \
866 debug_req(NULL, level, req, __FILE__, __func__, __LINE__, \
867 "@@@ "fmt" ", ## args); \
872 * Structure that defines a single page of a bulk transfer
874 struct ptlrpc_bulk_page {
875 /** Linkage to list of pages in a bulk */
878 * Number of bytes in a page to transfer starting from \a bp_pageoffset
881 /** offset within a page */
883 /** The page itself */
884 struct page *bp_page;
887 #define BULK_GET_SOURCE 0
888 #define BULK_PUT_SINK 1
889 #define BULK_GET_SINK 2
890 #define BULK_PUT_SOURCE 3
893 * Definition of buk descriptor.
894 * Bulks are special "Two phase" RPCs where initial request message
895 * is sent first and it is followed bt a transfer (o receiving) of a large
896 * amount of data to be settled into pages referenced from the bulk descriptors.
897 * Bulks transfers (the actual data following the small requests) are done
898 * on separate LNet portals.
899 * In lustre we use bulk transfers for READ and WRITE transfers from/to OSTs.
900 * Another user is readpage for MDT.
902 struct ptlrpc_bulk_desc {
903 /** completed successfully */
904 unsigned long bd_success:1;
905 /** accessible to the network (network io potentially in progress) */
906 unsigned long bd_network_rw:1;
907 /** {put,get}{source,sink} */
908 unsigned long bd_type:2;
910 unsigned long bd_registered:1;
911 /** For serialization with callback */
912 cfs_spinlock_t bd_lock;
913 /** Import generation when request for this bulk was sent */
914 int bd_import_generation;
915 /** Server side - export this bulk created for */
916 struct obd_export *bd_export;
917 /** Client side - import this bulk was sent on */
918 struct obd_import *bd_import;
919 /** LNet portal for this bulk */
921 /** Back pointer to the request */
922 struct ptlrpc_request *bd_req;
923 cfs_waitq_t bd_waitq; /* server side only WQ */
924 int bd_iov_count; /* # entries in bd_iov */
925 int bd_max_iov; /* allocated size of bd_iov */
926 int bd_nob; /* # bytes covered */
927 int bd_nob_transferred; /* # bytes GOT/PUT */
931 struct ptlrpc_cb_id bd_cbid; /* network callback info */
932 lnet_handle_md_t bd_md_h; /* associated MD */
933 lnet_nid_t bd_sender; /* stash event::sender */
935 #if defined(__KERNEL__)
937 * encrypt iov, size is either 0 or bd_iov_count.
939 lnet_kiov_t *bd_enc_iov;
941 lnet_kiov_t bd_iov[0];
943 lnet_md_iovec_t bd_iov[0];
948 * Definition of server service thread structure
950 struct ptlrpc_thread {
952 * List of active threads in svc->srv_threads
956 * thread-private data (preallocated memory)
961 * service thread index, from ptlrpc_start_threads
969 * put watchdog in the structure per thread b=14840
971 struct lc_watchdog *t_watchdog;
973 * the svc this thread belonged to b=18582
975 struct ptlrpc_service *t_svc;
976 cfs_waitq_t t_ctl_waitq;
977 struct lu_env *t_env;
981 * Request buffer descriptor structure.
982 * This is a structure that contains one posted request buffer for service.
983 * Once data land into a buffer, event callback creates actual request and
984 * notifies wakes one of the service threads to process new incoming request.
985 * More than one request can fit into the buffer.
987 struct ptlrpc_request_buffer_desc {
988 /** Link item for rqbds on a service */
989 cfs_list_t rqbd_list;
990 /** History of requests for this buffer */
991 cfs_list_t rqbd_reqs;
992 /** Back pointer to service for which this buffer is registered */
993 struct ptlrpc_service *rqbd_service;
994 /** LNet descriptor */
995 lnet_handle_md_t rqbd_md_h;
997 /** The buffer itself */
999 struct ptlrpc_cb_id rqbd_cbid;
1001 * This "embedded" request structure is only used for the
1002 * last request to fit into the buffer
1004 struct ptlrpc_request rqbd_req;
1007 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
1008 typedef void (*svcreq_printfn_t)(void *, struct ptlrpc_request *);
1009 typedef int (*svc_hpreq_handler_t)(struct ptlrpc_request *);
1012 * How many high priority requests to serve before serving one normal
1015 #define PTLRPC_SVC_HP_RATIO 10
1018 * Definition of PortalRPC service.
1019 * The service is listening on a particular portal (like tcp port)
1020 * and perform actions for a specific server like IO service for OST
1021 * or general metadata service for MDS.
1023 struct ptlrpc_service {
1024 cfs_list_t srv_list; /* chain thru all services */
1025 int srv_max_req_size; /* biggest request to receive */
1026 int srv_max_reply_size; /* biggest reply to send */
1027 int srv_buf_size; /* size of individual buffers */
1028 int srv_nbuf_per_group; /* # buffers to allocate in 1 group */
1029 int srv_nbufs; /* total # req buffer descs allocated */
1030 int srv_threads_min; /* threads to start at SOW */
1031 int srv_threads_max; /* thread upper limit */
1032 int srv_threads_started; /* index of last started thread */
1033 int srv_threads_running; /* # running threads */
1034 cfs_atomic_t srv_n_difficult_replies; /* # 'difficult' replies */
1035 int srv_n_active_reqs; /* # reqs being served */
1036 int srv_n_hpreq; /* # HPreqs being served */
1037 cfs_duration_t srv_rqbd_timeout; /* timeout before re-posting reqs, in tick */
1038 int srv_watchdog_factor; /* soft watchdog timeout multiplier */
1039 unsigned srv_cpu_affinity:1; /* bind threads to CPUs */
1040 unsigned srv_at_check:1; /* check early replies */
1041 unsigned srv_is_stopping:1; /* under unregister_service */
1042 cfs_time_t srv_at_checktime; /* debug */
1044 /** Local portal on which to receive requests */
1045 __u32 srv_req_portal;
1046 /** Portal on the client to send replies to */
1047 __u32 srv_rep_portal;
1051 struct adaptive_timeout srv_at_estimate;/* estimated rpc service time */
1052 cfs_spinlock_t srv_at_lock;
1053 struct ptlrpc_at_array srv_at_array; /* reqs waiting for replies */
1054 cfs_timer_t srv_at_timer; /* early reply timer */
1057 int srv_n_queued_reqs; /* # reqs in either of the queues below */
1058 int srv_hpreq_count; /* # hp requests handled */
1059 int srv_hpreq_ratio; /* # hp per lp reqs to handle */
1060 cfs_list_t srv_req_in_queue; /* incoming reqs */
1061 cfs_list_t srv_request_queue; /* reqs waiting for service */
1062 cfs_list_t srv_request_hpq; /* high priority queue */
1064 cfs_list_t srv_request_history; /* request history */
1065 __u64 srv_request_seq; /* next request sequence # */
1066 __u64 srv_request_max_cull_seq; /* highest seq culled from history */
1067 svcreq_printfn_t srv_request_history_print_fn; /* service-specific print fn */
1069 cfs_list_t srv_idle_rqbds; /* request buffers to be reposted */
1070 cfs_list_t srv_active_rqbds; /* req buffers receiving */
1071 cfs_list_t srv_history_rqbds; /* request buffer history */
1072 int srv_nrqbd_receiving; /* # posted request buffers */
1073 int srv_n_history_rqbds; /* # request buffers in history */
1074 int srv_max_history_rqbds;/* max # request buffers in history */
1076 cfs_atomic_t srv_outstanding_replies;
1077 cfs_list_t srv_active_replies; /* all the active replies */
1079 cfs_list_t srv_reply_queue; /* replies waiting for service */
1081 cfs_waitq_t srv_waitq; /* all threads sleep on this. This
1082 * wait-queue is signalled when new
1083 * incoming request arrives and when
1084 * difficult reply has to be handled. */
1086 cfs_list_t srv_threads; /* service thread list */
1087 /** Handler function for incoming requests for this service */
1088 svc_handler_t srv_handler;
1089 svc_hpreq_handler_t srv_hpreq_handler; /* hp request handler */
1091 char *srv_name; /* only statically allocated strings here; we don't clean them */
1092 char *srv_thread_name; /* only statically allocated strings here; we don't clean them */
1094 cfs_spinlock_t srv_lock;
1096 /** Root of /proc dir tree for this service */
1097 cfs_proc_dir_entry_t *srv_procroot;
1098 /** Pointer to statistic data for this service */
1099 struct lprocfs_stats *srv_stats;
1101 /** List of free reply_states */
1102 cfs_list_t srv_free_rs_list;
1103 /** waitq to run, when adding stuff to srv_free_rs_list */
1104 cfs_waitq_t srv_free_rs_waitq;
1107 * Tags for lu_context associated with this thread, see struct
1112 * if non-NULL called during thread creation (ptlrpc_start_thread())
1113 * to initialize service specific per-thread state.
1115 int (*srv_init)(struct ptlrpc_thread *thread);
1117 * if non-NULL called during thread shutdown (ptlrpc_main()) to
1118 * destruct state created by ->srv_init().
1120 void (*srv_done)(struct ptlrpc_thread *thread);
1122 //struct ptlrpc_srv_ni srv_interfaces[0];
1126 * Declaration of ptlrpcd control structure
1128 struct ptlrpcd_ctl {
1130 * Ptlrpc thread control flags (LIOD_START, LIOD_STOP, LIOD_FORCE)
1132 unsigned long pc_flags;
1134 * Thread lock protecting structure fields.
1136 cfs_spinlock_t pc_lock;
1140 cfs_completion_t pc_starting;
1144 cfs_completion_t pc_finishing;
1146 * Thread requests set.
1148 struct ptlrpc_request_set *pc_set;
1150 * Thread name used in cfs_daemonize()
1154 * Environment for request interpreters to run in.
1156 struct lu_env pc_env;
1159 * Async rpcs flag to make sure that ptlrpcd_check() is called only
1164 * Currently not used.
1168 * User-space async rpcs callback.
1170 void *pc_wait_callback;
1172 * User-space check idle rpcs callback.
1174 void *pc_idle_callback;
1178 /* Bits for pc_flags */
1179 enum ptlrpcd_ctl_flags {
1181 * Ptlrpc thread start flag.
1183 LIOD_START = 1 << 0,
1185 * Ptlrpc thread stop flag.
1189 * Ptlrpc thread force flag (only stop force so far).
1190 * This will cause aborting any inflight rpcs handled
1191 * by thread if LIOD_STOP is specified.
1193 LIOD_FORCE = 1 << 2,
1195 * This is a recovery ptlrpc thread.
1197 LIOD_RECOVERY = 1 << 3
1200 /* ptlrpc/events.c */
1201 extern lnet_handle_eq_t ptlrpc_eq_h;
1202 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
1203 lnet_process_id_t *peer, lnet_nid_t *self);
1205 * These callbacks are invoked by LNet when something happened to
1209 extern void request_out_callback (lnet_event_t *ev);
1210 extern void reply_in_callback(lnet_event_t *ev);
1211 extern void client_bulk_callback (lnet_event_t *ev);
1212 extern void request_in_callback(lnet_event_t *ev);
1213 extern void reply_out_callback(lnet_event_t *ev);
1214 extern void server_bulk_callback (lnet_event_t *ev);
1217 /* ptlrpc/connection.c */
1218 struct ptlrpc_connection *ptlrpc_connection_get(lnet_process_id_t peer,
1220 struct obd_uuid *uuid);
1221 int ptlrpc_connection_put(struct ptlrpc_connection *c);
1222 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
1223 int ptlrpc_connection_init(void);
1224 void ptlrpc_connection_fini(void);
1225 extern lnet_pid_t ptl_get_pid(void);
1227 /* ptlrpc/niobuf.c */
1229 * Actual interfacing with LNet to put/get/register/unregister stuff
1232 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
1233 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
1234 int ptlrpc_register_bulk(struct ptlrpc_request *req);
1235 int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async);
1237 static inline int ptlrpc_server_bulk_active(struct ptlrpc_bulk_desc *desc)
1241 LASSERT(desc != NULL);
1243 cfs_spin_lock(&desc->bd_lock);
1244 rc = desc->bd_network_rw;
1245 cfs_spin_unlock(&desc->bd_lock);
1249 static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req)
1251 struct ptlrpc_bulk_desc *desc = req->rq_bulk;
1254 LASSERT(req != NULL);
1256 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) &&
1257 req->rq_bulk_deadline > cfs_time_current_sec())
1263 cfs_spin_lock(&desc->bd_lock);
1264 rc = desc->bd_network_rw;
1265 cfs_spin_unlock(&desc->bd_lock);
1269 #define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
1270 #define PTLRPC_REPLY_EARLY 0x02
1271 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
1272 int ptlrpc_reply(struct ptlrpc_request *req);
1273 int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
1274 int ptlrpc_error(struct ptlrpc_request *req);
1275 void ptlrpc_resend_req(struct ptlrpc_request *request);
1276 int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
1277 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
1278 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
1281 /* ptlrpc/client.c */
1283 * Client-side portals API. Everything to send requests, receive replies,
1284 * request queues, request management, etc.
1287 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
1288 struct ptlrpc_client *);
1289 void ptlrpc_cleanup_client(struct obd_import *imp);
1290 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
1292 int ptlrpc_queue_wait(struct ptlrpc_request *req);
1293 int ptlrpc_replay_req(struct ptlrpc_request *req);
1294 int ptlrpc_unregister_reply(struct ptlrpc_request *req, int async);
1295 void ptlrpc_restart_req(struct ptlrpc_request *req);
1296 void ptlrpc_abort_inflight(struct obd_import *imp);
1297 void ptlrpc_cleanup_imp(struct obd_import *imp);
1298 void ptlrpc_abort_set(struct ptlrpc_request_set *set);
1300 struct ptlrpc_request_set *ptlrpc_prep_set(void);
1301 int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
1302 set_interpreter_func fn, void *data);
1303 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
1304 int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set);
1305 int ptlrpc_set_wait(struct ptlrpc_request_set *);
1306 int ptlrpc_expired_set(void *data);
1307 void ptlrpc_interrupted_set(void *data);
1308 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
1309 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
1310 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
1311 int ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
1312 struct ptlrpc_request *req);
1314 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
1315 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
1317 struct ptlrpc_request_pool *
1318 ptlrpc_init_rq_pool(int, int,
1319 void (*populate_pool)(struct ptlrpc_request_pool *, int));
1321 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
1322 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
1323 const struct req_format *format);
1324 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
1325 struct ptlrpc_request_pool *,
1326 const struct req_format *format);
1327 void ptlrpc_request_free(struct ptlrpc_request *request);
1328 int ptlrpc_request_pack(struct ptlrpc_request *request,
1329 __u32 version, int opcode);
1330 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
1331 const struct req_format *format,
1332 __u32 version, int opcode);
1333 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
1334 __u32 version, int opcode, char **bufs,
1335 struct ptlrpc_cli_ctx *ctx);
1336 struct ptlrpc_request *ptlrpc_prep_fakereq(struct obd_import *imp,
1337 unsigned int timeout,
1338 ptlrpc_interpterer_t interpreter);
1339 void ptlrpc_fakereq_finished(struct ptlrpc_request *req);
1341 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
1342 int opcode, int count, __u32 *lengths,
1344 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
1345 __u32 version, int opcode,
1346 int count, __u32 *lengths, char **bufs,
1347 struct ptlrpc_request_pool *pool);
1348 void ptlrpc_req_finished(struct ptlrpc_request *request);
1349 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
1350 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
1351 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
1352 int npages, int type, int portal);
1353 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
1354 int npages, int type, int portal);
1355 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
1356 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
1357 cfs_page_t *page, int pageoffset, int len);
1358 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
1359 struct obd_import *imp);
1360 __u64 ptlrpc_next_xid(void);
1361 __u64 ptlrpc_sample_next_xid(void);
1362 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
1366 struct ptlrpc_service_conf {
1369 int psc_max_req_size;
1370 int psc_max_reply_size;
1373 int psc_watchdog_factor;
1374 int psc_min_threads;
1375 int psc_max_threads;
1379 /* ptlrpc/service.c */
1381 * Server-side services API. Register/unregister service, request state
1382 * management, service thread management
1386 void ptlrpc_save_lock (struct ptlrpc_request *req,
1387 struct lustre_handle *lock, int mode, int no_ack);
1388 void ptlrpc_commit_replies(struct obd_export *exp);
1389 void ptlrpc_dispatch_difficult_reply (struct ptlrpc_reply_state *rs);
1390 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
1391 struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
1392 svc_handler_t h, char *name,
1393 struct proc_dir_entry *proc_entry,
1394 svcreq_printfn_t prntfn,
1397 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
1399 int req_portal, int rep_portal,
1400 int watchdog_factor,
1401 svc_handler_t, char *name,
1402 cfs_proc_dir_entry_t *proc_entry,
1404 int min_threads, int max_threads,
1405 char *threadname, __u32 ctx_tags,
1406 svc_hpreq_handler_t);
1407 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
1409 int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc);
1410 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc);
1411 int ptlrpc_unregister_service(struct ptlrpc_service *service);
1412 int liblustre_check_services (void *arg);
1413 void ptlrpc_daemonize(char *name);
1414 int ptlrpc_service_health_check(struct ptlrpc_service *);
1415 void ptlrpc_hpreq_reorder(struct ptlrpc_request *req);
1416 void ptlrpc_server_active_request_inc(struct ptlrpc_request *req);
1417 void ptlrpc_server_active_request_dec(struct ptlrpc_request *req);
1418 void ptlrpc_server_drop_request(struct ptlrpc_request *req);
1421 int ptlrpc_hr_init(void);
1422 void ptlrpc_hr_fini(void);
1424 # define ptlrpc_hr_init() (0)
1425 # define ptlrpc_hr_fini() do {} while(0)
1428 struct ptlrpc_svc_data {
1430 struct ptlrpc_service *svc;
1431 struct ptlrpc_thread *thread;
1432 struct obd_device *dev;
1436 /* ptlrpc/import.c */
1441 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
1442 int ptlrpc_init_import(struct obd_import *imp);
1443 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
1444 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
1446 /* ptlrpc/pack_generic.c */
1447 int ptlrpc_reconnect_import(struct obd_import *imp);
1451 * ptlrpc msg buffer and swab interface
1455 int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
1457 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
1459 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len);
1460 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len);
1462 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
1463 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
1465 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
1466 __u32 *lens, char **bufs);
1467 int lustre_pack_reply(struct ptlrpc_request *, int count, __u32 *lens,
1469 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
1470 __u32 *lens, char **bufs, int flags);
1471 #define LPRFL_EARLY_REPLY 1
1472 int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens,
1473 char **bufs, int flags);
1474 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
1475 unsigned int newlen, int move_data);
1476 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
1477 int __lustre_unpack_msg(struct lustre_msg *m, int len);
1478 int lustre_msg_hdr_size(__u32 magic, int count);
1479 int lustre_msg_size(__u32 magic, int count, __u32 *lengths);
1480 int lustre_msg_size_v2(int count, __u32 *lengths);
1481 int lustre_packed_msg_size(struct lustre_msg *msg);
1482 int lustre_msg_early_size(void);
1483 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
1484 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
1485 int lustre_msg_buflen(struct lustre_msg *m, int n);
1486 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
1487 int lustre_msg_bufcount(struct lustre_msg *m);
1488 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
1489 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
1490 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
1491 __u32 lustre_msg_get_flags(struct lustre_msg *msg);
1492 void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
1493 void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
1494 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
1495 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
1496 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
1497 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
1498 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
1499 __u32 lustre_msg_get_type(struct lustre_msg *msg);
1500 __u32 lustre_msg_get_version(struct lustre_msg *msg);
1501 void lustre_msg_add_version(struct lustre_msg *msg, int version);
1502 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
1503 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
1504 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
1505 __u64 *lustre_msg_get_versions(struct lustre_msg *msg);
1506 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
1507 __u64 lustre_msg_get_slv(struct lustre_msg *msg);
1508 __u32 lustre_msg_get_limit(struct lustre_msg *msg);
1509 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
1510 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
1511 int lustre_msg_get_status(struct lustre_msg *msg);
1512 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
1513 int lustre_msg_is_v1(struct lustre_msg *msg);
1514 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
1515 __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
1516 __u32 lustre_msg_get_service_time(struct lustre_msg *msg);
1517 __u32 lustre_msg_get_cksum(struct lustre_msg *msg);
1518 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 0, 0)
1519 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg, int compat18);
1521 # warning "remove checksum compatibility support for b1_8"
1522 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
1524 void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
1525 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
1526 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
1527 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
1528 void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed);
1529 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions);
1530 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
1531 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
1532 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
1533 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *sizes);
1534 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
1535 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
1536 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
1537 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
1540 lustre_shrink_reply(struct ptlrpc_request *req, int segment,
1541 unsigned int newlen, int move_data)
1543 LASSERT(req->rq_reply_state);
1544 LASSERT(req->rq_repmsg);
1545 req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
1550 /** Change request phase of \a req to \a new_phase */
1552 ptlrpc_rqphase_move(struct ptlrpc_request *req, enum rq_phase new_phase)
1554 if (req->rq_phase == new_phase)
1557 if (new_phase == RQ_PHASE_UNREGISTERING) {
1558 req->rq_next_phase = req->rq_phase;
1560 cfs_atomic_inc(&req->rq_import->imp_unregistering);
1563 if (req->rq_phase == RQ_PHASE_UNREGISTERING) {
1565 cfs_atomic_dec(&req->rq_import->imp_unregistering);
1568 DEBUG_REQ(D_INFO, req, "move req \"%s\" -> \"%s\"",
1569 ptlrpc_rqphase2str(req), ptlrpc_phase2str(new_phase));
1571 req->rq_phase = new_phase;
1575 * Returns true if request \a req got early reply and hard deadline is not met
1578 ptlrpc_client_early(struct ptlrpc_request *req)
1580 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1581 req->rq_reply_deadline > cfs_time_current_sec())
1583 return req->rq_early;
1587 * Returns true if we got real reply from server for this request
1590 ptlrpc_client_replied(struct ptlrpc_request *req)
1592 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1593 req->rq_reply_deadline > cfs_time_current_sec())
1595 return req->rq_replied;
1598 /** Returns true if request \a req is in process of receiving server reply */
1600 ptlrpc_client_recv(struct ptlrpc_request *req)
1602 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1603 req->rq_reply_deadline > cfs_time_current_sec())
1605 return req->rq_receiving_reply;
1609 ptlrpc_client_recv_or_unlink(struct ptlrpc_request *req)
1613 cfs_spin_lock(&req->rq_lock);
1614 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1615 req->rq_reply_deadline > cfs_time_current_sec()) {
1616 cfs_spin_unlock(&req->rq_lock);
1619 rc = req->rq_receiving_reply || req->rq_must_unlink;
1620 cfs_spin_unlock(&req->rq_lock);
1625 ptlrpc_client_wake_req(struct ptlrpc_request *req)
1627 if (req->rq_set == NULL)
1628 cfs_waitq_signal(&req->rq_reply_waitq);
1630 cfs_waitq_signal(&req->rq_set->set_waitq);
1634 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
1636 LASSERT(cfs_atomic_read(&rs->rs_refcount) > 0);
1637 cfs_atomic_inc(&rs->rs_refcount);
1641 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
1643 LASSERT(cfs_atomic_read(&rs->rs_refcount) > 0);
1644 if (cfs_atomic_dec_and_test(&rs->rs_refcount))
1645 lustre_free_reply_state(rs);
1648 /* Should only be called once per req */
1649 static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
1651 if (req->rq_reply_state == NULL)
1652 return; /* shouldn't occur */
1653 ptlrpc_rs_decref(req->rq_reply_state);
1654 req->rq_reply_state = NULL;
1655 req->rq_repmsg = NULL;
1658 static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
1660 return lustre_msg_get_magic(req->rq_reqmsg);
1663 static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
1665 switch (req->rq_reqmsg->lm_magic) {
1666 case LUSTRE_MSG_MAGIC_V2:
1667 return req->rq_reqmsg->lm_repsize;
1669 LASSERTF(0, "incorrect message magic: %08x\n",
1670 req->rq_reqmsg->lm_magic);
1675 static inline int ptlrpc_send_limit_expired(struct ptlrpc_request *req)
1677 if (req->rq_delay_limit != 0 &&
1678 cfs_time_before(cfs_time_add(req->rq_queued_time,
1679 cfs_time_seconds(req->rq_delay_limit)),
1680 cfs_time_current())) {
1686 static inline int ptlrpc_no_resend(struct ptlrpc_request *req)
1688 if (!req->rq_no_resend && ptlrpc_send_limit_expired(req)) {
1689 cfs_spin_lock(&req->rq_lock);
1690 req->rq_no_resend = 1;
1691 cfs_spin_unlock(&req->rq_lock);
1693 return req->rq_no_resend;
1696 /* ldlm/ldlm_lib.c */
1698 * Target client logic
1701 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
1702 int client_obd_cleanup(struct obd_device *obddev);
1703 int client_connect_import(const struct lu_env *env,
1704 struct obd_export **exp, struct obd_device *obd,
1705 struct obd_uuid *cluuid, struct obd_connect_data *,
1707 int client_disconnect_export(struct obd_export *exp);
1708 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
1710 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
1711 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
1712 void client_destroy_import(struct obd_import *imp);
1715 int server_disconnect_export(struct obd_export *exp);
1717 /* ptlrpc/pinger.c */
1719 * Pinger API (client side only)
1722 enum timeout_event {
1725 struct timeout_item;
1726 typedef int (*timeout_cb_t)(struct timeout_item *, void *);
1727 int ptlrpc_pinger_add_import(struct obd_import *imp);
1728 int ptlrpc_pinger_del_import(struct obd_import *imp);
1729 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
1730 timeout_cb_t cb, void *data,
1731 cfs_list_t *obd_list);
1732 int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
1733 enum timeout_event event);
1734 struct ptlrpc_request * ptlrpc_prep_ping(struct obd_import *imp);
1735 int ptlrpc_obd_ping(struct obd_device *obd);
1736 cfs_time_t ptlrpc_suspend_wakeup_time(void);
1738 void ping_evictor_start(void);
1739 void ping_evictor_stop(void);
1741 #define ping_evictor_start() do {} while (0)
1742 #define ping_evictor_stop() do {} while (0)
1744 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req);
1747 /* ptlrpc/ptlrpcd.c */
1750 * Ptlrpcd scope is a set of two threads: ptlrpcd-foo and ptlrpcd-foo-rcv,
1751 * these threads are used to asynchronously send requests queued with
1752 * ptlrpcd_add_req(req, PCSOPE_FOO), and to handle completion call-backs for
1753 * such requests. Multiple scopes are needed to avoid dead-locks.
1755 enum ptlrpcd_scope {
1756 /** Scope of bulk read-write rpcs. */
1758 /** Everything else. */
1763 int ptlrpcd_start(const char *name, struct ptlrpcd_ctl *pc);
1764 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force);
1765 void ptlrpcd_wake(struct ptlrpc_request *req);
1766 int ptlrpcd_add_req(struct ptlrpc_request *req, enum ptlrpcd_scope scope);
1767 void ptlrpcd_add_rqset(struct ptlrpc_request_set *set);
1768 int ptlrpcd_addref(void);
1769 void ptlrpcd_decref(void);
1771 /* ptlrpc/lproc_ptlrpc.c */
1773 * procfs output related functions
1776 const char* ll_opcode2str(__u32 opcode);
1778 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
1779 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
1780 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes);
1782 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
1783 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
1784 static inline void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes) {}
1788 /* ptlrpc/llog_server.c */
1789 int llog_origin_handle_create(struct ptlrpc_request *req);
1790 int llog_origin_handle_destroy(struct ptlrpc_request *req);
1791 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
1792 int llog_origin_handle_next_block(struct ptlrpc_request *req);
1793 int llog_origin_handle_read_header(struct ptlrpc_request *req);
1794 int llog_origin_handle_close(struct ptlrpc_request *req);
1795 int llog_origin_handle_cancel(struct ptlrpc_request *req);
1796 int llog_catinfo(struct ptlrpc_request *req);
1798 /* ptlrpc/llog_client.c */
1799 extern struct llog_operations llog_client_ops;